File: test_descriptors_py36.py

package info (click to toggle)
python-wrapt 1.15.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,104 kB
  • sloc: python: 5,994; ansic: 2,354; makefile: 182; sh: 46
file content (38 lines) | stat: -rw-r--r-- 973 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import print_function

import unittest

import wrapt

class TestObjectDescriptors(unittest.TestCase):

    def test_set_name(self):
        @wrapt.decorator
        def _decorator(wrapped, instance, args, kwargs):
            return wrapped(*args, **kwargs)

        attribute_name = []

        class _descriptor_wrapper:
            def __init__(self, descriptor):
                self.__wrapped__ = descriptor

            def __set_name__(self, owner, name):
                attribute_name.append(name)

            def __get__(self, instance, owner=None):
                return self.__wrapped__.__get__(instance, owner)

        class Instance(object):
            @_decorator
            @_descriptor_wrapper
            def method(self):
                return True

        instance = Instance()

        self.assertEqual(attribute_name, ["method"])
        self.assertEqual(instance.method(), True)

if __name__ == '__main__':
    unittest.main()