From 5344de2807bbd59ed5a0e13fd41f24121ca0a752 Mon Sep 17 00:00:00 2001 From: Kori Kuzma Date: Tue, 2 Apr 2024 09:41:46 -0400 Subject: [PATCH] tests: fix test data dir + update param name change (#319) --- tests/conftest.py | 5 +++ tests/unit/database/test_database.py | 45 ++++++++++--------- .../harvesters/moa/test_moa_assertions.py | 11 +++-- tests/unit/harvesters/moa/test_moa_harvest.py | 2 +- tests/unit/harvesters/moa/test_moa_source.py | 8 ++-- tests/unit/harvesters/test_civic_harvester.py | 7 +-- .../test_civic_transform_diagnostic.py | 4 +- .../test_civic_transform_prognostic.py | 4 +- .../test_civic_transform_therapeutic.py | 4 +- tests/unit/transform/test_moa_transform.py | 15 ++++--- 10 files changed, 57 insertions(+), 48 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 81197e35..b8168022 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,11 +1,16 @@ """Module for pytest fixtures.""" import json from copy import deepcopy +from pathlib import Path import pytest from metakb.normalizers import ViccNormalizers +TEST_DATA_DIR = Path(__file__).resolve().parents[0] / "data" +TEST_HARVESTERS_DIR = TEST_DATA_DIR / "harvesters" +TEST_TRANSFORM_DIR = TEST_DATA_DIR / "transform" + @pytest.fixture(scope="session") def cetuximab_extensions(): diff --git a/tests/unit/database/test_database.py b/tests/unit/database/test_database.py index c646346a..bcc2054d 100644 --- a/tests/unit/database/test_database.py +++ b/tests/unit/database/test_database.py @@ -207,7 +207,7 @@ def test_gene_rules( """Verify property and relationship rules for Gene nodes.""" check_unique_property("Gene", "id") check_relation_count( - "Gene", "Study", "HAS_GENE_CONTEXT", direction="in", min=1, max=None + "Gene", "Study", "HAS_GENE_CONTEXT", direction="in", min_rels=1, max_rels=None ) expected_labels = [{"Gene"}] @@ -244,15 +244,15 @@ def test_variation_rules( "CategoricalVariation", "HAS_DEFINING_CONTEXT", direction="in", - min=0, - max=None, + min_rels=0, + max_rels=None, ) check_relation_count( "Variation", "CategoricalVariation", "HAS_MEMBERS", - min=0, - max=None, + min_rels=0, + max_rels=None, direction="in", ) @@ -315,10 +315,10 @@ def test_categorical_variation_rules( """Verify property and relationship rules for Categorical Variation nodes.""" check_unique_property("CategoricalVariation", "id") check_relation_count( - "CategoricalVariation", "Variation", "HAS_DEFINING_CONTEXT", max=1 + "CategoricalVariation", "Variation", "HAS_DEFINING_CONTEXT", max_rels=1 ) check_relation_count( - "CategoricalVariation", "Variation", "HAS_MEMBERS", min=0, max=None + "CategoricalVariation", "Variation", "HAS_MEMBERS", min_rels=0, max_rels=None ) expected_node_labels = [{"CategoricalVariation", "ProteinSequenceConsequence"}] @@ -369,7 +369,7 @@ def test_location_rules( """Verify property and relationship rules for Location nodes.""" check_unique_property("Location", "id") check_relation_count( - "Location", "Variation", "HAS_LOCATION", direction="in", max=None + "Location", "Variation", "HAS_LOCATION", direction="in", max_rels=None ) expected_labels = [{"Location", "SequenceLocation"}] @@ -409,30 +409,33 @@ def test_therapeutic_procedure_rules( ): """Verify property and relationship rules for Therapeutic Procedure nodes.""" check_unique_property("TherapeuticProcedure", "id") - # min is 0 because TherapeuticAgent may not be attached to study directly, but + # min_rels is 0 because TherapeuticAgent may not be attached to study directly, but # through CombinationTherapy and TherapeuticSubstituteGroup check_relation_count( "TherapeuticProcedure", "Study", "HAS_THERAPEUTIC", - min=0, - max=None, + min_rels=0, + max_rels=None, direction="in", ) check_relation_count( - "CombinationTherapy", "TherapeuticAgent", "HAS_COMPONENTS", max=None + "CombinationTherapy", "TherapeuticAgent", "HAS_COMPONENTS", max_rels=None ) check_relation_count( - "CombinationTherapy", "Study", "HAS_THERAPEUTIC", max=None, direction="in" + "CombinationTherapy", "Study", "HAS_THERAPEUTIC", max_rels=None, direction="in" ) check_relation_count( - "TherapeuticSubstituteGroup", "TherapeuticAgent", "HAS_SUBSTITUTES", max=None + "TherapeuticSubstituteGroup", + "TherapeuticAgent", + "HAS_SUBSTITUTES", + max_rels=None, ) check_relation_count( "TherapeuticSubstituteGroup", "Study", "HAS_THERAPEUTIC", - max=None, + max_rels=None, direction="in", ) @@ -485,7 +488,7 @@ def test_condition_rules( """Verify property and relationship rules for condition nodes.""" check_unique_property("Condition", "id") check_relation_count( - "Condition", "Study", "HAS_TUMOR_TYPE", max=None, direction="in" + "Condition", "Study", "HAS_TUMOR_TYPE", max_rels=None, direction="in" ) expected_node_labels = [{"Disease", "Condition"}] @@ -514,8 +517,8 @@ def test_study_rules( check_relation_count("Study", "Condition", "HAS_TUMOR_TYPE") check_relation_count("Study", "TherapeuticProcedure", "HAS_THERAPEUTIC") check_relation_count("Study", "Coding", "HAS_STRENGTH") - check_relation_count("Study", "Method", "IS_SPECIFIED_BY", max=None) - check_relation_count("Study", "Gene", "HAS_GENE_CONTEXT", max=None) + check_relation_count("Study", "Method", "IS_SPECIFIED_BY", max_rels=None) + check_relation_count("Study", "Gene", "HAS_GENE_CONTEXT", max_rels=None) expected_node_labels = [{"Study", "VariantTherapeuticResponseStudy"}] check_node_labels("Study", expected_node_labels, 1) @@ -560,7 +563,7 @@ def test_document_rules( """Verify property and relationship rules for Document nodes.""" check_unique_property("Document", "id") check_relation_count( - "Document", "Study", "IS_REPORTED_IN", min=0, max=None, direction="in" + "Document", "Study", "IS_REPORTED_IN", min_rels=0, max_rels=None, direction="in" ) expected_labels = [{"Document"}] @@ -604,7 +607,9 @@ def test_method_rules( ): """Verify property and relationship rules for Method nodes.""" check_unique_property("Method", "id") - check_relation_count("Method", "Study", "IS_SPECIFIED_BY", max=None, direction="in") + check_relation_count( + "Method", "Study", "IS_SPECIFIED_BY", max_rels=None, direction="in" + ) expected_node_labels = [{"Method"}] check_node_labels("Method", expected_node_labels, 1) diff --git a/tests/unit/harvesters/moa/test_moa_assertions.py b/tests/unit/harvesters/moa/test_moa_assertions.py index 88c02d9a..4ff84f98 100644 --- a/tests/unit/harvesters/moa/test_moa_assertions.py +++ b/tests/unit/harvesters/moa/test_moa_assertions.py @@ -4,9 +4,9 @@ from unittest.mock import patch import pytest +from tests.conftest import TEST_HARVESTERS_DIR -from metakb import PROJECT_ROOT -from metakb.harvesters import MoaHarvester +from metakb.harvesters.moa import MoaHarvester @pytest.fixture(scope="module") @@ -54,13 +54,12 @@ def assertion165(): @patch.object(MoaHarvester, "_get_all_assertions") def test_assertion_170(test_get_all_assertions, test_get_all_variants, assertion165): """Test moa harvester works correctly for assertions.""" - with ( - PROJECT_ROOT / "tests" / "data" / "harvesters/moa/assertions.json" - ).open() as f: + moa_harvester_test_dir = TEST_HARVESTERS_DIR / "moa" + with (moa_harvester_test_dir / "assertions.json").open() as f: data = json.load(f) test_get_all_assertions.return_value = data - with (PROJECT_ROOT / "tests" / "data" / "harvesters/moa/variants.json").open() as f: + with (moa_harvester_test_dir / "variants.json").open() as f: data = json.load(f) test_get_all_variants.return_value = data diff --git a/tests/unit/harvesters/moa/test_moa_harvest.py b/tests/unit/harvesters/moa/test_moa_harvest.py index 1520025d..e06e2a73 100644 --- a/tests/unit/harvesters/moa/test_moa_harvest.py +++ b/tests/unit/harvesters/moa/test_moa_harvest.py @@ -1,7 +1,7 @@ """Test MOAlmanac Harvester.""" from metakb import APP_ROOT -from metakb.harvesters import MoaHarvester +from metakb.harvesters.moa import MoaHarvester def test_harvest(): diff --git a/tests/unit/harvesters/moa/test_moa_source.py b/tests/unit/harvesters/moa/test_moa_source.py index e87c55ed..4dcfdf17 100644 --- a/tests/unit/harvesters/moa/test_moa_source.py +++ b/tests/unit/harvesters/moa/test_moa_source.py @@ -3,9 +3,9 @@ from unittest.mock import patch import pytest +from tests.conftest import TEST_HARVESTERS_DIR -from metakb import PROJECT_ROOT -from metakb.harvesters import MoaHarvester +from metakb.harvesters.moa import MoaHarvester @pytest.fixture(scope="module") @@ -33,9 +33,7 @@ def source68(): @patch.object(MoaHarvester, "_get_all_assertions") def test_source68(test_get_all_assertions, source68): """Test moa harvester works correctly for evidence.""" - with ( - PROJECT_ROOT / "tests" / "data" / "harvesters/moa/assertions.json" - ).open() as f: + with (TEST_HARVESTERS_DIR / "moa" / "assertions.json").open() as f: data = json.load(f) test_get_all_assertions.return_value = data diff --git a/tests/unit/harvesters/test_civic_harvester.py b/tests/unit/harvesters/test_civic_harvester.py index 2b5300ed..23d7dde8 100644 --- a/tests/unit/harvesters/test_civic_harvester.py +++ b/tests/unit/harvesters/test_civic_harvester.py @@ -2,11 +2,12 @@ import json import pytest +from tests.conftest import TEST_HARVESTERS_DIR -from metakb import APP_ROOT, PROJECT_ROOT -from metakb.harvesters import CivicHarvester +from metakb import APP_ROOT +from metakb.harvesters.civic import CivicHarvester -TEST_DATA_PATH = PROJECT_ROOT / "tests" / "data" / "harvesters" / "civic" +TEST_DATA_PATH = TEST_HARVESTERS_DIR / "civic" TEST_CIVICPY_CACHE_PATH = sorted(TEST_DATA_PATH.glob("civicpy_cache_*.pkl"))[-1] diff --git a/tests/unit/transform/test_civic_transform_diagnostic.py b/tests/unit/transform/test_civic_transform_diagnostic.py index a89ff8af..54f69aeb 100644 --- a/tests/unit/transform/test_civic_transform_diagnostic.py +++ b/tests/unit/transform/test_civic_transform_diagnostic.py @@ -3,11 +3,11 @@ import pytest import pytest_asyncio +from tests.conftest import TEST_TRANSFORM_DIR -from metakb import PROJECT_ROOT from metakb.transform.civic import CivicTransform -DATA_DIR = PROJECT_ROOT / "tests" / "data" / "transform" / "diagnostic" +DATA_DIR = TEST_TRANSFORM_DIR / "diagnostic" FILENAME = "civic_cdm.json" diff --git a/tests/unit/transform/test_civic_transform_prognostic.py b/tests/unit/transform/test_civic_transform_prognostic.py index 75e41261..a4cb02ce 100644 --- a/tests/unit/transform/test_civic_transform_prognostic.py +++ b/tests/unit/transform/test_civic_transform_prognostic.py @@ -3,11 +3,11 @@ import pytest import pytest_asyncio +from tests.conftest import TEST_TRANSFORM_DIR -from metakb import PROJECT_ROOT from metakb.transform.civic import CivicTransform -DATA_DIR = PROJECT_ROOT / "tests" / "data" / "transform" / "prognostic" +DATA_DIR = TEST_TRANSFORM_DIR / "prognostic" FILENAME = "civic_cdm.json" diff --git a/tests/unit/transform/test_civic_transform_therapeutic.py b/tests/unit/transform/test_civic_transform_therapeutic.py index d1f99cd5..6be49bd9 100644 --- a/tests/unit/transform/test_civic_transform_therapeutic.py +++ b/tests/unit/transform/test_civic_transform_therapeutic.py @@ -3,11 +3,11 @@ import pytest import pytest_asyncio +from tests.conftest import TEST_TRANSFORM_DIR -from metakb import PROJECT_ROOT from metakb.transform.civic import CivicTransform -DATA_DIR = PROJECT_ROOT / "tests" / "data" / "transform" / "therapeutic" +DATA_DIR = TEST_TRANSFORM_DIR / "therapeutic" FILENAME = "civic_cdm.json" diff --git a/tests/unit/transform/test_moa_transform.py b/tests/unit/transform/test_moa_transform.py index 00686e73..e4e9a9d5 100644 --- a/tests/unit/transform/test_moa_transform.py +++ b/tests/unit/transform/test_moa_transform.py @@ -3,11 +3,10 @@ import pytest import pytest_asyncio +from tests.conftest import TEST_TRANSFORM_DIR -from metakb import PROJECT_ROOT from metakb.transform.moa import MoaTransform -DATA_DIR = PROJECT_ROOT / "tests" / "data" / "transform" FILENAME = "moa_cdm.json" @@ -15,13 +14,15 @@ @pytest.mark.asyncio() async def data(normalizers): """Create a MOA Transform test fixture.""" - harvester_path = DATA_DIR / "moa_harvester.json" + harvester_path = TEST_TRANSFORM_DIR / "moa_harvester.json" moa = MoaTransform( - data_dir=DATA_DIR, harvester_path=harvester_path, normalizers=normalizers + data_dir=TEST_TRANSFORM_DIR, + harvester_path=harvester_path, + normalizers=normalizers, ) await moa.transform() - moa.create_json(transform_dir=DATA_DIR, filename=FILENAME) - with (DATA_DIR / FILENAME).open() as f: + moa.create_json(transform_dir=TEST_TRANSFORM_DIR, filename=FILENAME) + with (TEST_TRANSFORM_DIR / FILENAME).open() as f: return json.load(f) @@ -196,4 +197,4 @@ def studies(moa_aid66_study, moa_aid155_study): def test_moa_cdm(data, studies, check_transformed_cdm): """Test that moa transform works correctly.""" - check_transformed_cdm(data, studies, DATA_DIR / FILENAME) + check_transformed_cdm(data, studies, TEST_TRANSFORM_DIR / FILENAME)