summaryrefslogtreecommitdiff
path: root/astroid/tests/unittest_lookup.py
diff options
context:
space:
mode:
Diffstat (limited to 'astroid/tests/unittest_lookup.py')
-rw-r--r--astroid/tests/unittest_lookup.py79
1 files changed, 38 insertions, 41 deletions
diff --git a/astroid/tests/unittest_lookup.py b/astroid/tests/unittest_lookup.py
index 4811981d..28c60209 100644
--- a/astroid/tests/unittest_lookup.py
+++ b/astroid/tests/unittest_lookup.py
@@ -17,13 +17,15 @@
# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""tests for the astroid variable lookup capabilities
"""
+import functools
import sys
-from functools import partial
import unittest
-from astroid import nodes, InferenceError, NotFoundError, UnresolvableName
-from astroid.scoped_nodes import builtin_lookup
-from astroid.bases import YES
+from astroid import bases
+from astroid import builder
+from astroid import exceptions
+from astroid import nodes
+from astroid import scoped_nodes
from astroid import test_utils
from astroid.tests import resources
@@ -48,7 +50,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
def func():
c = 1
'''
- astroid = test_utils.build_module(code, __name__)
+ astroid = builder.parse(code, __name__)
# a & b
a = next(astroid.nodes_of_class(nodes.Name))
self.assertEqual(a.lineno, 2)
@@ -67,19 +69,20 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
b_value = next(b_infer)
self.assertEqual(b_value.value, 1)
# c
- self.assertRaises(StopIteration, partial(next, b_infer))
+ self.assertRaises(StopIteration, functools.partial(next, b_infer))
func = astroid.locals['func'][0]
self.assertEqual(len(func.lookup('c')[1]), 1)
def test_module(self):
- astroid = test_utils.build_module('pass', __name__)
+ astroid = builder.parse('pass', __name__)
# built-in objects
none = next(astroid.ilookup('None'))
self.assertIsNone(none.value)
obj = next(astroid.ilookup('object'))
self.assertIsInstance(obj, nodes.ClassDef)
self.assertEqual(obj.name, 'object')
- self.assertRaises(InferenceError, partial(next, astroid.ilookup('YOAA')))
+ self.assertRaises(exceptions.InferenceError,
+ functools.partial(next, astroid.ilookup('YOAA')))
# XXX
self.assertEqual(len(list(self.nonregr.ilookup('enumerate'))), 2)
@@ -92,7 +95,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
class A(A):
pass
'''
- astroid = test_utils.build_module(code, __name__)
+ astroid = builder.parse(code, __name__)
cls1 = astroid.locals['A'][0]
cls2 = astroid.locals['A'][1]
name = next(cls2.nodes_of_class(nodes.Name))
@@ -105,8 +108,8 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
self.assertTrue(isinstance(my_dict, nodes.Dict), my_dict)
none = next(method.ilookup('None'))
self.assertIsNone(none.value)
- self.assertRaises(InferenceError, partial(next, method.ilookup('YOAA')))
-
+ self.assertRaises(exceptions.InferenceError,
+ functools.partial(next, method.ilookup('YOAA')))
def test_function_argument_with_default(self):
make_class = self.module2['make_class']
@@ -124,15 +127,15 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
obj = next(klass.ilookup('object'))
self.assertIsInstance(obj, nodes.ClassDef)
self.assertEqual(obj.name, 'object')
- self.assertRaises(InferenceError, partial(next, klass.ilookup('YOAA')))
+ self.assertRaises(exceptions.InferenceError,
+ functools.partial(next, klass.ilookup('YOAA')))
def test_inner_classes(self):
ddd = list(self.nonregr['Ccc'].ilookup('Ddd'))
self.assertEqual(ddd[0].name, 'Ddd')
-
def test_loopvar_hiding(self):
- astroid = test_utils.build_module("""
+ astroid = builder.parse("""
x = 10
for x in range(5):
print (x)
@@ -148,7 +151,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
self.assertEqual(len(xnames[2].lookup('x')[1]), 2)
def test_list_comps(self):
- astroid = test_utils.build_module("""
+ astroid = builder.parse("""
print ([ i for i in range(10) ])
print ([ i for i in range(10) ])
print ( list( i for i in range(10) ) )
@@ -163,18 +166,18 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
def test_list_comp_target(self):
"""test the list comprehension target"""
- astroid = test_utils.build_module("""
+ astroid = builder.parse("""
ten = [ var for var in range(10) ]
var
""")
var = astroid.body[1].value
if sys.version_info < (3, 0):
- self.assertEqual(var.inferred(), [YES])
+ self.assertEqual(var.inferred(), [bases.YES])
else:
- self.assertRaises(UnresolvableName, var.inferred)
+ self.assertRaises(exceptions.UnresolvableName, var.inferred)
def test_dict_comps(self):
- astroid = test_utils.build_module("""
+ astroid = builder.parse("""
print ({ i: j for i in range(10) for j in range(10) })
print ({ i: j for i in range(10) for j in range(10) })
""", __name__)
@@ -191,7 +194,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
self.assertEqual(xnames[1].lookup('i')[1][0].lineno, 3)
def test_set_comps(self):
- astroid = test_utils.build_module("""
+ astroid = builder.parse("""
print ({ i for i in range(10) })
print ({ i for i in range(10) })
""", __name__)
@@ -202,15 +205,15 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
self.assertEqual(xnames[1].lookup('i')[1][0].lineno, 3)
def test_set_comp_closure(self):
- astroid = test_utils.build_module("""
+ astroid = builder.parse("""
ten = { var for var in range(10) }
var
""")
var = astroid.body[1].value
- self.assertRaises(UnresolvableName, var.inferred)
+ self.assertRaises(exceptions.UnresolvableName, var.inferred)
def test_generator_attributes(self):
- tree = test_utils.build_module("""
+ tree = builder.parse("""
def count():
"test"
yield 0
@@ -218,8 +221,8 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
iterer = count()
num = iterer.next()
""")
- next = tree.body[2].value.func # Getattr
- gener = next.expr.inferred()[0] # Generator
+ next = tree.body[2].value.func
+ gener = next.expr.inferred()[0]
if sys.version_info < (3, 0):
self.assertIsInstance(gener.getattr('next')[0], nodes.FunctionDef)
else:
@@ -240,18 +243,17 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
class NoName: pass
p3 = NoName()
'''
- astroid = test_utils.build_module(code, __name__)
+ astroid = builder.parse(code, __name__)
p1 = next(astroid['p1'].infer())
self.assertTrue(p1.getattr('__name__'))
p2 = next(astroid['p2'].infer())
self.assertTrue(p2.getattr('__name__'))
self.assertTrue(astroid['NoName'].getattr('__name__'))
p3 = next(astroid['p3'].infer())
- self.assertRaises(NotFoundError, p3.getattr, '__name__')
-
+ self.assertRaises(exceptions.NotFoundError, p3.getattr, '__name__')
def test_function_module_special(self):
- astroid = test_utils.build_module('''
+ astroid = builder.parse('''
def initialize(linter):
"""initialize linter with checkers in this package """
package_load(linter, __path__[0])
@@ -259,16 +261,14 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
path = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == '__path__'][0]
self.assertEqual(len(path.lookup('__path__')[1]), 1)
-
def test_builtin_lookup(self):
- self.assertEqual(builtin_lookup('__dict__')[1], ())
- intstmts = builtin_lookup('int')[1]
+ self.assertEqual(scoped_nodes.builtin_lookup('__dict__')[1], ())
+ intstmts = scoped_nodes.builtin_lookup('int')[1]
self.assertEqual(len(intstmts), 1)
self.assertIsInstance(intstmts[0], nodes.ClassDef)
self.assertEqual(intstmts[0].name, 'int')
self.assertIs(intstmts[0], nodes.const_factory(1)._proxied)
-
def test_decorator_arguments_lookup(self):
code = '''
def decorator(value):
@@ -288,8 +288,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
obj = next(it)
self.assertIsInstance(obj, nodes.Const)
self.assertEqual(obj.value, 10)
- self.assertRaises(StopIteration, partial(next, it))
-
+ self.assertRaises(StopIteration, functools.partial(next, it))
def test_inner_decorator_member_lookup(self):
code = '''
@@ -305,8 +304,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
it = decname.infer()
obj = next(it)
self.assertIsInstance(obj, nodes.FunctionDef)
- self.assertRaises(StopIteration, partial(next, it))
-
+ self.assertRaises(StopIteration, functools.partial(next, it))
def test_static_method_lookup(self):
code = '''
@@ -322,12 +320,11 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
def __init__(self):
print (FileA.funcA())
'''
- astroid = test_utils.build_module(code, __name__)
+ astroid = builder.parse(code, __name__)
it = astroid['Test']['__init__'].ilookup('FileA')
obj = next(it)
self.assertIsInstance(obj, nodes.ClassDef)
- self.assertRaises(StopIteration, partial(next, it))
-
+ self.assertRaises(StopIteration, functools.partial(next, it))
def test_global_delete(self):
code = '''
@@ -343,7 +340,7 @@ class LookupTest(resources.SysPathSetup, unittest.TestCase):
def run1():
f = Frobble()
'''
- astroid = test_utils.build_module(code, __name__)
+ astroid = builder.parse(code, __name__)
stmts = astroid['run2'].lookup('Frobbel')[1]
self.assertEqual(len(stmts), 0)
stmts = astroid['run1'].lookup('Frobbel')[1]