def test_self_lifting(self):
        wrapped = mocks.Descriptor()
        wrapper = DescriptorDecoratorBase(None)

        result = _lifted_desc_results(wrapped, wrapper, None, object)

        self.assertIs(result, wrapper)
    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)
    def test_with_binding_descriptor(self):
        instance = mocks.ClassWithDescriptor(Binding(mocks.Descriptor()))
        cls = type(instance)

        result = get_descriptor_from(instance, attrname)

        self.assertIs(result, cls.__dict__[attrname])
    def test_other(self):
        wrapped = mocks.Descriptor()
        instance = mocks.ClassWithDescriptor(wrapped)
        instance.attr = 5
        wrapper = DescriptorDecoratorBase(wrapped)

        result = _lifted_desc_results(wrapped, wrapper, instance, type(instance))

        self.assertEqual(result, 5)
 def setUp(self):
     self.decor = SetOnce(mocks.Descriptor())
     self.instance = mocks.ClassWithDescriptor(self.decor)
     self.Class = type(self.instance)
    def setUp(self):
        self.decor = Binding(mocks.Descriptor())
        self.instance = mocks.ClassWithDescriptor(self.decor)
        self.Class = type(self.instance)

        self.instance.attr = 5
 def setUp(self):
     self.decor = DescriptorDecoratorBase(Binding(mocks.Descriptor()))
     self.Class = type(mocks.ClassWithDescriptor(self.decor))
     self.instance = self.Class()
     self.instance.attr = 5
    def test_secret_setting(self):
        instance = mocks.ClassWithDescriptor(SecretSet(mocks.Descriptor()))

        Setter.secret(instance, attrname, 0, binding=False)

        self.assertEqual(getattr(instance, attrname), 0)
    def test_with_binding_descriptor(self):
        cls = type(mocks.ClassWithDescriptor(Binding(mocks.Descriptor())))

        result = get_descriptor(cls, attrname)

        self.assertIs(result, cls.__dict__[attrname])
class Class:
    attr = mocks.Descriptor()
    attrname = 'attr'