Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
espenhgn committed Sep 20, 2024
1 parent 9e94aa4 commit e700645
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/container_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/test_container_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check failure on line 28 in tests/test_container_template.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_container_template.py#L28 <501>

line too long (85 > 79 characters)
Raw output
./tests/test_container_template.py:28:80: E501 line too long (85 > 79 characters)
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():
Expand All @@ -49,15 +49,15 @@ 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


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

Expand All @@ -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

0 comments on commit e700645

Please sign in to comment.