def test_forced_setting_with_binding_descriptor(self): instance = mocks.ClassWithDescriptor(ForcedSet(Binding( mocks.Descriptor()))) Setter.forced(instance, attrname, 0, binding=True) self.assertEqual(getattr(instance, attrname), 0)
class ForcedSet_Test(TestCase): def setUp(self): self.decor = ForcedSet(mocks.Descriptor()) self.instance = mocks.ClassWithDescriptor(self.decor) self.Class = type(self.instance) def test_normal_set_fails(self): with self.assertRaises(AttributeError): self.instance.attr = 5 def test_forced_call_works(self): self.decor.__set__(self.instance, 5, force=True) self.assertEqual(self.instance.attr, 5) def test_other_call_version(self): self.Class.attr.__set__(self.instance, 5, force=True) self.assertEqual(self.instance.attr, 5)
def setUp(self): self.decor = ForcedSet(mocks.Descriptor()) self.instance = mocks.ClassWithDescriptor(self.decor) self.Class = type(self.instance)