Example #1
0
 def test_from_json__customized_json_changed(self):
     """ Test Reaction.from_json with a customized reaction and modified json. Ensure propensities don't change. """
     test_json = {
         'name': 'test_reaction',
         'reactants': [{
             'key': 'B',
             'value': 1
         }],
         'products': [{
             'key': 'A',
             'value': 1
         }],
         'marate': None,
         'annotation': None,
         'propensity_function': '(k1*A)',
         'ode_propensity_function': '(k1*A)',
         'massaction': False,
         'type': 'customized'
     }
     reaction = Reaction.from_json(test_json)
     self.assertEqual(reaction.name, 'test_reaction')
     self.assertEqual(reaction.reactants, {'B': 1})
     self.assertEqual(reaction.products, {'A': 1})
     self.assertEqual(reaction.propensity_function, '(k1*A)')
     self.assertEqual(reaction.ode_propensity_function, '(k1*A)')
     self.assertIsNone(reaction.marate)
     self.assertIsNone(reaction.annotation)
     self.assertFalse(reaction.massaction)
     self.assertEqual(reaction.type, 'customized')
Example #2
0
 def test_from_json__massaction_json_changed(self):
     """ Test Reaction.from_json with a mass-action reaction and modified json. Ensure propensities are updated."""
     test_json = {
         'name': 'test_reaction',
         'reactants': [{
             'key': 'B',
             'value': 1
         }],
         'products': [{
             'key': 'A',
             'value': 1
         }],
         'marate': 'k1',
         'annotation': None,
         'propensity_function': '(k1*A)',
         'ode_propensity_function': '(k1*A)',
         'massaction': True,
         'type': 'mass-action'
     }
     reaction = Reaction.from_json(test_json)
     self.assertEqual(reaction.name, 'test_reaction')
     self.assertEqual(reaction.reactants, {'B': 1})
     self.assertEqual(reaction.products, {'A': 1})
     self.assertEqual(reaction.propensity_function, '(k1*B)')
     self.assertEqual(reaction.ode_propensity_function, '(k1*B)')
     self.assertEqual(reaction.marate, 'k1')
     self.assertIsNone(reaction.annotation)
     self.assertTrue(reaction.massaction)
     self.assertEqual(reaction.type, 'mass-action')
Example #3
0
 def test_from_json__invalid_json(self):
     """ Test Reaction.from_json with a reaction that fails validation. """
     test_json = {
         'name': 'test_reaction',
         'reactants': [{
             'key': 'A',
             'value': 1
         }],
         'products': [{
             'key': 'B',
             'value': 1
         }],
         'marate': None,
         'annotation': None,
         'propensity_function': '(k1*A)',
         'ode_propensity_function': '(k1*A)',
         'massaction': True,
         'type': 'mass-action'
     }
     with self.assertRaises(ReactionError):
         reaction = Reaction.from_json(test_json)