Skip to content

Commit

Permalink
Merge branch 'standards-for-ara-kp-specification'
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardBruskiewich committed Aug 5, 2022
2 parents ff589b0 + 004d931 commit 3f99e6e
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ coverage.xml
.hypothesis/
.pytest_cache/

# local Unit test configuration
pytest.ini

# Translations
*.mo
*.pot
Expand Down
3 changes: 0 additions & 3 deletions tests/onehop/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/test_results/
/test-database/
/file-report-unit-test-database/

# ignore local Pytest config file
pytest.ini
51 changes: 42 additions & 9 deletions tests/onehop/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import logging

from deprecation import deprecated
from pytest_harvest import get_session_results_dct

from reasoner_validator.biolink import check_biolink_model_compliance_of_input_edge
Expand Down Expand Up @@ -37,6 +38,11 @@
logger = logging.getLogger(__name__)


# TODO: temporary circuit breaker for (currently 4-August-2022)
# undisciplined edge test data sets (like from RTX-KG2c)
UNREASONABLE_NUMBER_OF_TEST_EDGES: int = 10


def pytest_sessionfinish(session):
""" Gather all results and save them to a csv.
Works both on worker and master nodes, and also with xdist disabled
Expand Down Expand Up @@ -360,13 +366,15 @@ def load_test_data_source(
component_catalog: Dict[str, Dict[str, Any]] = dict()


@deprecated
def cache_resource_metadata(metadata: Dict[str, Any]):
component = metadata['component']
assert component in ["KP", "ARA"]
resource_id: str = metadata['api_name']
component_catalog[resource_id] = metadata


@deprecated
def get_metadata_by_resource(resource_id: str) -> Optional[Dict[str, Any]]:
if resource_id in component_catalog:
metadata: Dict = component_catalog[resource_id]
Expand All @@ -375,6 +383,7 @@ def get_metadata_by_resource(resource_id: str) -> Optional[Dict[str, Any]]:
return None


@deprecated
def get_component_by_resource(resource_id: str) -> Optional[str]:
metadata: Dict = get_metadata_by_resource(resource_id)
if metadata and "component" in metadata:
Expand All @@ -386,6 +395,7 @@ def get_component_by_resource(resource_id: str) -> Optional[str]:
kp_edges_catalog: Dict[str, Dict[str, Union[int, str]]] = dict()


@deprecated
def add_kp_edge(resource_id: str, edge_idx: int, edge: Dict[str, Any]):
metadata: Dict = get_metadata_by_resource(resource_id)
assert metadata
Expand All @@ -396,6 +406,7 @@ def add_kp_edge(resource_id: str, edge_idx: int, edge: Dict[str, Any]):
metadata['edges'][edge_idx] = edge


@deprecated
def get_kp_edge(resource_id: str, edge_idx: int) -> Optional[Dict[str, Any]]:
metadata: Dict = get_metadata_by_resource(resource_id)
if metadata:
Expand All @@ -416,8 +427,8 @@ def generate_trapi_kp_tests(metafunc, trapi_version: str, biolink_version: str)
:param trapi_version, str, TRAPI release set to be used in the validation
:param biolink_version, str, Biolink Model release set to be used in the validation
"""
edges = []
idlist = []
edges: List = []
idlist: List = []

# TODO: test_run_id is currently unused in this method; it is otherwise an
# optional user session identifier for the test (can be an empty string)
Expand All @@ -439,7 +450,8 @@ def generate_trapi_kp_tests(metafunc, trapi_version: str, biolink_version: str)
)
continue

cache_resource_metadata(kpjson)
# No point in caching for latest implementation of reporting
# cache_resource_metadata(kpjson)

dataset_level_test_exclusions: Set = set()
if "exclude_tests" in kpjson:
Expand Down Expand Up @@ -490,8 +502,13 @@ def generate_trapi_kp_tests(metafunc, trapi_version: str, biolink_version: str)
f"generate_trapi_kp_tests(): input file '{source}' "
"is missing its 'infores' field value? Inferred from its API name?"
)
# create a pseudo-infores from a lower cased and hyphenated API name
kp_api_name: str = edge['kp_api_name']
edge['kp_source'] = f"infores:{kp_api_name.lower()}"
if not kp_api_name:
logger.warning("generate_trapi_kp_tests(): KP API Name is missing? Skipping entry...")
continue
kp_infores_object_id = kp_api_name.lower().replace("_", "-")
edge['kp_source'] = f"infores:{kp_infores_object_id}"

if 'source_type' in kpjson:
edge['kp_source_type'] = kpjson['source_type']
Expand Down Expand Up @@ -534,6 +551,10 @@ def generate_trapi_kp_tests(metafunc, trapi_version: str, biolink_version: str)
if metafunc.config.getoption('one', default=False):
break

# Circuit breaker for overly large edge test data sets
if edge_i > UNREASONABLE_NUMBER_OF_TEST_EDGES:
break

print(f"### End of Test Input Edges for KP '{kpjson['api_name']}' ###")

if "kp_trapi_case" in metafunc.fixturenames:
Expand Down Expand Up @@ -574,7 +595,8 @@ def generate_trapi_ara_tests(metafunc, kp_edges, trapi_version, biolink_version)
"""
kp_dict = defaultdict(list)
for e in kp_edges:
kp_dict[e['kp_api_name']].append(e)
# We connect ARA's to their KPs by infores (== kp_source) now...
kp_dict[e['kp_source']].append(e)

ara_edges = []
idlist = []
Expand All @@ -595,13 +617,24 @@ def generate_trapi_ara_tests(metafunc, kp_edges, trapi_version, biolink_version)
)
continue

cache_resource_metadata(arajson)
# No point in caching for latest implementation of reporting
# cache_resource_metadata(arajson)

for kp in arajson['KPs']:

# By replacing spaces in name with underscores,
# should give get the KP "api_name" indexing the edges.
kp = '_'.join(kp.split())
#
# TODO: use of KP infores ('kp_source') CURIES in the Registry ARA spec
# likely now completely breaks the old filename-centric
# (non-Registry) local test_triples mechanism for KP resolution
# # By replacing spaces in name with underscores,
# # should give get the KP "api_name" indexing the edges.
# kp = '_'.join(kp.split())

if kp not in kp_dict:
logger.warning(
f"generate_trapi_ara_tests(): '{kp}' test edges not (yet) available for ARA {source}. Skipping..."
)
continue

for edge_i, kp_edge in enumerate(kp_dict[kp]):

Expand Down
4 changes: 2 additions & 2 deletions tests/onehop/test_triples/ARA/Unit_Test_ARA/Test_ARA.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"url": "https://aragorn.renci.org/1.2",
"infores": "aragorn",
"KPs": [
"Test KP 1",
"Test KP 2"
"test-kp-1",
"test-kp-2"
]
}
2 changes: 1 addition & 1 deletion tests/onehop/test_triples/KP/Unit_Test_KP/Test_KP_1.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"url": "https://automat.renci.org/panther/1.2",
"source_type": "original",
"infores": "panther",
"infores": "test-kp-1",
"exclude_tests": ["RSE"],
"edges": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/onehop/test_triples/KP/Unit_Test_KP/Test_KP_2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"url": "https://automat.renci.org/ontological-hierarchy/1.2",
"source_type": "original",
"infores": "ontological-hierarchy",
"infores": "test-kp-2",
"exclude_tests": ["RPBS"],
"edges": [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/translator/registry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"version": "0.0.1",
"x-translator": {
"component": "KP",
"infores": "infores:panther",
"infores": "infores:test-kp-1",
"team": "Ranking Agent",
"biolink-version": "2.2.16"
},
Expand All @@ -40,7 +40,7 @@
"version": "0.0.1",
"x-translator": {
"component": "KP",
"infores": "infores:ontological-hierarchy",
"infores": "test-kp-2",
"team": "Ranking Agent",
"biolink-version": "2.2.16"
},
Expand Down
13 changes: 9 additions & 4 deletions tests/translator/registry/test_translator_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ def shared_test_extract_component_test_data_metadata_from_registry(
},
"x-trapi": {
"version": "1.2.0",
"test_data_location": "http://some-kp-web-test-data-directory"
"test_data_location": "https://github.com/TranslatorSRI/SRI_testing/blob"
"/main/tests/onehop/test_triples/KP/Unit_Test_KP/Test_KP_1.json"
}
}
}
]
},
"http://some-kp-web-test-data-directory" # test_data_location
"https://raw.githubusercontent.com/TranslatorSRI/SRI_testing"
"/main/tests/onehop/test_triples/KP/Unit_Test_KP/Test_KP_1.json" # KP test_data_location
),
( # Query 1 - Empty "hits" List
{
Expand Down Expand Up @@ -299,13 +301,16 @@ def test_extract_kp_test_data_metadata_from_registry(query: Tuple[Dict, str, str
},
"x-trapi": {
"version": "1.2.0",
"test_data_location": "http://some-ara-web-test-data-directory"
"test_data_location": "https://github.com/TranslatorSRI/SRI_testing/blob" +
"/main/tests/onehop/test_triples/ARA" +
"/Unit_Test_ARA/Test_ARA.json"
}
}
}
]
},
"http://some-ara-web-test-data-directory" # test_data_location
"https://raw.githubusercontent.com/TranslatorSRI/SRI_testing" +
"/main/tests/onehop/test_triples/ARA/Unit_Test_ARA/Test_ARA.json" # ARA test_data_location
)
]
)
Expand Down
Loading

0 comments on commit 3f99e6e

Please sign in to comment.