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())
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())
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)