Exemplo n.º 1
0
    def test_add_mechanisms(self):

        mixture = Mixture()

        tx = SimpleTranscription()
        tl = SimpleTranslation()

        test_mech = {tx.mechanism_type: tx, tl.mechanism_type: tl}

        # test that mixture has no mechanism
        self.assertTrue(isinstance(mixture.mechanisms, dict) and len(mixture.mechanisms) == 0)

        #test mechanism setter
        mixture.mechanisms = test_mech
        self.assertEqual(mixture.mechanisms.keys(), test_mech.keys())

        #test mechanisms are copied
        self.assertEqual(type(mixture.mechanisms[tx.mechanism_type]),  type(test_mech[tx.mechanism_type]))
        self.assertFalse(mixture.mechanisms[tx.mechanism_type] == test_mech[tx.mechanism_type])

        #remove all mechanisms
        mixture.mechanisms = {}
        self.assertEqual(mixture.mechanisms, {})

        #test add_mechanism
        mixture.add_mechanism(tx, tx.mechanism_type)
        mixture.add_mechanism(tl)
        self.assertEqual(mixture.mechanisms.keys(), test_mech.keys())

        #test add_mechanisms with list
        mixture.mechanisms = {}
        test_mech_list = list(test_mech.values())
        mixture.add_mechanisms(test_mech_list)
        self.assertEqual(mixture.mechanisms.keys(), test_mech.keys())
Exemplo n.º 2
0
    def test_update_mechanisms(self):

        tx = SimpleTranscription()
        tl = SimpleTranslation()

        test_mech = {tx.mechanism_type: tx, tl.mechanism_type: tl}

        # test that component has no mechanism
        self.assertTrue(isinstance(self.component.mechanisms, dict) and len(self.component.mechanisms) == 0)

        #test mechanism setter
        self.component.mechanisms = test_mech
        self.assertEqual(self.component.mechanisms.keys(), test_mech.keys())

        #test mechanisms are copied
        self.assertEqual(type(self.component.mechanisms[tx.mechanism_type]),  type(test_mech[tx.mechanism_type]))
        self.assertFalse(self.component.mechanisms[tx.mechanism_type] == test_mech[tx.mechanism_type])

        #remove all mechanisms
        self.component.mechanisms = {}
        self.assertEqual(self.component.mechanisms, {})

        #test add_mechanism
        self.component.add_mechanism(tx, tx.mechanism_type)
        self.component.add_mechanism(tl)
        self.assertEqual(self.component.mechanisms.keys(), test_mech.keys())

        #test add_mechanisms with list
        self.component.mechanisms = {}
        test_mech_list = list(test_mech.values())
        self.component.add_mechanisms(test_mech_list)
        self.assertEqual(self.component.mechanisms.keys(), test_mech.keys())
Exemplo n.º 3
0
    def test_get_parameter(self):

        # testing an invalid parameter
        with self.assertRaisesRegex(ValueError, 'No parameters can be found that match the'):
            self.component.get_parameter(param_name='kb')

        # Create Param Dict
        kb, ku, ktx, ktl, kdeg, cooperativity = 100, 10, 3, 2, 1, 4
        p_id = 'p10'

        parameters = {"kb": kb, "kdeg":kdeg,
                      ("transcription", None, "ktx"): ktx,
                      ("transcription", p_id, 'ku'): ku,
                      (None, p_id, "ktl"): ktl }
        # update the component parameters
        self.component.update_parameters(parameters=parameters)

        tx = SimpleTranscription()
        # testing the different parameter definitions
        self.assertEqual(self.component.get_parameter(param_name='kb').value, kb)
        self.assertEqual(self.component.get_parameter(mechanism=tx, param_name='ktx').value, ktx)
        self.assertEqual(self.component.get_parameter(part_id=p_id, param_name='ktl').value, ktl)
        self.assertEqual(self.component.get_parameter(mechanism=tx, part_id=p_id, param_name='ku').value, ku)

        # testing parameter with return_numerical = True
        self.assertEqual(self.component.get_parameter(param_name='kb', return_numerical = True), kb)

        one_param = {"kb": kb}
        self.component.update_parameters(parameters=one_param)
        # testing that one_param was registered
        self.assertEqual(self.component.get_parameter(param_name="kb").value, one_param["kb"])

        #testing a parameter which can't be found
        with self.assertRaisesRegex(ValueError, "No parameters can be found"):
            self.component.get_parameter("not a parameter")
Exemplo n.º 4
0
    def test_add_mechanism(self):
        tx = SimpleTranscription()
        tl = SimpleTranslation()

        #test adding a single mechanism instead of a list still works
        self.component.add_mechanisms(tx)
        self.assertTrue(tx.mechanism_type in self.component.mechanisms)

        #add a non-mechanism
        with self.assertRaisesRegex(TypeError,
                                    'mechanism must be a Mechanism.'):
            self.component.add_mechanism(None)

        with self.assertRaisesRegex(
                ValueError, 'add_mechanisms expected a list of Mechanisms.'):
            self.component.add_mechanisms(None)

        #add same mechanism, new type
        self.component.add_mechanism(tx, mech_type="new")
        self.assertTrue("new" in self.component.mechanisms)
        self.assertTrue(
            type(self.component.mechanisms["new"]) == SimpleTranscription)

        #Add invalid mech_type
        with self.assertRaisesRegex(TypeError,
                                    'mechanism keys must be strings.'):
            self.component.add_mechanism(tx, mech_type=1234)

        #add a mechanism already in the Component
        with self.assertRaisesRegex(
                ValueError,
                f"mech_type {tx.mechanism_type} already in component"):
            self.component.add_mechanism(tx)

        #add mechanism with optional_mechanism - does not overwrite!
        self.component.add_mechanism(tl,
                                     mech_type=tx.mechanism_type,
                                     optional_mechanism=True)
        self.assertTrue(tx.mechanism_type in self.component.mechanisms)
        self.assertTrue(
            type(self.component.mechanisms[tx.mechanism_type]) ==
            SimpleTranscription)

        #add mechanism with overwrite
        self.component.add_mechanism(tl,
                                     mech_type=tx.mechanism_type,
                                     overwrite=True)
        self.assertTrue(tx.mechanism_type in self.component.mechanisms)
        self.assertTrue(
            type(self.component.mechanisms[tx.mechanism_type]) ==
            SimpleTranslation)