summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-07-24 17:01:10 +0200
committercpopa <devnull@localhost>2014-07-24 17:01:10 +0200
commit2c18a4ad2b1fb435e850615a2cceebec3bfe2352 (patch)
tree6714dd3c53a3f9dcfb63ad58bb3160ef57e2afe5 /test
parent4305109a216a5b48df7619380b39e9d6465e1d53 (diff)
downloadastroid-2c18a4ad2b1fb435e850615a2cceebec3bfe2352.tar.gz
Function nodes can detect decorator call chain and see if they are decorated with builtin descriptors (`classmethod` and `staticmethod`).
Diffstat (limited to 'test')
-rw-r--r--test/unittest_scoped_nodes.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/unittest_scoped_nodes.py b/test/unittest_scoped_nodes.py
index 116b275..94f3a34 100644
--- a/test/unittest_scoped_nodes.py
+++ b/test/unittest_scoped_nodes.py
@@ -411,6 +411,47 @@ test()
self.assertEqual(node.locals['stcmethod'][0].type,
'staticmethod')
+ def test_decorator_builtin_descriptors(self):
+ astroid = abuilder.string_build(dedent("""
+ def static_decorator(platform=None, order=50):
+ def wrapper(f):
+ f.cgm_module = True
+ f.cgm_module_order = order
+ f.cgm_module_platform = platform
+ return staticmethod(f)
+ return wrapper
+
+ def classmethod_decorator(platform=None):
+ def wrapper(f):
+ f.platform = platform
+ return classmethod(f)
+ return wrapper
+
+ class SomeClass(object):
+ @static_decorator()
+ def static(node, cfg):
+ pass
+ @classmethod_decorator()
+ def classmethod(cls):
+ pass
+ @static_decorator
+ def not_so_static(node):
+ pass
+ @classmethod_decorator
+ def not_so_classmethod(node):
+ pass
+
+ """))
+ node = astroid.locals['SomeClass'][0]
+ self.assertEqual(node.locals['static'][0].type,
+ 'staticmethod')
+ self.assertEqual(node.locals['classmethod'][0].type,
+ 'classmethod')
+ self.assertEqual(node.locals['not_so_static'][0].type,
+ 'method')
+ self.assertEqual(node.locals['not_so_classmethod'][0].type,
+ 'method')
+
class ClassNodeTC(TestCase):