Skip to content

Commit

Permalink
Add tests for removing cache after contest type change
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 24, 2023
1 parent 09e0630 commit f632221
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ def run(self, args):
print("Task: %s (tag: %s)" % (title, self.ID))
self.cpus = args.cpus or mp.cpu_count()
cache.save_to_cache_extra_compilation_files(self.config.get("extra_compilation_files", []), self.ID)
cache.check_if_contest_type_changed(self.config.get("contest_type", "default"))
cache.check_if_contest_type_changed(self.config.get("sinol_contest_type", "default"))

checker = package_util.get_files_matching_pattern(self.ID, f'{self.ID}chk.*')
if len(checker) != 0:
Expand Down
37 changes: 37 additions & 0 deletions tests/commands/run/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,43 @@ def test(file_to_change, lang, comment_character):
test("liblib.py", "py", "#")


@pytest.mark.parametrize("create_package", [get_simple_package_path()], indirect=True)
def test_contest_type_change(create_package, time_tool):
"""
Test if after changing contest type, all cached test results are removed.
"""
package_path = create_package
create_ins_outs(package_path)
parser = configure_parsers()
args = parser.parse_args(["run", "--time-tool", time_tool])
command = Command()

# First run to cache test results.
command.run(args)

# Change contest type.
config_path = os.path.join(os.getcwd(), "config.yml")
with open(config_path, "r") as f:
config = yaml.load(f, Loader=yaml.SafeLoader)
config["sinol_contest_type"] = "oi"
with open(config_path, "w") as f:
f.write(yaml.dump(config))

# Compile checker check if test results are removed.
command = Command()
# We remove tests, so that `run()` exits before creating new cached test results.
for test in glob.glob("in/*.in"):
os.unlink(test)
with pytest.raises(SystemExit):
command.run(args)

task_id = package_util.get_task_id()
solutions = package_util.get_solutions(task_id, None)
for solution in solutions:
cache_file: CacheFile = cache.get_cache_file(solution)
assert cache_file.tests == {}


@pytest.mark.parametrize("create_package", [get_simple_package_path()], indirect=True)
def test_cwd_in_prog(create_package):
"""
Expand Down

0 comments on commit f632221

Please sign in to comment.