def test_FakeClassRegisteredByClass(self):
     callback = FakeCreatedCallbackTester(self)
     fakeable.add_created_callback(callback)
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass)
     MyCoolClass()
     invocation = callback.assert_invoked_exactly_once()
     self.assertEqual(invocation.name, "MyCoolClass")
     self.assertIsInstance(invocation.obj, MyUnfakeableClass)
     self.assertIs(invocation.obj_type, MyCoolClass)
 def test_FakeClassRegisteredByClass_2InstancesCreated(self):
     callback = FakeCreatedCallbackTester(self)
     fakeable.add_created_callback(callback)
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass)
     MyCoolClass()
     MyCoolClass()
     invocations = callback.assert_invocation_count(2)
     self.assertEqual(invocations[0].name, "MyCoolClass")
     self.assertIsInstance(invocations[0].obj, MyUnfakeableClass)
     self.assertIs(invocations[0].obj_type, MyCoolClass)
     self.assertEqual(invocations[1].name, "MyCoolClass")
     self.assertIsInstance(invocations[1].obj, MyUnfakeableClass)
     self.assertIs(invocations[1].obj_type, MyCoolClass)
 def test_FakeClassRegisteredTwiceByClass(self):
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass1)
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass2)
     x = MyCoolClass()
     self.assertIsInstance(x, MyUnfakeableClass2)
 def test_ClassRegisteredByNameAndClass_NameRegisteredAfter(self):
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass1)
     fakeable.set_fake_class("MyCoolClass", MyUnfakeableClass2)
     x = MyCoolClass()
     self.assertIsInstance(x, MyUnfakeableClass1)
 def test_2FakeClassesRegisteredByClass_OtherClassRegisteredBefore(self):
     fakeable.set_fake_class(MyCoolClassCustomFakeName, MyUnfakeableClass1)
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass2)
     x = MyCoolClass()
     self.assertIsInstance(x, MyUnfakeableClass2)
 def test_FakeClassRegisteredByClass_KeywordArgs(self):
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass)
     x = MyCoolClass(arg1=1, arg2=2)
     self.assertIsInstance(x, MyUnfakeableClass)
     self.assertEqual(x.arg1, 1)
     self.assertEqual(x.arg2, 2)
 def test_FakeClassRegisteredByClass_PositionalArgs(self):
     fakeable.set_fake_class(MyCoolClass, MyUnfakeableClass)
     x = MyCoolClass(1, 2)
     self.assertIsInstance(x, MyUnfakeableClass)
     self.assertEqual(x.arg1, 1)
     self.assertEqual(x.arg2, 2)
 def test_FakeClassRegisteredByName(self):
     fakeable.set_fake_class("MyCoolClass", MyUnfakeableClass)
     x = MyCoolClass()
     self.assertIsInstance(x, MyUnfakeableClass)
Beispiel #9
0
 def setUp(self):
     super().setUp()
     fakeable.set_fake_class(TargetRegistry, FakeTargetRegistry)