From 20da673bfd6b7ecf0a359106b06293a654a3dcd1 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Tue, 19 Sep 2023 21:14:44 +0800 Subject: [PATCH] Fix the tests such that it no longer require the working directory to be the root directory (#28) Co-authored-by: William (Zhiyi) Wu --- .../Sandpit/Exscientia/Align/test_decouple.py | 5 ++++- .../Sandpit/Exscientia/Align/test_make_ml.py | 5 ++++- tests/Sandpit/Exscientia/Align/test_squash.py | 3 ++- .../Exscientia/Convert/test_convert.py | 5 ++++- .../FreeEnergy/test_alchemical_free_energy.py | 9 ++++++-- tests/Sandpit/Exscientia/Gateway/test_file.py | 5 ++++- .../Exscientia/Gateway/test_fileset.py | 11 +++++----- tests/Sandpit/Exscientia/Gateway/test_node.py | 3 ++- .../Sandpit/Exscientia/IO/test_file_cache.py | 3 ++- tests/Sandpit/Exscientia/IO/test_tuple.py | 3 ++- tests/Sandpit/Exscientia/MD/test_md.py | 11 ++++++---- .../Sandpit/Exscientia/Process/test_amber.py | 18 ++++++++-------- .../Exscientia/Process/test_dummy_protocol.py | 5 ++++- .../Exscientia/Process/test_gromacs.py | 16 ++++++++------ tests/Sandpit/Exscientia/Process/test_namd.py | 7 ++++--- .../Sandpit/Exscientia/Process/test_openmm.py | 5 ++++- tests/Sandpit/Exscientia/Process/test_somd.py | 7 +++++-- .../Sandpit/Exscientia/Stream/test_stream.py | 5 ++++- .../Exscientia/Trajectory/test_trajectory.py | 21 +++++++++++-------- .../Exscientia/_SireWrappers/test_bond.py | 5 ++++- .../Exscientia/_SireWrappers/test_molecule.py | 5 ++++- .../_SireWrappers/test_properties.py | 3 ++- .../_SireWrappers/test_search_result.py | 5 ++++- .../Exscientia/_SireWrappers/test_system.py | 5 ++++- tests/conftest.py | 4 ++++ 25 files changed, 118 insertions(+), 56 deletions(-) diff --git a/tests/Sandpit/Exscientia/Align/test_decouple.py b/tests/Sandpit/Exscientia/Align/test_decouple.py index 210bdd816..150938ddd 100644 --- a/tests/Sandpit/Exscientia/Align/test_decouple.py +++ b/tests/Sandpit/Exscientia/Align/test_decouple.py @@ -6,6 +6,7 @@ from BioSimSpace.Sandpit.Exscientia.Align._decouple import decouple import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp # Store the tutorial URL. url = BSS.tutorialUrl() @@ -14,7 +15,9 @@ @pytest.fixture(scope="session") def mol(): # Alanin-dipeptide. - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"])[0] + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + )[0] def test_sanity(mol): diff --git a/tests/Sandpit/Exscientia/Align/test_make_ml.py b/tests/Sandpit/Exscientia/Align/test_make_ml.py index 908fd3ee5..b2c2a54e9 100644 --- a/tests/Sandpit/Exscientia/Align/test_make_ml.py +++ b/tests/Sandpit/Exscientia/Align/test_make_ml.py @@ -2,6 +2,7 @@ import BioSimSpace.Sandpit.Exscientia as BSS from BioSimSpace.Sandpit.Exscientia.Align import make_ml +from tests.conftest import root_fp # Store the tutorial URL. url = BSS.tutorialUrl() @@ -9,7 +10,9 @@ @pytest.fixture def mol(): - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"])[0] + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + )[0] @pytest.fixture diff --git a/tests/Sandpit/Exscientia/Align/test_squash.py b/tests/Sandpit/Exscientia/Align/test_squash.py index bfcc29656..0f01bf088 100644 --- a/tests/Sandpit/Exscientia/Align/test_squash.py +++ b/tests/Sandpit/Exscientia/Align/test_squash.py @@ -7,6 +7,7 @@ from sire.maths import Vector import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp # Make sure AMBER is installed. if BSS._amber_home is not None: @@ -60,7 +61,7 @@ def dual_topology_system(): @pytest.fixture def perturbed_tripeptide(): return pickle.load( - open("tests/Sandpit/Exscientia/input/merged_tripeptide.pickle", "rb") + open(f"{root_fp}/Sandpit/Exscientia/input/merged_tripeptide.pickle", "rb") ) diff --git a/tests/Sandpit/Exscientia/Convert/test_convert.py b/tests/Sandpit/Exscientia/Convert/test_convert.py index 220f48b51..e444c3144 100644 --- a/tests/Sandpit/Exscientia/Convert/test_convert.py +++ b/tests/Sandpit/Exscientia/Convert/test_convert.py @@ -3,11 +3,14 @@ from sire.legacy import Mol as SireMol import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp @pytest.fixture(scope="session") def system(): - return BSS.IO.readMolecules(["tests/input/ala.crd", "tests/input/ala.top"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.crd", f"{root_fp}/input/ala.top"] + ) def test_system(system): diff --git a/tests/Sandpit/Exscientia/FreeEnergy/test_alchemical_free_energy.py b/tests/Sandpit/Exscientia/FreeEnergy/test_alchemical_free_energy.py index 5c2b8f952..873c654d5 100644 --- a/tests/Sandpit/Exscientia/FreeEnergy/test_alchemical_free_energy.py +++ b/tests/Sandpit/Exscientia/FreeEnergy/test_alchemical_free_energy.py @@ -14,6 +14,7 @@ has_gromacs, url, ) +from tests.conftest import root_fp import BioSimSpace.Sandpit.Exscientia as BSS from BioSimSpace.Sandpit.Exscientia.Protocol import FreeEnergyEquilibration @@ -133,7 +134,9 @@ class TestAnalysePARQUET: @pytest.fixture(scope="class") def data(tmp_path_factory): outdir = tmp_path_factory.mktemp("out") - shutil.copytree("tests/Sandpit/Exscientia/input/parquet", outdir / "parquet") + shutil.copytree( + f"{root_fp}/Sandpit/Exscientia/input/parquet", outdir / "parquet" + ) return str(outdir / "parquet") def test_analyse(self, data): @@ -153,7 +156,9 @@ class Test_gmx_ABFE: @staticmethod @pytest.fixture(scope="class") def freenrg(): - m = BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"])[0] + m = BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + )[0] decouple_m = decouple(m) solvated = BSS.Solvent.tip3p( molecule=decouple_m, box=3 * [3 * BSS.Units.Length.nanometer] diff --git a/tests/Sandpit/Exscientia/Gateway/test_file.py b/tests/Sandpit/Exscientia/Gateway/test_file.py index e36faf36f..ea098822d 100644 --- a/tests/Sandpit/Exscientia/Gateway/test_file.py +++ b/tests/Sandpit/Exscientia/Gateway/test_file.py @@ -1,6 +1,7 @@ import pytest from BioSimSpace.Sandpit.Exscientia.Gateway import File +from tests.conftest import root_fp def test_no_arguments(): @@ -10,7 +11,9 @@ def test_no_arguments(): f = File() -@pytest.mark.parametrize("value", ["tests/input/ala.crd", "tests/input/ala.top"]) +@pytest.mark.parametrize( + "value", [f"{root_fp}/input/ala.crd", f"{root_fp}/input/ala.top"] +) def test_value(value): """Test whether object is initialised correctly and value is set.""" diff --git a/tests/Sandpit/Exscientia/Gateway/test_fileset.py b/tests/Sandpit/Exscientia/Gateway/test_fileset.py index d2e1b0216..9b4bdf9e5 100644 --- a/tests/Sandpit/Exscientia/Gateway/test_fileset.py +++ b/tests/Sandpit/Exscientia/Gateway/test_fileset.py @@ -1,6 +1,7 @@ import pytest from BioSimSpace.Sandpit.Exscientia.Gateway import FileSet +from tests.conftest import root_fp def test_no_arguments(): @@ -13,11 +14,11 @@ def test_no_arguments(): @pytest.mark.parametrize( "value", [ - ["tests/input/ala.crd", "tests/input/ala.top"], + [f"{root_fp}/input/ala.crd", f"{root_fp}/input/ala.top"], [ - "tests/input/alanin.pdb", - "tests/input/alanin.psf", - "tests/input/alanin.params", + f"{root_fp}/input/alanin.pdb", + f"{root_fp}/input/alanin.psf", + f"{root_fp}/input/alanin.params", ], ], ) @@ -58,7 +59,7 @@ def test_missing_files(): # One file missing. with pytest.raises(IOError): f = FileSet(help="Help!") - f.setValue(["tests/input/amber/ala/ala.crd", "missing2.txt"]) + f.setValue([f"{root_fp}/input/amber/ala/ala.crd", "missing2.txt"]) @pytest.mark.parametrize("optional", [True, False]) diff --git a/tests/Sandpit/Exscientia/Gateway/test_node.py b/tests/Sandpit/Exscientia/Gateway/test_node.py index 3d47cbd3a..61e9ff047 100644 --- a/tests/Sandpit/Exscientia/Gateway/test_node.py +++ b/tests/Sandpit/Exscientia/Gateway/test_node.py @@ -4,9 +4,10 @@ import sys import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp # Store the name of the test script. -script_name = "tests/Gateway/node.py" +script_name = f"{root_fp}/Gateway/node.py" # Store the name of the python interpreter. exe = sys.executable diff --git a/tests/Sandpit/Exscientia/IO/test_file_cache.py b/tests/Sandpit/Exscientia/IO/test_file_cache.py index cce3c62a8..92e0a8d91 100644 --- a/tests/Sandpit/Exscientia/IO/test_file_cache.py +++ b/tests/Sandpit/Exscientia/IO/test_file_cache.py @@ -6,6 +6,7 @@ import BioSimSpace.Sandpit.Exscientia as BSS from tests.Sandpit.Exscientia.conftest import has_amber, has_openff +from tests.conftest import root_fp def test_file_cache(): @@ -18,7 +19,7 @@ def test_file_cache(): BSS.IO._file_cache._cache = BSS.IO._file_cache._FixedSizeOrderedDict() # Load the molecular system. - s = BSS.IO.readMolecules(["tests/input/ala.crd", "tests/input/ala.top"]) + s = BSS.IO.readMolecules([f"{root_fp}/input/ala.crd", f"{root_fp}/input/ala.top"]) # Create a temporary working directory. tmp_dir = tempfile.TemporaryDirectory() diff --git a/tests/Sandpit/Exscientia/IO/test_tuple.py b/tests/Sandpit/Exscientia/IO/test_tuple.py index f4fc601bb..1f8700888 100644 --- a/tests/Sandpit/Exscientia/IO/test_tuple.py +++ b/tests/Sandpit/Exscientia/IO/test_tuple.py @@ -1,6 +1,7 @@ import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp def test_tuple(): """Check that we can read from a tuple of files.""" - BSS.IO.readMolecules(("tests/input/ala.crd", "tests/input/ala.top")) + BSS.IO.readMolecules((f"{root_fp}/input/ala.crd", f"{root_fp}/input/ala.top")) diff --git a/tests/Sandpit/Exscientia/MD/test_md.py b/tests/Sandpit/Exscientia/MD/test_md.py index f479d9ab1..f2afe28db 100644 --- a/tests/Sandpit/Exscientia/MD/test_md.py +++ b/tests/Sandpit/Exscientia/MD/test_md.py @@ -3,6 +3,7 @@ import BioSimSpace.Sandpit.Exscientia as BSS from tests.Sandpit.Exscientia.conftest import url, has_amber, has_gromacs, has_namd +from tests.conftest import root_fp @pytest.mark.skipif(has_amber is False, reason="Requires AMBER to be installed.") @@ -13,7 +14,9 @@ def test_amber(): protocol = BSS.Protocol.Minimisation(steps=100) # Load the molecular system. - system = BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + system = BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) # Initialise the AMBER process. process = BSS.MD.run(system, protocol, name="test") @@ -55,9 +58,9 @@ def test_namd(): # Load the molecular system. system = BSS.IO.readMolecules( [ - "tests/input/alanin.psf", - "tests/input/alanin.pdb", - "tests/input/alanin.params", + f"{root_fp}/input/alanin.psf", + f"{root_fp}/input/alanin.pdb", + f"{root_fp}/input/alanin.params", ] ) diff --git a/tests/Sandpit/Exscientia/Process/test_amber.py b/tests/Sandpit/Exscientia/Process/test_amber.py index 489f5bd84..60168a707 100644 --- a/tests/Sandpit/Exscientia/Process/test_amber.py +++ b/tests/Sandpit/Exscientia/Process/test_amber.py @@ -10,12 +10,15 @@ import BioSimSpace.Sandpit.Exscientia as BSS from tests.Sandpit.Exscientia.conftest import url, has_amber, has_pyarrow +from tests.conftest import root_fp @pytest.fixture(scope="session") def system(): """Re-use the same molecuar system for each test.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.mark.skipif( @@ -280,9 +283,9 @@ def test_parse_fep_output(system, protocol): # Assign the path to the output file. if isinstance(protocol, BSS.Protocol.FreeEnergy): - out_file = "tests/Sandpit/Exscientia/output/amber_fep.out" + out_file = f"{root_fp}/Sandpit/Exscientia/output/amber_fep.out" else: - out_file = "tests/Sandpit/Exscientia/output/amber_fep_min.out" + out_file = f"{root_fp}/Sandpit/Exscientia/output/amber_fep_min.out" # Copy the existing output file into the working directory. shutil.copyfile(out_file, process.workDir() + "/amber.out") @@ -320,7 +323,6 @@ def test_parse_fep_output(system, protocol): assert len(records_sc1) != 0 - class TestsaveMetric: @staticmethod @pytest.fixture() @@ -334,7 +336,6 @@ def alchemical_system(system): system_copy.updateMolecule(0, mol) return system_copy - @staticmethod @pytest.fixture() def setup(alchemical_system): @@ -344,7 +345,7 @@ def setup(alchemical_system): BSS.Protocol.FreeEnergy(temperature=298 * BSS.Units.Temperature.kelvin), ) shutil.copyfile( - "tests/Sandpit/Exscientia/output/amber_fep.out", + f"{root_fp}/Sandpit/Exscientia/output/amber_fep.out", process.workDir() + "/amber.out", ) process.saveMetric() @@ -357,10 +358,9 @@ def test_error_alchemlyb_extract(self, alchemical_system): BSS.Protocol.FreeEnergy(temperature=298 * BSS.Units.Temperature.kelvin), ) process.wait() - with open(process.workDir() + '/amber.err', 'r') as f: + with open(process.workDir() + "/amber.err", "r") as f: text = f.read() - assert 'Exception Information' in text - + assert "Exception Information" in text def test_metric_parquet_exist(self, setup): assert Path(f"{setup.workDir()}/metric.parquet").exists() diff --git a/tests/Sandpit/Exscientia/Process/test_dummy_protocol.py b/tests/Sandpit/Exscientia/Process/test_dummy_protocol.py index a50c5e533..fa063d427 100644 --- a/tests/Sandpit/Exscientia/Process/test_dummy_protocol.py +++ b/tests/Sandpit/Exscientia/Process/test_dummy_protocol.py @@ -1,6 +1,7 @@ import pytest from tests.Sandpit.Exscientia.conftest import has_amber, has_gromacs +from tests.conftest import root_fp import BioSimSpace.Sandpit.Exscientia as BSS from BioSimSpace.Sandpit.Exscientia.Process._process import Process @@ -9,7 +10,9 @@ @pytest.fixture(scope="session") def system(): """Re-use the same molecuar system for each test.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.mark.skipif( diff --git a/tests/Sandpit/Exscientia/Process/test_gromacs.py b/tests/Sandpit/Exscientia/Process/test_gromacs.py index 1a42967c5..7d4e57c49 100644 --- a/tests/Sandpit/Exscientia/Process/test_gromacs.py +++ b/tests/Sandpit/Exscientia/Process/test_gromacs.py @@ -27,12 +27,15 @@ has_openff, has_pyarrow, ) +from tests.conftest import root_fp @pytest.fixture(scope="session") def system(): """Re-use the same molecuar system for each test.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.fixture(scope="session") @@ -254,7 +257,7 @@ def setup(perturbable_system): ) process = BSS.Process.Gromacs(perturbable_system, protocol) shutil.copyfile( - "tests/Sandpit/Exscientia/output/gromacs.edr", + f"{root_fp}/Sandpit/Exscientia/output/gromacs.edr", process.workDir() + "/gromacs.edr", ) shutil.copyfile( @@ -343,17 +346,18 @@ def test_u_nk_parquet(self, setup): def test_error_alchemlyb_extract(self, perturbable_system, monkeypatch): def extract(*args): - raise ValueError('alchemlyb.parsing.gmx.extract failed.') - monkeypatch.setattr('alchemlyb.parsing.gmx.extract', extract) + raise ValueError("alchemlyb.parsing.gmx.extract failed.") + + monkeypatch.setattr("alchemlyb.parsing.gmx.extract", extract) # Create a process using any system and the protocol. process = BSS.Process.Gromacs( perturbable_system, BSS.Protocol.FreeEnergy(temperature=298 * BSS.Units.Temperature.kelvin), ) process.wait() - with open(process.workDir() + '/gromacs.err', 'r') as f: + with open(process.workDir() + "/gromacs.err", "r") as f: text = f.read() - assert 'Exception Information' in text + assert "Exception Information" in text @pytest.mark.skipif( diff --git a/tests/Sandpit/Exscientia/Process/test_namd.py b/tests/Sandpit/Exscientia/Process/test_namd.py index 5327a4a28..3ad97f742 100644 --- a/tests/Sandpit/Exscientia/Process/test_namd.py +++ b/tests/Sandpit/Exscientia/Process/test_namd.py @@ -3,6 +3,7 @@ import BioSimSpace.Sandpit.Exscientia as BSS from tests.Sandpit.Exscientia.conftest import url, has_namd +from tests.conftest import root_fp @pytest.fixture(scope="session") @@ -10,9 +11,9 @@ def system(): """Re-use the same molecuar system for each test.""" return BSS.IO.readMolecules( [ - "tests/input/alanin.psf", - f"tests/input/alanin.pdb", - f"tests/input/alanin.params", + f"{root_fp}/input/alanin.psf", + f"{root_fp}/input/alanin.pdb", + f"{root_fp}/input/alanin.params", ] ) diff --git a/tests/Sandpit/Exscientia/Process/test_openmm.py b/tests/Sandpit/Exscientia/Process/test_openmm.py index f4a55342b..10c9f0045 100644 --- a/tests/Sandpit/Exscientia/Process/test_openmm.py +++ b/tests/Sandpit/Exscientia/Process/test_openmm.py @@ -4,12 +4,15 @@ import BioSimSpace.Sandpit.Exscientia as BSS from tests.Sandpit.Exscientia.conftest import url, has_amber, has_gromacs, has_openff +from tests.conftest import root_fp @pytest.fixture(scope="session") def system(): """Re-use the same molecuar system for each test.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.mark.parametrize("restraint", ["backbone", "heavy", "all", "none"]) diff --git a/tests/Sandpit/Exscientia/Process/test_somd.py b/tests/Sandpit/Exscientia/Process/test_somd.py index 11ecc6ba0..ca81a539c 100644 --- a/tests/Sandpit/Exscientia/Process/test_somd.py +++ b/tests/Sandpit/Exscientia/Process/test_somd.py @@ -12,6 +12,7 @@ import warnings import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp # Store the tutorial URL. url = BSS.tutorialUrl() @@ -20,7 +21,9 @@ @pytest.fixture(scope="session") def system(): """Re-use the same molecuar system for each test.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.fixture(scope="session") @@ -91,7 +94,7 @@ def test_pert_file(): BSS.Process._somd._to_pert_file(mol) # Check that the files are the same. - assert filecmp.cmp("MORPH.pert", "tests/input/morph.pert") + assert filecmp.cmp("MORPH.pert", f"{root_fp}/input/morph.pert") # Remove the temporary perturbation file. os.remove("MORPH.pert") diff --git a/tests/Sandpit/Exscientia/Stream/test_stream.py b/tests/Sandpit/Exscientia/Stream/test_stream.py index bf40c3993..432110cbc 100644 --- a/tests/Sandpit/Exscientia/Stream/test_stream.py +++ b/tests/Sandpit/Exscientia/Stream/test_stream.py @@ -2,11 +2,14 @@ import pytest import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp @pytest.fixture def system(scope="session"): - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.fixture(autouse=True) diff --git a/tests/Sandpit/Exscientia/Trajectory/test_trajectory.py b/tests/Sandpit/Exscientia/Trajectory/test_trajectory.py index 667c0fea7..6711d806e 100644 --- a/tests/Sandpit/Exscientia/Trajectory/test_trajectory.py +++ b/tests/Sandpit/Exscientia/Trajectory/test_trajectory.py @@ -11,20 +11,23 @@ def wrap(arg): from tests.Sandpit.Exscientia.conftest import has_mdanalysis, has_mdtraj +from tests.conftest import root_fp @pytest.fixture(scope="session") def system(): """A system object with the same topology as the trajectories.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.fixture(scope="session") def traj_sire(system): """A trajectory object using the Sire backend.""" return BSS.Trajectory.Trajectory( - trajectory="tests/input/ala.trr", - topology="tests/input/ala.gro", + trajectory=f"{root_fp}/input/ala.trr", + topology=f"{root_fp}/input/ala.gro", system=system, backend="SIRE", ) @@ -34,8 +37,8 @@ def traj_sire(system): def traj_mdtraj(system): """A trajectory object using the MDTraj backend.""" return BSS.Trajectory.Trajectory( - trajectory="tests/input/ala.trr", - topology="tests/input/ala.gro", + trajectory=f"{root_fp}/input/ala.trr", + topology=f"{root_fp}/input/ala.gro", system=system, backend="MDTRAJ", ) @@ -45,8 +48,8 @@ def traj_mdtraj(system): def traj_mdanalysis(system): """A trajectory object using the MDAnalysis backend.""" return BSS.Trajectory.Trajectory( - trajectory="tests/input/ala.trr", - topology="tests/input/ala.tpr", + trajectory=f"{root_fp}/input/ala.trr", + topology=f"{root_fp}/input/ala.tpr", system=system, backend="MDANALYSIS", ) @@ -58,8 +61,8 @@ def traj_mdanalysis_pdb(system): new_system = system.copy() new_system._sire_object.setProperty("fileformat", wrap("PDB")) return BSS.Trajectory.Trajectory( - trajectory="tests/input/ala.trr", - topology="tests/input/ala.tpr", + trajectory=f"{root_fp}/input/ala.trr", + topology=f"{root_fp}/input/ala.tpr", system=new_system, backend="MDANALYSIS", ) diff --git a/tests/Sandpit/Exscientia/_SireWrappers/test_bond.py b/tests/Sandpit/Exscientia/_SireWrappers/test_bond.py index bab5be6d8..861e49241 100644 --- a/tests/Sandpit/Exscientia/_SireWrappers/test_bond.py +++ b/tests/Sandpit/Exscientia/_SireWrappers/test_bond.py @@ -1,10 +1,13 @@ import pytest import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp def test_bonds(): - system = BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + system = BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) bonds = system.search("bonds") diff --git a/tests/Sandpit/Exscientia/_SireWrappers/test_molecule.py b/tests/Sandpit/Exscientia/_SireWrappers/test_molecule.py index f66f70db4..d19b385f8 100644 --- a/tests/Sandpit/Exscientia/_SireWrappers/test_molecule.py +++ b/tests/Sandpit/Exscientia/_SireWrappers/test_molecule.py @@ -3,11 +3,14 @@ import BioSimSpace.Sandpit.Exscientia as BSS from tests.Sandpit.Exscientia.conftest import url, has_amber, has_pyarrow +from tests.conftest import root_fp @pytest.fixture(scope="session") def system(): - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.mark.skipif( diff --git a/tests/Sandpit/Exscientia/_SireWrappers/test_properties.py b/tests/Sandpit/Exscientia/_SireWrappers/test_properties.py index 545bf249c..47bf616f1 100644 --- a/tests/Sandpit/Exscientia/_SireWrappers/test_properties.py +++ b/tests/Sandpit/Exscientia/_SireWrappers/test_properties.py @@ -1,8 +1,9 @@ import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp def test_sire_properties(): - s = BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + s = BSS.IO.readMolecules([f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"]) m = s[0]._sire_object diff --git a/tests/Sandpit/Exscientia/_SireWrappers/test_search_result.py b/tests/Sandpit/Exscientia/_SireWrappers/test_search_result.py index 45903da4f..aae552377 100644 --- a/tests/Sandpit/Exscientia/_SireWrappers/test_search_result.py +++ b/tests/Sandpit/Exscientia/_SireWrappers/test_search_result.py @@ -1,6 +1,7 @@ import pytest import BioSimSpace.Sandpit.Exscientia as BSS +from tests.conftest import root_fp # Store the tutorial URL. url = BSS.tutorialUrl() @@ -9,7 +10,9 @@ @pytest.fixture(scope="session") def system(): """Re-use the same molecuar system for each test.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) @pytest.fixture(scope="session") diff --git a/tests/Sandpit/Exscientia/_SireWrappers/test_system.py b/tests/Sandpit/Exscientia/_SireWrappers/test_system.py index f715ee05a..1d8948520 100644 --- a/tests/Sandpit/Exscientia/_SireWrappers/test_system.py +++ b/tests/Sandpit/Exscientia/_SireWrappers/test_system.py @@ -4,12 +4,15 @@ import BioSimSpace.Sandpit.Exscientia as BSS from tests.Sandpit.Exscientia.conftest import url, has_amber, has_openff +from tests.conftest import root_fp @pytest.fixture(scope="session") def system(): """Re-use the same molecuar system for each test.""" - return BSS.IO.readMolecules(["tests/input/ala.top", "tests/input/ala.crd"]) + return BSS.IO.readMolecules( + [f"{root_fp}/input/ala.top", f"{root_fp}/input/ala.crd"] + ) # Parameterise the function with a set of molecule indices. diff --git a/tests/conftest.py b/tests/conftest.py index 9c547f7c3..b303e6d82 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +from pathlib import Path + collect_ignore_glob = ["*/out_test*.py"] import os @@ -55,3 +57,5 @@ ) has_mdrestraints_generator = _have_imported(MDRestraintsGenerator) + +root_fp = Path(__file__).parent.resolve()