Пример #1
0
 def test_gen_expr_var_scope(self):
     data = 'l = list(n for n in range(10))\n'
     astroid = self.builder.string_build(data, __name__, __file__)
     # n unavailable outside gen expr scope
     self.assertNotIn('n', astroid)
     # test n is inferable anyway
     n = get_name_node(astroid, 'n')
     self.assertIsNot(n.scope(), astroid)
     self.assertEqual([i.__class__ for i in n.infer()], [YES.__class__])
Пример #2
0
 def test_gen_expr_var_scope(self):
     data = 'l = list(n for n in range(10))\n'
     astng = self.builder.string_build(data, __name__, __file__)
     # n unavailable outside gen expr scope
     self.failIf('n' in astng)
     # test n is inferable anyway
     n = get_name_node(astng, 'n')
     self.failIf(n.scope() is astng)
     self.failUnlessEqual([i.__class__ for i in n.infer()], [YES.__class__])
Пример #3
0
 def test_gen_expr_var_scope(self):
     data = 'l = list(n for n in range(10))\n'
     astroid = self.builder.string_build(data, __name__, __file__)
     # n unavailable outside gen expr scope
     self.assertNotIn('n', astroid)
     # test n is inferable anyway
     n = get_name_node(astroid, 'n')
     self.assertIsNot(n.scope(), astroid)
     self.assertEqual([i.__class__ for i in n.infer()],
                      [YES.__class__])
Пример #4
0
 def test_gen_expr_var_scope(self):
     data = 'l = list(n for n in range(10))\n'
     astng = self.builder.string_build(data, __name__, __file__)
     # n unavailable outside gen expr scope
     self.failIf('n' in astng)
     # test n is inferable anyway
     n = get_name_node(astng, 'n')
     self.failIf(n.scope() is astng)
     self.failUnlessEqual([i.__class__ for i in n.infer()],
                          [YES.__class__])
Пример #5
0
    def test_inner_decorator_member_lookup(self):
        code = '''
class FileA:
    def decorator(bla):
        return bla

    @decorator
    def funcA():
        return 4
        '''
        astng = builder.string_build(code, __name__, __file__)
        decname = get_name_node(astng['FileA'], 'decorator')
        it = decname.infer()
        obj = it.next()
        self.assertIsInstance(obj, nodes.Function)
        self.assertRaises(StopIteration, it.next)
Пример #6
0
    def test_inner_decorator_member_lookup(self):
        code = '''
class FileA:
    def decorator(bla):
        return bla

    @decorator
    def funcA():
        return 4
        '''
        astng = builder.string_build(code, __name__, __file__)
        decname = get_name_node(astng['FileA'], 'decorator')
        it = decname.infer()
        obj = it.next()
        self.assertIsInstance(obj, nodes.Function)
        self.assertRaises(StopIteration, it.next)
Пример #7
0
    def test_inner_decorator_member_lookup(self):
        if sys.version_info < (2, 4):
            self.skipTest('this test require python >= 2.4')
        code = '''
class FileA:
    def decorator(bla):
        return bla
    
    @decorator
    def funcA():
        return 4
        '''
        astng = builder.string_build(code, __name__, __file__)
        decname = get_name_node(astng['FileA'], 'decorator')
        it = decname.infer()
        obj = it.next()
        self.assertIsInstance(obj, nodes.Function)
        self.assertRaises(StopIteration, it.next)
Пример #8
0
    def test_decorator_arguments_lookup(self):
        code = '''
def decorator(value):
    def wrapper(function):
        return function
    return wrapper

class foo:
    member = 10

    @decorator(member) #This will cause pylint to complain
    def test(self):
        pass
        '''
        astng = builder.string_build(code, __name__, __file__)
        member = get_name_node(astng['foo'], 'member')
        it = member.infer()
        obj = it.next()
        self.assertIsInstance(obj, nodes.Const)
        self.assertEqual(obj.value, 10)
        self.assertRaises(StopIteration, it.next)
Пример #9
0
    def test_decorator_arguments_lookup(self):
        code = '''
def decorator(value):
    def wrapper(function):
        return function
    return wrapper

class foo:
    member = 10

    @decorator(member) #This will cause pylint to complain
    def test(self):
        pass
        '''
        astng = builder.string_build(code, __name__, __file__)
        member = get_name_node(astng['foo'], 'member')
        it = member.infer()
        obj = it.next()
        self.assertIsInstance(obj, nodes.Const)
        self.assertEqual(obj.value, 10)
        self.assertRaises(StopIteration, it.next)