Skip to content

Commit 1cea61a

Browse files
committed
Add tests
1 parent 0d87acb commit 1cea61a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

tests/commands/gen/test_integration.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import glob
55

66
from sinol_make import configure_parsers
7+
from sinol_make import util as sm_util
78
from sinol_make.commands.gen import Command
89
from sinol_make.commands.gen import gen_util
9-
from sinol_make.helpers import package_util, paths
10+
from sinol_make.helpers import package_util, paths, cache
1011
from tests.fixtures import *
1112
from tests import util
1213

@@ -47,6 +48,9 @@ def test_correct_inputs(capsys, create_package):
4748
"""
4849
Test `ingen` command with all unchanged inputs.
4950
"""
51+
task_id = package_util.get_task_id()
52+
correct_solution = package_util.get_correct_solution(task_id)
53+
cache.save_compiled(correct_solution, "exe")
5054
simple_run()
5155
md5_sums = get_md5_sums(create_package)
5256

@@ -63,6 +67,9 @@ def test_changed_inputs(capsys, create_package):
6367
"""
6468
Test `ingen` command with changed inputs.
6569
"""
70+
task_id = package_util.get_task_id()
71+
correct_solution = package_util.get_correct_solution(task_id)
72+
cache.save_compiled(correct_solution, "exe")
6673
simple_run()
6774
md5_sums = get_md5_sums(create_package)
6875
correct_md5 = md5_sums.copy()
@@ -152,3 +159,29 @@ def test_missing_output_files(create_package):
152159
assert os.path.exists(outs[0])
153160
shutil.rmtree(paths.get_cache_path())
154161
os.unlink(os.path.join(package_path, "in", ".md5sums"))
162+
163+
164+
@pytest.mark.parametrize("create_package", [util.get_shell_ingen_pack_path(), util.get_simple_package_path()],
165+
indirect=True)
166+
def test_correct_solution_changed(create_package):
167+
"""
168+
Test if `.md5sums` is deleted when correct solution is changed.
169+
"""
170+
package_path = create_package
171+
task_id = package_util.get_task_id()
172+
md5sums = os.path.join(package_path, "in", ".md5sums")
173+
simple_run()
174+
assert os.path.exists(md5sums)
175+
outputs = {}
176+
for output in glob.glob(os.path.join(package_path, "out", "*.out")):
177+
outputs[os.path.basename(output)] = sm_util.get_file_md5(output)
178+
179+
solution = package_util.get_correct_solution(task_id)
180+
with open(os.path.join(solution), "w") as f:
181+
f.write("int main() {}")
182+
cache.check_correct_solution(task_id)
183+
assert not os.path.exists(md5sums)
184+
simple_run()
185+
assert os.path.exists(md5sums)
186+
for output in glob.glob(os.path.join(package_path, "out", "*.out")):
187+
assert outputs[os.path.basename(output)] != sm_util.get_file_md5(output)

0 commit comments

Comments
 (0)