From 2624f648c34c78b2493320d57a06f1d7fac1328e Mon Sep 17 00:00:00 2001 From: Espen Hagen <2492641+espenhgn@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:43:42 +0200 Subject: [PATCH] Fix tests for when Apptainer/Singularity is available (#8) * Fix tests for when Apptainer/Singularity is available Fixes #7 * check for apptainer runtime --- tests/test_mtag_container.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/test_mtag_container.py b/tests/test_mtag_container.py index 729f06e..9abcbbd 100644 --- a/tests/test_mtag_container.py +++ b/tests/test_mtag_container.py @@ -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') @@ -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