diff --git a/mira/modeling/askenet/ops.py b/mira/modeling/askenet/ops.py index 1c15fae2e..2a9f40fe4 100644 --- a/mira/modeling/askenet/ops.py +++ b/mira/modeling/askenet/ops.py @@ -164,6 +164,11 @@ def remove_state(tm, state_id): return tm +@amr_to_mira +def add_state(tm, state_id, grounding: None, units: None): + pass + + # Remove transition @amr_to_mira def remove_transition(tm, transition_id): diff --git a/pyproject.toml b/pyproject.toml index 09aa4efdb..2223bed9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,4 +16,5 @@ reverse_relative = true [tool.pytest.ini_options] markers = [ "slow: marks tests as slow for pytest (deselect with '-m \"not slow\"')" + "sbmlmath: marks tests that should not be tested due to them using sbmlmath" ] diff --git a/tests/test_modeling/test_askenet_ops.py b/tests/test_modeling/test_askenet_ops.py index 67625b1b0..c5ffc5aa1 100644 --- a/tests/test_modeling/test_askenet_ops.py +++ b/tests/test_modeling/test_askenet_ops.py @@ -17,8 +17,8 @@ def setUpClass(cls): 'https://raw.githubusercontent.com/DARPA-ASKEM/' 'Model-Representations/main/petrinet/examples/sir.json').json() - '''These unit tests are conducted by zipping through lists of each key in a amr file - (e.g. parameters, observables, etc). Zipping in this manner assumes that the order (assuming insertion order) + '''These unit tests are conducted by zipping through lists of each key in a amr file + (e.g. parameters, observables, etc). Zipping in this manner assumes that the order (assuming insertion order) is preserved before and after mira operation for an amr key ''' @@ -117,6 +117,7 @@ def test_replace_state_id(self): self.assertEqual(old_observable['id'], new_observable['id']) def test_replace_transition_id(self): + old_id = 'inf' new_id = 'new_inf' amr = _d(self.sir_amr) @@ -296,7 +297,7 @@ def test_remove_state(self): self.assertNotEquals(removed_state_id, new_initial['target']) # parameters that are associated in an expression with a removed state are not present in output amr - # (e.g.) if there exists an expression: 'S*I*beta' and we remove S, then beta is no longer present in output + # (e.g.) if there exists an expression: "S*I*beta" and we remove S, then beta is no longer present in output # list of parameters for new_parameter in new_semantics_ode_parameters: self.assertNotIn(removed_state_id, new_parameter['id']) @@ -319,8 +320,8 @@ def test_remove_transition(self): @pytest.mark.sbmlmath def test_add_transition(self): - infected = Concept(name="infected_population", identifiers={"ido": "0000511"}) - recovered = Concept(name="immune_population", identifiers={"ido": "0000592"}) + test_subject = Concept(name="test_subject", identifiers={"ido": "0000511"}) + test_outcome = Concept(name="test_outcome", identifiers={"ido": "0000592"}) expression_xml = "Edelta" new_transition_id = 'test' old_natural_conversion_amr = _d(self.sir_amr) @@ -329,10 +330,12 @@ def test_add_transition(self): # NaturalConversion new_natural_conversion_amr = add_transition(old_natural_conversion_amr, new_transition_id, expression_xml, - src_id=infected, - tgt_id=recovered) + src_id=test_subject, + tgt_id=test_outcome) natural_conversion_transition_dict = {} natural_conversion_rates_dict = {} + natural_conversion_state_dict = {} + for transition in new_natural_conversion_amr['model']['transitions']: name = transition.pop('id') natural_conversion_transition_dict[name] = transition @@ -341,17 +344,25 @@ def test_add_transition(self): name = rate.pop('target') natural_conversion_rates_dict[name] = rate + for state in new_natural_conversion_amr['model']['states']: + name = state.pop('id') + natural_conversion_state_dict[name] = state + self.assertIn(new_transition_id, natural_conversion_transition_dict) self.assertIn(new_transition_id, natural_conversion_rates_dict) self.assertEqual(expression_xml, natural_conversion_rates_dict[new_transition_id]['expression_mathml']) self.assertEqual(sstr(mathml_to_expression(expression_xml)), natural_conversion_rates_dict[new_transition_id]['expression']) + self.assertIn(test_subject.name, natural_conversion_state_dict) + self.assertIn(test_outcome.name, natural_conversion_state_dict) # NaturalProduction new_natural_production_amr = add_transition(old_natural_production_amr, new_transition_id, expression_xml, - tgt_id=recovered) + tgt_id=test_outcome) natural_production_transition_dict = {} natural_production_rates_dict = {} + natural_production_state_dict = {} + for transition in new_natural_production_amr['model']['transitions']: name = transition.pop('id') natural_production_transition_dict[name] = transition @@ -360,17 +371,24 @@ def test_add_transition(self): name = rate.pop('target') natural_production_rates_dict[name] = rate + for state in new_natural_production_amr['model']['states']: + name = state.pop('id') + natural_production_state_dict[name] = state + self.assertIn(new_transition_id, natural_production_transition_dict) self.assertIn(new_transition_id, natural_production_rates_dict) self.assertEqual(expression_xml, natural_production_rates_dict[new_transition_id]['expression_mathml']) self.assertEqual(sstr(mathml_to_expression(expression_xml)), natural_production_rates_dict[new_transition_id]['expression']) + self.assertIn(test_outcome.name, natural_production_state_dict) # NaturalDegradation new_natural_degradation_amr = add_transition(old_natural_degradation_amr, new_transition_id, expression_xml, - src_id=infected) + src_id=test_subject) natural_degradation_transition_dict = {} natural_degradation_rates_dict = {} + natural_degradation_states_dict = {} + for transition in new_natural_degradation_amr['model']['transitions']: name = transition.pop('id') natural_degradation_transition_dict[name] = transition @@ -379,11 +397,16 @@ def test_add_transition(self): name = rate.pop('target') natural_degradation_rates_dict[name] = rate + for state in new_natural_degradation_amr['model']['states']: + name = state.pop('id') + natural_degradation_states_dict[name] = state + self.assertIn(new_transition_id, natural_degradation_transition_dict) self.assertIn(new_transition_id, natural_degradation_rates_dict) self.assertEqual(expression_xml, natural_degradation_rates_dict[new_transition_id]['expression_mathml']) self.assertEqual(sstr(mathml_to_expression(expression_xml)), natural_degradation_rates_dict[new_transition_id]['expression']) + self.assertIn(test_subject.name, natural_degradation_states_dict) @pytest.mark.sbmlmath def test_replace_rate_law_sympy(self): diff --git a/tox.ini b/tox.ini index 0eb59af35..a54f545da 100644 --- a/tox.ini +++ b/tox.ini @@ -10,15 +10,16 @@ envlist = py [testenv] -passenv = PYTHONPATH MIRA_REST_URL +passenv = PYTHONPATH, MIRA_REST_URL extras = tests web +deps = + pydantic<2.0 commands = coverage run -p -m pytest --durations=20 {posargs:tests} -m "not slow and not sbmlmath" ; coverage combine ; coverage xml - [testenv:docs] extras = docs