Skip to content

Commit

Permalink
tests: fix test data dir + update param name change (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma authored Apr 2, 2024
1 parent f8dbd4e commit 5344de2
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 48 deletions.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
45 changes: 25 additions & 20 deletions tests/unit/database/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]
Expand Down Expand Up @@ -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",
)

Expand Down Expand Up @@ -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"}]
Expand Down Expand Up @@ -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"}]
Expand Down Expand Up @@ -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",
)

Expand Down Expand Up @@ -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"}]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"}]
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/harvesters/moa/test_moa_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/harvesters/moa/test_moa_harvest.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/harvesters/moa/test_moa_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions tests/unit/harvesters/test_civic_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/transform/test_civic_transform_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/transform/test_civic_transform_prognostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/transform/test_civic_transform_therapeutic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
15 changes: 8 additions & 7 deletions tests/unit/transform/test_moa_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@

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"


@pytest_asyncio.fixture(scope="module")
@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)


Expand Down Expand Up @@ -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)

0 comments on commit 5344de2

Please sign in to comment.