diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..474ef68 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,52 @@ +import os +from pathlib import Path + +import pytest +import torch + +TEST_DIR = Path(__file__).parent +ENV_PDB_DIR = os.environ.get("ENV_PDB_DIR") +PDB_BASE_DIR = Path(ENV_PDB_DIR) if ENV_PDB_DIR else TEST_DIR / "test_files" + + +@pytest.fixture +def device(): + return torch.device("cuda" if torch.cuda.is_available() else "cpu") + +@pytest.fixture(scope="session") +def pdb_base_dir(): + """Wrapper of constant PDB_BASE_DIR. + """ + return PDB_BASE_DIR + + +def _resolve_pdb_path(pdb_id): + """Resolves a PDB path, skipping if missing.""" + path = PDB_BASE_DIR / pdb_id / f"{pdb_id}_final.pdb" + if not path.exists(): + pytest.skip(f"PDB file not found: {path}") + return str(path) + + +@pytest.fixture +def pdb_6eey(): + """6eey - standard PDB that passes all quality checks.""" + return _resolve_pdb_path("6eey") + + +@pytest.fixture +def pdb_2b5w(): + """2b5w - fails COM distance check.""" + return _resolve_pdb_path("2b5w") + + +@pytest.fixture +def pdb_8dzt(): + """8dzt - fails water clash check at 2% threshold with 2A distance.""" + return _resolve_pdb_path("8dzt") + + +@pytest.fixture +def pdb_1deu(): + """1deu - has insertion codes (52 residues with ins_code='P').""" + return _resolve_pdb_path("1deu") diff --git a/tests/test_dataset.py b/tests/test_dataset.py index e97aaed..80c5975 100644 --- a/tests/test_dataset.py +++ b/tests/test_dataset.py @@ -19,8 +19,6 @@ All test cases created with assistance from Claude Code. """ -from pathlib import Path - import numpy as np import pytest import torch @@ -44,39 +42,6 @@ ) -@pytest.fixture -def pdb_base_dir(): - """Base directory for PDB files.""" - return Path("/sb/wankowicz_lab/data/srivasv/pdb_redo_data") - - -@pytest.fixture -def pdb_6eey(pdb_base_dir): - """Path to 6eey PDB file - should pass all quality checks.""" - path = pdb_base_dir / "6eey" / "6eey_final.pdb" - if not path.exists(): - pytest.skip(f"PDB file not found: {path}") - return str(path) - - -@pytest.fixture -def pdb_2b5w(pdb_base_dir): - """Path to 2b5w PDB file - should fail COM distance check.""" - path = pdb_base_dir / "2b5w" / "2b5w_final.pdb" - if not path.exists(): - pytest.skip(f"PDB file not found: {path}") - return str(path) - - -@pytest.fixture -def pdb_8dzt(pdb_base_dir): - """Path to 8dzt PDB file - should fail water clash check at 2% threshold.""" - path = pdb_base_dir / "8dzt" / "8dzt_final.pdb" - if not path.exists(): - pytest.skip(f"PDB file not found: {path}") - return str(path) - - @pytest.fixture def tmp_processed_dir(tmp_path): """Temporary directory for processed files.""" diff --git a/tests/test_encoder.py b/tests/test_encoder.py index f48531b..bd0b760 100644 --- a/tests/test_encoder.py +++ b/tests/test_encoder.py @@ -20,11 +20,6 @@ # ============== Fixtures ============== -@pytest.fixture -def device(): - return torch.device("cuda" if torch.cuda.is_available() else "cpu") - - @pytest.fixture def sample_homogeneous_data(): """Sample Data for testing ProteinGVPEncoder directly.""" diff --git a/test_files/6eey_final.pdb b/tests/test_files/6eey/6eey_final.pdb similarity index 100% rename from test_files/6eey_final.pdb rename to tests/test_files/6eey/6eey_final.pdb diff --git a/tests/test_flow.py b/tests/test_flow.py index 7990f6a..22db8f5 100644 --- a/tests/test_flow.py +++ b/tests/test_flow.py @@ -19,11 +19,6 @@ from src.gvp_encoder import GVPEncoder, ProteinGVPEncoder, make_encoder_data -@pytest.fixture -def device(): - return torch.device("cuda" if torch.cuda.is_available() else "cpu") - - @pytest.fixture def simple_hetero_data(device): """Minimal HeteroData with protein and water nodes.""" diff --git a/tests/test_forward.py b/tests/test_forward.py index d15da6d..ef415cd 100644 --- a/tests/test_forward.py +++ b/tests/test_forward.py @@ -77,11 +77,6 @@ def __exit__(self, exc_type, exc, tb): return False # don't suppress exceptions -@pytest.fixture -def device(): - return torch.device("cuda" if torch.cuda.is_available() else "cpu") - - def make_batched_hetero( device, n_graphs=2,