Skip to content

Commit

Permalink
sinol-make export should add +x to xyzingen.sh (#142)
Browse files Browse the repository at this point in the history
* Add executable permission to shell ingen in export

* Add test
  • Loading branch information
MasloMaslane authored Oct 9, 2023
1 parent 057ed32 commit 2e22266
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import glob
import stat
import shutil
import tarfile
import argparse
Expand Down Expand Up @@ -62,6 +63,10 @@ def copy_package_required_files(self, target_dir: str):
shutil.copytree(file_path, os.path.join(target_dir, file))
else:
shutil.copy(file_path, target_dir)
shell_ingen = os.path.join(target_dir, 'prog', f'{self.task_id}ingen.sh')
if os.path.exists(shell_ingen):
st = os.stat(shell_ingen)
os.chmod(shell_ingen, st.st_mode | stat.S_IEXEC)

print('Copying example tests...')
for ext in ['in', 'out']:
Expand Down
26 changes: 26 additions & 0 deletions tests/commands/export/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import yaml
import stat
import glob
import pytest
import tarfile
Expand Down Expand Up @@ -80,3 +81,28 @@ def test_doc_cleared(create_package):
assert os.path.exists(extracted)
for pattern in ['doc/*~', 'doc/*.aux', 'doc/*.log', 'doc/*.dvi', 'doc/*.err', 'doc/*.inf']:
assert glob.glob(os.path.join(extracted, pattern)) == []


@pytest.mark.parametrize("create_package", [util.get_shell_ingen_pack_path()], indirect=True)
def test_correct_permissions(create_package, capsys):
"""
Checks if shell ingen has correct permissions.
"""
shell_ingen = os.path.join(os.getcwd(), 'prog', f'{package_util.get_task_id()}ingen.sh')
st = os.stat(shell_ingen)
os.chmod(shell_ingen, st.st_mode & ~stat.S_IEXEC)

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:
tar.extractall(tmpdir)

shell_ingen = os.path.join(tmpdir, task_id, 'prog', f'{task_id}ingen.sh')
assert os.path.exists(shell_ingen)
st = os.stat(shell_ingen)
assert st.st_mode & stat.S_IEXEC

0 comments on commit 2e22266

Please sign in to comment.