Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: SBML test suite: show tag summary for passed tests #1420

Merged
merged 9 commits into from
Feb 18, 2021
Merged
44 changes: 43 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
"""Pytest configuration for SBML test suite"""

from typing import List
import re
import sys
from typing import List

import pytest


# stores passed SBML semantic test suite IDs
passed_ids = []


def parse_selection(selection_str: str) -> List[int]:
Expand Down Expand Up @@ -50,3 +56,39 @@ def pytest_generate_tests(metafunc):
test_numbers -= {1395}

metafunc.parametrize("test_number", test_numbers)


def pytest_sessionfinish(session, exitstatus):
"""Process test results"""
global passed_ids
terminalreporter = session.config.pluginmanager.get_plugin(
'terminalreporter')
terminalreporter.ensure_newline()
# parse test names to get passed case IDs (don't know any better way to
# access fixture values)
from testSBMLSuite import format_test_id
passed_ids = [format_test_id(_) for _ in passed_ids]
if passed_ids:
write_passed_tags(passed_ids, terminalreporter)
terminalreporter.ensure_newline()


def write_passed_tags(passed_ids, out=sys.stdout):
"""Write tags of passed SBML semantic test cases"""
passed_tags = set()
from testSBMLSuite import get_tags_for_test
for test_id in passed_ids:
passed_tags |= get_tags_for_test(test_id)

out.write("At least one test with the following tags has passed:\n")
out.write(' ' + '\n '.join(passed_tags))


def pytest_runtest_logreport(report: "TestReport") -> None:
"""Collect test case IDs of passed SBML semantic test suite cases"""
if report.when == 'call'\
and report.outcome == 'passed'\
and '::test_sbml_testsuite_case[' in report.nodeid:
test_case_id = re.sub(r'^.*::test_sbml_testsuite_case\[(\d+)].*$',
r'\1', report.nodeid)
passed_ids.append(test_case_id)
16 changes: 16 additions & 0 deletions tests/testSBMLSuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import copy
import importlib
import os
import re
import shutil
import sys

Expand Down Expand Up @@ -303,3 +304,18 @@ def format_test_id(test_id) -> str:
test_str = str(test_id)
test_str = '0'*(5-len(test_str)) + test_str
return test_str


def get_tags_for_test(test_id):
"""Get sbml test suite tags for the given test ID"""

current_test_path = os.path.join(TEST_PATH, test_id)
info_file = os.path.join(current_test_path, f'{test_id}-model.m')
with open(info_file) as f:
for line in f:
if line.startswith('testTags:'):
res = set(re.split(r'[ ,:]', line[len('testTags:'):].strip()))
res.discard('')
return res
print(f"No testTags found for test case {test_id}.")
return set()