Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()