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_add_global_mechanism(self):
        mixture = Mixture()
        GM = GlobalMechanism(name = "gm", mechanism_type = "global")

        mixture.add_global_mechanism(GM)
        #Global Mechanisms should be copied!
        self.assertTrue(mixture.global_mechanisms["global"] != GM)
        self.assertTrue(mixture.global_mechanisms["global"].name == GM.name)

        #test setter to clear
        mixture.global_mechanisms = {}
        self.assertTrue("global" not in mixture.global_mechanisms)
        #test add via add_mechanisms with different key
        mixture.add_mechanisms({"key2":GM})
        self.assertTrue("global" not in mixture.global_mechanisms)
        self.assertTrue("key2" in mixture.global_mechanisms)