-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix up the tests to actually work and be better
- Loading branch information
1 parent
b97144c
commit 6d28e41
Showing
9 changed files
with
262 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,24 +9,22 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v2 | ||
uses: actions/checkout@v4 | ||
|
||
# Cache docker layers for faster build | ||
- uses: satackey/[email protected] | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
- uses: actions/setup-python@v5 | ||
name: Setup python | ||
with: | ||
python-version: '3.11' | ||
cache: 'pip' | ||
|
||
- name: Build | ||
run: docker build -t harness-testing -f Dockerfile.test . | ||
- name: Install requirements | ||
run: pip install -r requirements.txt | ||
|
||
- run: pip install -r requirements-runners.txt | ||
- run: pip install -r requirements-test.txt | ||
|
||
- name: Run tests and get output | ||
run: | | ||
echo 'TEST_OUTPUT<<EOF' >> $GITHUB_ENV | ||
echo "$(docker run harness-testing)" >> $GITHUB_ENV | ||
echo 'EOF' >> $GITHUB_ENV | ||
- name: Exit if there are any test failures | ||
run: '[[ $TEST_OUTPUT != *FAILED* ]]' | ||
run: pytest | ||
|
||
check-format: | ||
name: Check that code matches Black formatter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pytest==7.4.2 | ||
pytest-asyncio==0.23.3 | ||
pytest-httpx==0.30.0 | ||
pytest-mock==3.11.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Logging setup.""" | ||
|
||
import logging | ||
|
||
|
||
class ColoredFormatter(logging.Formatter): | ||
"""Colored formatter.""" | ||
|
||
prefix = "[%(asctime)s: %(levelname)s/%(name)s]:" | ||
default = f"{prefix} %(message)s" | ||
error_fmt = f"\x1b[31m{prefix}\x1b[0m %(message)s" | ||
warning_fmt = f"\x1b[33m{prefix}\x1b[0m %(message)s" | ||
info_fmt = f"\x1b[32m{prefix}\x1b[0m %(message)s" | ||
debug_fmt = f"\x1b[34m{prefix}\x1b[0m %(message)s" | ||
|
||
def __init__(self, fmt=default): | ||
"""Initialize.""" | ||
logging.Formatter.__init__(self, fmt) | ||
|
||
def format(self, record): | ||
"""Format record.""" | ||
format_orig = self._style._fmt | ||
if record.levelno == logging.DEBUG: | ||
self._style._fmt = ColoredFormatter.debug_fmt | ||
elif record.levelno == logging.INFO: | ||
self._style._fmt = ColoredFormatter.info_fmt | ||
elif record.levelno == logging.WARNING: | ||
self._style._fmt = ColoredFormatter.warning_fmt | ||
elif record.levelno == logging.ERROR: | ||
self._style._fmt = ColoredFormatter.error_fmt | ||
result = logging.Formatter.format(self, record) | ||
self._style._fmt = format_orig | ||
return result | ||
|
||
|
||
def setup_logger(): | ||
"""Set up Test Harness logger.""" | ||
logger = logging.getLogger("harness") | ||
logger.setLevel(logging.DEBUG) | ||
handler = logging.StreamHandler() | ||
handler.setLevel(logging.DEBUG) | ||
handler.setFormatter(ColoredFormatter()) | ||
logger.addHandler(handler) | ||
|
||
return logger | ||
|
||
|
||
def assert_no_level(logger, allowed_level, exceptions=0): | ||
""" | ||
Check that the logger has no records greater than | ||
the allowed level. | ||
Also has a parameter to specify the number of exceptions | ||
to the rule (number of records that will be ignored). | ||
""" | ||
total = 0 | ||
for record in logger.records: | ||
if record.levelno >= allowed_level: | ||
total += 1 | ||
if total > exceptions: | ||
raise Exception(f"Invalid Log Record: {record}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""Mock Test Responses.""" | ||
|
||
kp_response = { | ||
"message": { | ||
"query_graph": { | ||
"nodes": { | ||
"n0": {"ids": ["MESH:D008687"]}, | ||
"n1": {"categories": ["biolink:Disease"]}, | ||
}, | ||
"edges": { | ||
"n0n1": { | ||
"subject": "n0", | ||
"object": "n1", | ||
"predicates": ["biolink:treats"], | ||
} | ||
}, | ||
}, | ||
"knowledge_graph": { | ||
"nodes": { | ||
"MESH:D008687": { | ||
"categories": ["biolink:SmallMolecule"], | ||
"name": "Metformin", | ||
"attributes": [], | ||
}, | ||
"MONDO:0005148": { | ||
"categories": [ | ||
"biolink:Disease", | ||
], | ||
"name": "type 2 diabetes mellitus", | ||
"attributes": [], | ||
}, | ||
}, | ||
"edges": { | ||
"n0n1": { | ||
"subject": "MESH:D008687", | ||
"object": "MONDO:0005148", | ||
"predicate": "biolink:treats", | ||
"sources": [ | ||
{ | ||
"resource_id": "infores:kp0", | ||
"resource_role": "primary_knowledge_source", | ||
} | ||
], | ||
"attributes": [], | ||
}, | ||
}, | ||
}, | ||
"results": [ | ||
{ | ||
"node_bindings": { | ||
"n0": [ | ||
{ | ||
"id": "MESH:D008687", | ||
"attributes": [], | ||
}, | ||
], | ||
"n1": [ | ||
{ | ||
"id": "MONDO:0005148", | ||
"attributes": [], | ||
}, | ||
], | ||
}, | ||
"analyses": [ | ||
{ | ||
"resource_id": "kp0", | ||
"edge_bindings": { | ||
"n0n1": [ | ||
{ | ||
"id": "n0n1", | ||
"attributes": [], | ||
}, | ||
], | ||
}, | ||
} | ||
], | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from test_harness.reporter import Reporter | ||
from test_harness.slacker import Slacker | ||
from test_harness.runner.query_runner import QueryRunner | ||
|
||
class MockReporter(Reporter): | ||
def __init__(self, base_url=None, refresh_token=None, logger=None): | ||
super().__init__() | ||
self.base_path = base_url | ||
self.test_run_id = 1 | ||
pass | ||
|
||
async def get_auth(self): | ||
pass | ||
|
||
async def create_test_run(self, test_env, suite_name): | ||
return 1 | ||
|
||
async def create_test(self, test, asset): | ||
return 2 | ||
|
||
async def upload_labels(self, test_id, labels): | ||
pass | ||
|
||
async def upload_logs(self, test_id, logs): | ||
pass | ||
|
||
async def upload_artifact_references(self, test_id, artifact_references): | ||
pass | ||
|
||
async def upload_screenshots(self, test_id, screenshot): | ||
pass | ||
|
||
async def upload_log(self, test_id, message): | ||
pass | ||
|
||
async def finish_test(self, test_id, result): | ||
return result | ||
|
||
async def finish_test_run(self): | ||
pass | ||
|
||
|
||
class MockSlacker(Slacker): | ||
def __init__(self): | ||
pass | ||
|
||
async def post_notification(self, messages=[]): | ||
print(f"posting messages: {messages}") | ||
pass | ||
|
||
async def upload_test_results_file(self, filename, extension, results): | ||
pass | ||
|
||
|
||
class MockQueryRunner(QueryRunner): | ||
async def retrieve_registry(self, trapi_version: str): | ||
self.registry = { | ||
"staging": { | ||
"ars": [ | ||
{ | ||
"_id": "testing", | ||
"title": "Tester", | ||
"infores": "infores:tester", | ||
"url": "http://tester" | ||
} | ||
], | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.