Skip to content

Commit

Permalink
Removed json test files
Browse files Browse the repository at this point in the history
  • Loading branch information
alongreyber committed Apr 22, 2021
1 parent 95ca4ff commit ace405b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 181 deletions.
49 changes: 0 additions & 49 deletions tests/query_planner/ex1_kps.json

This file was deleted.

25 changes: 0 additions & 25 deletions tests/query_planner/ex1_qg.json

This file was deleted.

49 changes: 0 additions & 49 deletions tests/query_planner/ex2_qg.json

This file was deleted.

47 changes: 36 additions & 11 deletions tests/query_planner/test_query_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from tests.helpers.context import \
with_registry_overlay, with_norm_overlay
from tests.helpers.utils import load_kps, generate_kps, validate_template, \
from tests.helpers.utils import generate_kps, validate_template, \
time_and_display, query_graph_from_string, \
kps_from_string, plan_template_from_string
from tests.helpers.logger import assert_no_level
Expand All @@ -22,8 +22,6 @@
from strider.config import settings
from strider.util import standardize_graph_lists

cwd = Path(__file__).parent

# Switch prefix path before importing server
settings.kpregistry_url = "http://registry"
settings.normalizer_url = "http://normalizer"
Expand Down Expand Up @@ -335,16 +333,30 @@ async def test_plan_double_loop(caplog):
assert_no_level(caplog, logging.WARNING)


ex1_kps = load_kps(cwd / "ex1_kps.json")


@pytest.mark.asyncio
@with_registry_overlay(settings.kpregistry_url, ex1_kps)
@with_registry_overlay(
settings.kpregistry_url,
kps_from_string(
"""
kp0 biolink:Disease -biolink:treated_by-> biolink:Drug
kp1 biolink:Drug -biolink:affects-> biolink:Gene
kp2 biolink:MolecularEntity -biolink:decreases_abundance_of-> biolink:GeneOrGeneProduct
kp3 biolink:Disease -biolink:treated_by-> biolink:MolecularEntity
"""
)
)
@with_norm_overlay(settings.normalizer_url)
async def test_plan_ex1(caplog):
""" Test that we get a good plan for our first example """
with open(cwd / "ex1_qg.json", "r") as f:
qg = json.load(f)
qg = query_graph_from_string(
"""
n0(( category biolink:MolecularEntity ))
n1(( id MONDO:0005148 ))
n2(( category biolink:GeneOrGeneProduct ))
n1-- biolink:treated_by -->n0
n0-- biolink:affects_abundance_of -->n2
"""
)
await prepare_query_graph(qg)

plans = await generate_plans(qg)
Expand Down Expand Up @@ -601,8 +613,21 @@ async def test_planning_performance_typical_example():
We should be able to do better on performance using our filtering methods.
"""

with open(cwd / "ex2_qg.json", "r") as f:
qg = json.load(f)
qg = query_graph_from_string(
"""
n0(( id MONDO:0005737 ))
n1(( category biolink:BiologicalProcessOrActivity ))
n2(( category biolink:AnatomicalEntity ))
n3(( category biolink:PhenotypicFeature ))
n4(( category biolink:PhenotypicFeature ))
n5(( id MONDO:6801 ))
n0-- biolink:related_to -->n1
n1-- biolink:related_to -->n2
n2-- biolink:related_to -->n3
n3-- biolink:related_to -->n4
n4-- biolink:related_to -->n5
"""
)
await prepare_query_graph(qg)

async def testable_generate_plans():
Expand Down
26 changes: 0 additions & 26 deletions tests/server/ex1_qg.json

This file was deleted.

88 changes: 67 additions & 21 deletions tests/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

setup_logger()

cwd = Path(__file__).parent

DEFAULT_PREFIXES = {
"biolink:Disease": ["MONDO", "DOID"],
"biolink:ChemicalSubstance": ["CHEBI", "MESH"],
Expand Down Expand Up @@ -61,8 +59,16 @@
)
async def test_solve_ex1():
"""Test solving the ex1 query graph"""
with open(cwd / "ex1_qg.json", "r") as f:
QGRAPH = json.load(f)
QGRAPH = query_graph_from_string(
"""
n0(( id CHEBI:6801 ))
n0(( category biolink:ChemicalSubstance ))
n1(( category biolink:Disease ))
n2(( category biolink:PhenotypicFeature ))
n0-- biolink:treats -->n1
n1-- biolink:has_phenotype -->n2
"""
)

# Create query
q = Query(
Expand All @@ -89,8 +95,8 @@ async def test_solve_ex1():
n1 MONDO:0005148
n2 HP:0004324
edge_bindings:
e01 CHEBI:6801-MONDO:0005148
e12 MONDO:0005148-HP:0004324
n0n1 CHEBI:6801-MONDO:0005148
n1n2 MONDO:0005148-HP:0004324
"""
],
},
Expand Down Expand Up @@ -158,11 +164,19 @@ async def test_duplicate_results():
}
)
async def test_solve_missing_predicate():
"""Test solving the ex1 query graph, in which one of the predicates is missing. """
with open(cwd / "ex1_qg.json", "r") as f:
QGRAPH = json.load(f)
"""Test solving a query graph, in which one of the predicates is missing. """
QGRAPH = query_graph_from_string(
"""
n0(( id CHEBI:6801 ))
n0(( category biolink:ChemicalSubstance ))
n1(( category biolink:Disease ))
n2(( category biolink:PhenotypicFeature ))
n0-- biolink:treats -->n1
n1-- biolink:has_phenotype -->n2
"""
)

del QGRAPH['edges']['e01']['predicate']
del QGRAPH['edges']['n0n1']['predicate']

# Create query
q = Query(
Expand Down Expand Up @@ -195,8 +209,16 @@ async def test_solve_missing_predicate():
)
async def test_solve_missing_category():
"""Test solving the ex1 query graph, in which one of the categories is missing. """
with open(cwd / "ex1_qg.json", "r") as f:
QGRAPH = json.load(f)
QGRAPH = query_graph_from_string(
"""
n0(( id CHEBI:6801 ))
n0(( category biolink:ChemicalSubstance ))
n1(( category biolink:Disease ))
n2(( category biolink:PhenotypicFeature ))
n0-- biolink:treats -->n1
n1-- biolink:has_phenotype -->n2
"""
)

del QGRAPH['nodes']['n0']['category']

Expand Down Expand Up @@ -356,8 +378,16 @@ async def test_solve_loop(caplog):
)
async def test_log_level_param():
"""Test that changing the log level changes the output """
with open(cwd / "ex1_qg.json", "r") as f:
QGRAPH = json.load(f)
QGRAPH = query_graph_from_string(
"""
n0(( id CHEBI:6801 ))
n0(( category biolink:ChemicalSubstance ))
n1(( category biolink:Disease ))
n2(( category biolink:PhenotypicFeature ))
n0-- biolink:treats -->n1
n1-- biolink:has_phenotype -->n2
"""
)

# Create query
q = Query(
Expand Down Expand Up @@ -403,10 +433,18 @@ async def test_log_level_param():
"""
}
)
async def test_plan_ex1():
async def test_plan_endpoint():
"""Test /plan endpoint"""
with open(cwd / "ex1_qg.json", "r") as f:
QGRAPH = json.load(f)
QGRAPH = query_graph_from_string(
"""
n0(( id CHEBI:6801 ))
n0(( category biolink:ChemicalSubstance ))
n1(( category biolink:Disease ))
n2(( category biolink:PhenotypicFeature ))
n0-- biolink:treats -->n1
n1-- biolink:has_phenotype -->n2
"""
)

# Create query
q = Query(
Expand All @@ -422,8 +460,8 @@ async def test_plan_ex1():
plan = output[0]

# Two steps in the plan each with KPs to contact
assert len(plan['n0-e01-n1']) == 2
assert len(plan['n1-e12-n2']) == 1
assert len(plan['n0-n0n1-n1']) == 2
assert len(plan['n1-n1n2-n2']) == 1


@pytest.mark.asyncio
Expand Down Expand Up @@ -464,8 +502,16 @@ async def test_kp_500():
Test that when a KP returns a 500 error we add
a message to the log but continue running
"""
with open(cwd / "ex1_qg.json", "r") as f:
QGRAPH = json.load(f)
QGRAPH = query_graph_from_string(
"""
n0(( id CHEBI:6801 ))
n0(( category biolink:ChemicalSubstance ))
n1(( category biolink:Disease ))
n2(( category biolink:PhenotypicFeature ))
n0-- biolink:treats -->n1
n1-- biolink:has_phenotype -->n2
"""
)

# Create query
q = Query(
Expand Down

0 comments on commit ace405b

Please sign in to comment.