def test_instantiating_invalid_forward(self): X = Alternative("X", A={'x': lambda: this_does_not_Exist}) with self.assertRaises(TypeError): X.A() this_does_not_exist = int #fixing it doesn't help with self.assertRaises(TypeError): X.A() #but a new type is OK. X = Alternative("X", A={'x': lambda: this_does_not_exist}) X.A()
def test_extracted_alternatives_have_correct_type(self): Alt = Alternative( "Alt", A={}, B={} ) tOfAlt = TupleOf(Alt) a = Alt.A() aTup = tOfAlt((a,)) self.assertEqual(a, aTup[0]) self.assertTrue(type(a) is type(aTup[0]))
def test_empty_alternatives(self): a = Alternative( "Alt", A={}, B={} ) self.assertEqual(a.A(), a.A()) self.assertIsInstance(deserialize(a, serialize(a, a.A())), a.A) self.assertEqual(a.A(), deserialize(a, serialize(a, a.A()))) self.assertEqual(a.B(), a.B()) self.assertNotEqual(a.A(), a.B()) self.assertNotEqual(a.B(), a.A())