def test_descriptor__get___set___in_proxy_subclass(self): class Descriptor(object): value = None instance = None cls = None def __get__(self, instance, cls): self.cls = cls return self.value def __set__(self, instance, value): self.value = value self.instance = instance descriptor = Descriptor() descriptor.value = "descriptor value" class Proxy(self._getTargetClass()): attr = descriptor proxy = Proxy(object()) self.assertEqual(proxy.attr, "descriptor value") self.assertEqual(descriptor.cls, Proxy) proxy.attr = 42 self.assertEqual(descriptor.value, 42) self.assertEqual(descriptor.instance, proxy)
def test_descriptor__set___only_in_proxy_subclass(self): class Descriptor(object): value = None instance = None def __set__(self, instance, value): self.value = value self.instance = instance descriptor = Descriptor() class Proxy(self._getTargetClass()): attr = descriptor proxy = Proxy(object()) proxy.attr = 42 self.assertEqual(proxy.attr, descriptor) self.assertEqual(descriptor.value, 42) self.assertEqual(descriptor.instance, proxy)