summaryrefslogtreecommitdiff
path: root/test/unittest_scoped_nodes.py
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-06-04 10:36:56 +0300
committercpopa <devnull@localhost>2014-06-04 10:36:56 +0300
commit78a8ae0cd8b21cd58ce4aed75d3cd2889e5eb3ae (patch)
treefa39a822b3178b182fea7edcfce53bbfa7783ba5 /test/unittest_scoped_nodes.py
parent438125bc6a0fbc24daeef1cc32575ba25187b2ff (diff)
downloadastroid-78a8ae0cd8b21cd58ce4aed75d3cd2889e5eb3ae.tar.gz
Add `slots` and `islots` methods to Class nodes.
Diffstat (limited to 'test/unittest_scoped_nodes.py')
-rw-r--r--test/unittest_scoped_nodes.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/unittest_scoped_nodes.py b/test/unittest_scoped_nodes.py
index 4d0bc59..fd46a8b 100644
--- a/test/unittest_scoped_nodes.py
+++ b/test/unittest_scoped_nodes.py
@@ -839,6 +839,67 @@ def g2():
# https://bitbucket.org/logilab/astroid/issue/17
self.assertEqual(list(instance.infer()), [YES])
+ def test_slots(self):
+ astroid = abuilder.string_build(dedent("""
+ from collections import deque
+ from textwrap import dedent
+
+ class First(object):
+ __slots__ = ("a", "b", 1)
+ class Second(object):
+ __slots__ = "a"
+ class Third(object):
+ __slots__ = deque(["a", "b", "c"])
+ class Fourth(object):
+ __slots__ = {"a": "a", "b": "b"}
+ class Fifth(object):
+ __slots__ = list
+ class Sixth(object):
+ __slots__ = ""
+ class Seventh(object):
+ __slots__ = dedent.__name__
+ class Eight(object):
+ __slots__ = ("parens")
+ """))
+ first = astroid['First']
+ first_slots = first.slots()
+ self.assertEqual(len(first_slots), 2)
+ self.assertIsInstance(first_slots[0], nodes.Const)
+ self.assertIsInstance(first_slots[1], nodes.Const)
+ self.assertEqual(first_slots[0].value, "a")
+ self.assertEqual(first_slots[1].value, "b")
+ self.assertEqual(list(first.islots()), first_slots)
+
+ second_slots = astroid['Second'].slots()
+ self.assertEqual(len(second_slots), 1)
+ self.assertIsInstance(second_slots[0], nodes.Const)
+ self.assertEqual(second_slots[0].value, "a")
+
+ third_slots = astroid['Third'].slots()
+ self.assertEqual(third_slots, [])
+
+ fourth_slots = astroid['Fourth'].slots()
+ self.assertEqual(len(fourth_slots), 2)
+ self.assertIsInstance(fourth_slots[0], nodes.Const)
+ self.assertIsInstance(fourth_slots[1], nodes.Const)
+ self.assertEqual(fourth_slots[0].value, "a")
+ self.assertEqual(fourth_slots[1].value, "b")
+
+ fifth_slots = astroid['Fifth'].slots()
+ self.assertEqual(fifth_slots, [])
+
+ sixth_slots = astroid['Sixth'].slots()
+ self.assertEqual(sixth_slots, [])
+
+ seventh_slots = astroid['Seventh'].slots()
+ self.assertEqual(len(seventh_slots), 0)
+
+ eight_slots = astroid['Eight'].slots()
+ self.assertEqual(len(eight_slots), 1)
+ self.assertIsInstance(eight_slots[0], nodes.Const)
+ self.assertEqual(eight_slots[0].value, "parens")
+
+
__all__ = ('ModuleNodeTC', 'ImportNodeTC', 'FunctionNodeTC', 'ClassNodeTC')
if __name__ == '__main__':