From d3075473ae4ce955e0c6b15f443deab9f18cccaf Mon Sep 17 00:00:00 2001 From: Richard Bruskiewich Date: Mon, 24 Jun 2024 12:57:19 -0700 Subject: [PATCH] Add mention in the root README, of the new test_case_processor() option for running Translator tests --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 35c2075..4fc827b 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,6 @@ To run TRAPI and Biolink Model validation tests validating query outputs from a ```python from typing import Dict import asyncio -from translator_testing_model.datamodel.pydanticmodel import ComponentEnum from standards_validation_test_runner import run_standards_validation_tests test_data = { @@ -190,6 +189,47 @@ results: Dict = asyncio.run(StandardsValidationTest.run_tests( Note that the trapi_generation variables - defined in the **graph_validation_test.utils.unit_test_templates** module - are all simply Python functions returning TRAPI JSON messages to send to the target components. In principle, if one understands what those functions are doing, you could write your own methods to do other kinds of TRAPI queries whose output can then be validated against the specified TRAPI and Biolink Model releases. +### Running Tests Directly on TRAPI Response output + +The new Translator testing framework has the notion of a "QueryRunner" which prepares and runs TRAPI queries then hands over the TRAPI Response (with the original TestAsset) over to a TestRunner for validation. + +For this use case, yet another script design pattern may be used, somewhat as follows: + +```python +from typing import Dict +from sys import stderr +import json +from standards_validation_test_runner import StandardsValidationTest +from translator_testing_model.datamodel.pydanticmodel import TestAsset +test_data = { + # One test edge (asset) + "subject_id": "DRUGBANK:DB01592", + "subject_category": "biolink:SmallMolecule", + "predicate_id": "biolink:has_side_effect", + "object_id": "MONDO:0011426", + "object_category": "biolink:Disease", + "components": ["molepro"], + "environment": "test", + "trapi_version": "1.5.0-beta", + "biolink_version": "4.1.6", + "runner_settings": "Inferred" +} + +with (open("TRAPI-Response-filename", mode="r") as trapi_json_file): + test_asset: TestAsset = TestAsset(**test_data) + trapi_response: Dict = json.load(trapi_json_file) + svt = StandardsValidationTest( + test_asset=test_asset, + environment=test_data["environment"], + component=test_data["components"][0] + ) + results: Dict = svt.test_case_processor(trapi_response=trapi_response) + assert results + json.dump(results, stderr, indent=4) +``` + +Note that even through the TRAPI query is not run inside the TestRunner, that the source component ("infores" CURIE reference identifier (e.g. 'molepro')) plus target environment (e.g. 'test') need to be given to the system as strings in the StandardsValidationTest() constructor, for use in properly indexing the 'results' dictionary. + ### Sample Output This is a sample of what the JSON output from test runs currently looks like (this sample came from a OneHopTest run).