Skip to content

Commit

Permalink
Fix handwritten tests in exported package (#169)
Browse files Browse the repository at this point in the history
* Fix

* Add tests
  • Loading branch information
MasloMaslane authored Jan 3, 2024
1 parent 3af16b9 commit 45677ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def copy_package_required_files(self, target_dir: str):
for ext in ['in', 'out']:
for test in glob.glob(os.path.join(os.getcwd(), ext, f'{self.task_id}*.{ext}')):
if package_util.extract_test_id(test, self.task_id) not in generated_tests:
tests_to_copy.append(test)
tests_to_copy.append((ext, test))

if len(tests_to_copy) > 0:
print(util.warning(f'Found {len(tests_to_copy)} tests that are not generated by ingen.'))
for test in tests_to_copy:
print(util.warning(f'Coping {os.path.basename(test)}...'))
shutil.copy(test, os.path.join(target_dir, os.path.splitext(os.path.basename(test))[1]))
print(util.warning(f'Coping {os.path.basename(test[1])}...'))
shutil.copy(test[1], os.path.join(target_dir, test[0], os.path.basename(test[1])))

def clear_files(self, target_dir: str):
"""
Expand Down
20 changes: 20 additions & 0 deletions tests/commands/export/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,23 @@ def test_correct_permissions(create_package, capsys):
assert os.path.exists(shell_ingen)
st = os.stat(shell_ingen)
assert st.st_mode & stat.S_IEXEC


@pytest.mark.parametrize("create_package", [util.get_handwritten_package_path()], indirect=True)
def test_handwritten_tests(create_package):
"""
Test if handwritten tests are correctly copied.
"""
parser = configure_parsers()
args = parser.parse_args(["export"])
command = Command()
command.run(args)
task_id = package_util.get_task_id()

with tempfile.TemporaryDirectory() as tmpdir:
with tarfile.open(f'{task_id}.tgz', "r") as tar:
sinol_util.extract_tar(tar, tmpdir)

extracted = os.path.join(tmpdir, task_id)
for file in ["in/hwr0.in", "in/hwr0a.in", "out/hwr0.out", "out/hwr0a.out"]:
assert os.path.exists(os.path.join(extracted, file))

0 comments on commit 45677ae

Please sign in to comment.