From b70bd8465c97aca2e76b4b89094cdd74db3a6865 Mon Sep 17 00:00:00 2001 From: Jonathan Karr Date: Mon, 28 Dec 2020 18:05:44 -0500 Subject: [PATCH 1/2] improving summary messages --- biosimulators_test_suite/exec_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biosimulators_test_suite/exec_core.py b/biosimulators_test_suite/exec_core.py index 145105e..48813d7 100644 --- a/biosimulators_test_suite/exec_core.py +++ b/biosimulators_test_suite/exec_core.py @@ -184,7 +184,7 @@ def run(self): print(termcolor.colored(result.type.value, TERMINAL_COLORS[result.type.value]), end='') print(' (', end='') if result.warnings: - print(termcolor.colored(str(len(result.warnings)) + ', ', TERMINAL_COLORS['warned']), end='') + print(termcolor.colored(str(len(result.warnings)) + ' warnings, ', TERMINAL_COLORS['warned']), end='') print('{:.1f} s'.format(result.duration), end='') print(').') From dcf53b0fd392d5b5276b4cee078ca872347e3268 Mon Sep 17 00:00:00 2001 From: Jonathan Karr Date: Mon, 28 Dec 2020 18:39:25 -0500 Subject: [PATCH 2/2] fixing test case --- biosimulators_test_suite/_version.py | 2 +- .../test_case/published_project.py | 23 +++++++++++++++---- ...-BMC-Syst-Biol-2017-iron-distribution.json | 2 +- tests/test_case/test_published_project.py | 12 ++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/biosimulators_test_suite/_version.py b/biosimulators_test_suite/_version.py index 7525d19..66a87bb 100644 --- a/biosimulators_test_suite/_version.py +++ b/biosimulators_test_suite/_version.py @@ -1 +1 @@ -__version__ = '0.1.4' +__version__ = '0.1.5' diff --git a/biosimulators_test_suite/test_case/published_project.py b/biosimulators_test_suite/test_case/published_project.py index ef0b793..f93c6eb 100644 --- a/biosimulators_test_suite/test_case/published_project.py +++ b/biosimulators_test_suite/test_case/published_project.py @@ -165,6 +165,7 @@ def from_dict(self, data): id = exp_report_def['id'] data_set_labels = set(exp_report_def.get('dataSets', [])) + points = tuple(exp_report_def['points']) values = {} for key, val in exp_report_def.get('values', {}).items(): @@ -173,7 +174,20 @@ def from_dict(self, data): else: values[key] = {} for k, v in val.items(): - values[key][tuple(int(index) for index in k.split(","))] = v + multi_index = tuple(int(index) for index in k.split(",")) + try: + numpy.ravel_multi_index([multi_index], points)[0] + except ValueError: + raise ValueError(( + "Key '{}' of the expected values of report '{}' of published project test case '{}' is invalid. " + "Key must be less than or equal to '{}'." + ).format( + multi_index, + self.id, + self.id.replace('published_project.PublishedProjectTestCase:', ''), + tuple(p - 1 for p in points), + )) + values[key][multi_index] = v invalid_dataset_ids = set(values.keys()).difference(set(data_set_labels)) if invalid_dataset_ids: @@ -187,7 +201,7 @@ def from_dict(self, data): self.expected_reports.append(ExpectedSedReport( id=id, data_sets=data_set_labels, - points=tuple(exp_report_def['points']), + points=points, values=values, )) @@ -305,16 +319,17 @@ def eval(self, specifications): value = report.loc[data_set_label, :] for el_id, expected_el_value in expected_value.items(): el_index = numpy.ravel_multi_index([el_id], value.shape)[0] + actual_el_value = value[el_index] try: numpy.testing.assert_allclose( - value[el_index], + actual_el_value, expected_el_value, rtol=self.r_tol, atol=self.a_tol, ) except AssertionError: errors.append('Data set {} of report {} does not have expected value at {}: {} != {}'.format( - data_set_label, expected_report.id, el_id, value[el_index], expected_el_value)) + data_set_label, expected_report.id, el_id, actual_el_value, expected_el_value)) else: try: numpy.testing.assert_allclose( diff --git a/examples/sbml-core/Parmar-BMC-Syst-Biol-2017-iron-distribution.json b/examples/sbml-core/Parmar-BMC-Syst-Biol-2017-iron-distribution.json index 5531a7d..77dc994 100644 --- a/examples/sbml-core/Parmar-BMC-Syst-Biol-2017-iron-distribution.json +++ b/examples/sbml-core/Parmar-BMC-Syst-Biol-2017-iron-distribution.json @@ -12,7 +12,7 @@ "values": { "time": { "0": 0.0, - "301": 5100.0 + "300": 5100.0 } } }], diff --git a/tests/test_case/test_published_project.py b/tests/test_case/test_published_project.py index 48d7035..5d9df9a 100644 --- a/tests/test_case/test_published_project.py +++ b/tests/test_case/test_published_project.py @@ -74,11 +74,19 @@ def test_CuratedCombineArchiveTestCase_from_dict_error_handling(self): filename = os.path.join('sbml-core', 'Caravagna-J-Theor-Biol-2010-tumor-suppressive-oscillations.json') with open(os.path.join(base_path, filename), 'r') as file: data = json.load(file) - data['expectedReports'][0]['values']['t'] = [0, 1, 2, 3, 4, 5] + id = 'published_project.PublishedProjectTestCase:sbml-core/Caravagna-J-Theor-Biol-2010-tumor-suppressive-oscillations.json' + + data['expectedReports'][0]['values'] = {'t': [0, 1, 2, 3, 4, 5]} with self.assertRaisesRegex(ValueError, "keys were not in the 'dataSets' property"): - id = 'published_project.PublishedProjectTestCase:sbml-core/Caravagna-J-Theor-Biol-2010-tumor-suppressive-oscillations.json' PublishedProjectTestCase(id=id).from_dict(data) + data['expectedReports'][0]['values'] = {'T': {'5001': 1000.2}} + with self.assertRaisesRegex(ValueError, "Key must be less than or equal to"): + PublishedProjectTestCase(id=id).from_dict(data) + + data['expectedReports'][0]['values'] = {'T': {'5000': 1000.}} + PublishedProjectTestCase(id=id).from_dict(data) + def test_CuratedCombineArchiveTestCase_from_json(self): base_path = os.path.join(os.path.dirname(__file__), '..', '..', 'examples') filename = os.path.join('sbml-core', 'Caravagna-J-Theor-Biol-2010-tumor-suppressive-oscillations.json')