From 2e2226688f5337a2a3d3fecb3f90521eaaf4a311 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 9 Oct 2023 19:11:33 +0200 Subject: [PATCH] `sinol-make export` should add +x to `xyzingen.sh` (#142) * Add executable permission to shell ingen in export * Add test --- src/sinol_make/commands/export/__init__.py | 5 +++++ tests/commands/export/test_integration.py | 26 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/sinol_make/commands/export/__init__.py b/src/sinol_make/commands/export/__init__.py index 8dbbc759..46447ca3 100644 --- a/src/sinol_make/commands/export/__init__.py +++ b/src/sinol_make/commands/export/__init__.py @@ -1,5 +1,6 @@ import os import glob +import stat import shutil import tarfile import argparse @@ -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']: diff --git a/tests/commands/export/test_integration.py b/tests/commands/export/test_integration.py index f7fe1dea..cfd46e30 100644 --- a/tests/commands/export/test_integration.py +++ b/tests/commands/export/test_integration.py @@ -1,4 +1,5 @@ import yaml +import stat import glob import pytest import tarfile @@ -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