From e7006451ac50b8ba1a4c885cd66b346917c5b168 Mon Sep 17 00:00:00 2001 From: Espen Hagen <2492641+espenhgn@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:56:07 +0200 Subject: [PATCH] test --- .github/workflows/container_build.yml | 5 +++-- tests/test_container_template.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index b0a8e99..8dd6588 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -56,8 +56,9 @@ jobs: ./dockerfiles/container_template/Dockerfile - name: Run unit tests run: | - docker run --rm ${{ env.TEST_TAG }} - docker run --rm -v $PWD:/home ${{ env.TEST_TAG }} py.test -v tests + docker run --rm ${{ env.TEST_TAG }} + ls -l + docker run --rm -v .:/home ${{ env.TEST_TAG }} py.test -v tests - name: Build uses: docker/build-push-action@v6 diff --git a/tests/test_container_template.py b/tests/test_container_template.py index 2bbd0b6..3f36b87 100644 --- a/tests/test_container_template.py +++ b/tests/test_container_template.py @@ -24,22 +24,22 @@ pth = os.path.join('containers', 'container_template.sif') out = subprocess.run('singularity') cwd = os.getcwd() - PREFIX = f'singularity run {pth} ' - PREFIX_MOUNT = PREFIX_MOUNT = f'singularity run --home={cwd}:/home/ {pth} ' + PREFIX = f'singularity run {pth} python' + PREFIX_MOUNT = PREFIX_MOUNT = f'singularity run --home={cwd}:/home/ {pth} python' except FileNotFoundError: try: out = subprocess.run('docker') pwd = os.getcwd() PREFIX = (f'docker run -p {port}:{port} ' + - 'ghcr.io/precimed/container_template ') + 'ghcr.io/precimed/container_template python') PREFIX_MOUNT = ( f'docker run -p {port}:{port} ' + f'--mount type=bind,source={pwd},target={pwd} ' + - 'ghcr.io/precimed/container_template ') + 'ghcr.io/precimed/container_template python') except FileNotFoundError: # neither singularity nor docker found, fall back to plain python - PREFIX = '' - PREFIX_MOUNT = '' + PREFIX = 'python' + PREFIX_MOUNT = 'python' def test_assert(): @@ -49,7 +49,7 @@ def test_assert(): def test_container_template_python(): """test that the Python installation works""" - call = f'{PREFIX}python --version' + call = f'{PREFIX} --version' out = subprocess.run(call.split(' ')) assert out.returncode == 0 @@ -57,7 +57,7 @@ def test_container_template_python(): def test_container_template_python_script(): '''test that Python can run a script''' pwd = os.getcwd() if PREFIX.rfind('docker') >= 0 else '.' - call = f'''{PREFIX_MOUNT}python {pwd}/tests/extras/hello.py''' + call = f'''{PREFIX_MOUNT} {pwd}/tests/extras/hello.py''' out = subprocess.run(call.split(' '), capture_output=True) assert out.returncode == 0 @@ -75,6 +75,6 @@ def test_container_template_python_packages(): 'jupyterlab', ] importstr = 'import ' + ', '.join(packages) - call = f"{PREFIX}python -c '{importstr}'" + call = f"{PREFIX} -c '{importstr}'" out = subprocess.run(call, shell=True) assert out.returncode == 0