Skip to content

Commit

Permalink
implementing ignoring parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed May 3, 2021
1 parent 54ee77b commit 658d032
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions biosimulators_cbmpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def exec_sed_task(task, variables, log=None):
except NotImplementedError as exception:
if (
ALGORITHM_SUBSTITUTION_POLICY_LEVELS[alg_substitution_policy]
> ALGORITHM_SUBSTITUTION_POLICY_LEVELS[AlgorithmSubstitutionPolicy.SAME_METHOD]
> ALGORITHM_SUBSTITUTION_POLICY_LEVELS[AlgorithmSubstitutionPolicy.NONE]
):
warn('Unsuported algorithm parameter `{}` was ignored:\n {}'.format(
change.kisao_id, str(exception).replace('\n', '\n ')),
Expand All @@ -151,7 +151,7 @@ def exec_sed_task(task, variables, log=None):
except ValueError as exception:
if (
ALGORITHM_SUBSTITUTION_POLICY_LEVELS[alg_substitution_policy]
> ALGORITHM_SUBSTITUTION_POLICY_LEVELS[AlgorithmSubstitutionPolicy.SAME_METHOD]
> ALGORITHM_SUBSTITUTION_POLICY_LEVELS[AlgorithmSubstitutionPolicy.NONE]
):
warn('Unsuported value `{}` for algorithm parameter `{}` was ignored:\n {}'.format(
change.new_value, change.kisao_id, str(exception).replace('\n', '\n ')),
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_exec_sed_task_successfully(self):

task2 = copy.deepcopy(task)
task2.simulation.algorithm.changes[0].new_value = 'not supported'
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'SAME_METHOD'}):
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'NONE'}):
with self.assertRaisesRegex(NotImplementedError, 'not a supported solver'):
core.exec_sed_task(task2, variables)

Expand Down Expand Up @@ -178,15 +178,15 @@ def test_exec_sed_task_successfully(self):
numpy.testing.assert_allclose(result, numpy.array(expected_results[var_id]), rtol=1e-4, atol=1e-8)

task.simulation.algorithm.changes.append(sedml_data_model.AlgorithmParameterChange(kisao_id='KISAO_0000531', new_value=2))
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'SAME_METHOD'}):
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'NONE'}):
with self.assertRaisesRegex(ValueError, 'greater than or equal'):
core.exec_sed_task(task, variables)
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'SIMILAR_VARIABLES'}):
with self.assertWarnsRegex(BioSimulatorsWarning, 'greater than or equal'):
core.exec_sed_task(task, variables)

task.simulation.algorithm.changes[-1].kisao_id = 'KISAO_9999999'
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'SAME_METHOD'}):
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'NONE'}):
with self.assertRaisesRegex(NotImplementedError, 'is not a parameter of'):
core.exec_sed_task(task, variables)
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'SIMILAR_VARIABLES'}):
Expand All @@ -212,7 +212,7 @@ def test_exec_sed_task_successfully(self):
task.simulation.algorithm.kisao_id = 'KISAO_0000554'
task.simulation.algorithm.changes[0].new_value = 'GLPK'

with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'SAME_METHOD'}):
with mock.patch.dict('os.environ', {'ALGORITHM_SUBSTITUTION_POLICY': 'NONE'}):
with self.assertRaisesRegex(NotImplementedError, 'not a supported solver for'):
core.exec_sed_task(task, variables)

Expand Down

0 comments on commit 658d032

Please sign in to comment.