Skip to content

Commit

Permalink
Fix tests for when Apptainer/Singularity is available (#8)
Browse files Browse the repository at this point in the history
* Fix tests for when Apptainer/Singularity is available
Fixes #7

* check for apptainer runtime
  • Loading branch information
espenhgn authored Oct 1, 2024
1 parent efa1ecf commit 2624f64
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/test_mtag_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
# Check that (1) singularity exist, and (2) if not, check for docker.
# If neither are found, tests will fall back to plain python.
try:
pth = os.path.join('containers', 'mtag.sif')
out = subprocess.run('singularity')
pth = os.path.join('apptainer', 'mtag.sif')
try:
out = subprocess.run('singularity')
runtime = 'singularity'
except FileNotFoundError:
try:
out = subprocess.run('apptainer')
runtime = 'apptainer'
except FileNotFoundError:
raise FileNotFoundError
cwd = os.getcwd()
MTAG = f'singularity run {pth}'
PREFIX = f'singularity run {pth} python'
PREFIX_MOUNT = f'singularity run --home={cwd}:/home/ {pth} python'
MTAG = f'{runtime} run {pth}'
PREFIX = f'{runtime} exec {pth} python'
PREFIX_MOUNT = f'{runtime} exec --home={cwd}:/home/ {pth} python'
except FileNotFoundError:
try:
out = subprocess.run('docker')
Expand All @@ -43,7 +51,7 @@
'ghcr.io/comorment/mtag')
except FileNotFoundError as err:
# neither singularity nor docker found, fall back to plain python
mssg = 'Neither singularity nor docker found, tests will fail'
mssg = 'Neither singularity, apptainer nor docker found; tests fail'
raise FileNotFoundError(mssg) from err


Expand Down

0 comments on commit 2624f64

Please sign in to comment.