def test_compile_crn(self): from biocrnpyler import ChemicalReactionNetwork from biocrnpyler import Species from biocrnpyler import Reaction from biocrnpyler import Mixture a = Species(name='a') b = Species(name='b') species_list = [a, b] def mock_update_reactions(): rxn = Reaction(inputs=[a], outputs=[b], k=0.1) return [rxn] rxn = Reaction(inputs=[a], outputs=[b], k=0.1) CRN = ChemicalReactionNetwork(species_list, [rxn]) mixture = Mixture(species=species_list) mixture.update_reactions = mock_update_reactions crn_from_mixture = mixture.compile_crn() self.assertEqual(CRN.species, crn_from_mixture.species) self.assertEqual(CRN.reactions, crn_from_mixture.reactions)
def test_update_reactions(self): mixture = Mixture() with self.assertRaisesRegexp(AttributeError, 'Mixture.crn_species not defined.'): mixture.update_reactions() component = Component(name='test_component') # creating a mock update function to decouple the update process from the rest of the code def mock_update_reactions(): rxn = Reaction(inputs=[], outputs=[], k=0.1) return [rxn] component.update_reactions = mock_update_reactions mixture.add_components(component) mixture.update_species() crn_rxn = mixture.update_reactions() crn_rxn_mock = mock_update_reactions() self.assertEqual(crn_rxn, crn_rxn_mock)
def test_update_reactions(self): from biocrnpyler import Mixture from biocrnpyler import Reaction from biocrnpyler import Component mixture = Mixture() with self.assertRaises(AttributeError): mixture.update_reactions() component = Component(name='test_component') def mock_update_reactions(): rxn = Reaction(inputs=[], outputs=[], k=0.1) return [rxn] component.update_reactions = mock_update_reactions mixture.add_components(component) mixture.update_species() crn_rxn = mixture.update_reactions() crn_rxn_mock = mock_update_reactions() self.assertEqual(crn_rxn, crn_rxn_mock)
def test_compile_crn(self): a = Species(name='a') b = Species(name='b') species_list = [a, b] # creating a mock update function to decouple the update process from the rest of the code def mock_update_reactions(): rxn = Reaction(inputs=[a], outputs=[b], k=0.1) return [rxn] rxn = Reaction(inputs=[a], outputs=[b], k=0.1) CRN = ChemicalReactionNetwork(species_list, [rxn]) mixture = Mixture(species=species_list) mixture.update_reactions = mock_update_reactions crn_from_mixture = mixture.compile_crn() # test that the mixture has the same species as the manually build CRN object self.assertEqual(CRN.species, crn_from_mixture.species) # test that the mixture has the same reactions as the manually build CRN object self.assertEqual(CRN.reactions, crn_from_mixture.reactions)