Пример #1
0
 def test_python25_no_relative_import(self):
     fname = join(abspath(dirname(__file__)), 'regrtest_data', 'package', 'absimport.py')
     astng = builder.file_build(fname, 'absimport')
     self.failUnless(astng.absolute_import_activated(), True)
     infered = get_name_node(astng, 'import_package_subpackage_module').infer().next()
     # failed to import since absolute_import is activated
     self.failUnless(infered is YES)
 def test_nonregr_absolute_import(self):
     fname = join(abspath(dirname(__file__)), 'regrtest_data', 'absimp', 'string.py')
     astng = builder.file_build(fname, 'absimp.string')
     self.assertTrue(astng.absolute_import_activated(), True)
     infered = get_name_node(astng, 'string').infer().next()
     self.assertIsInstance(infered, nodes.Module)
     self.assertEqual(infered.name, 'string')
     self.assertIn('ascii_letters', infered.locals)
 def test_nonregr_absolute_import(self):
     fname = join(abspath(dirname(__file__)), 'regrtest_data', 'absimp', 'string.py')
     astng = builder.file_build(fname, 'absimp.string')
     self.failUnless(astng.absolute_import_activated(), True)
     infered = next(get_name_node(astng, 'string').infer())
     self.assertIsInstance(infered, nodes.Module)
     self.assertEqual(infered.name, 'string')
     self.failUnless('lower' in infered.locals)
Пример #4
0
 def test_nonregr_absolute_import(self):
     fname = join(abspath(dirname(__file__)), 'regrtest_data', 'absimp',
                  'string.py')
     astng = builder.file_build(fname, 'absimp.string')
     self.failUnless(astng.absolute_import_activated(), True)
     infered = next(get_name_node(astng, 'string').infer())
     self.assertIsInstance(infered, nodes.Module)
     self.assertEqual(infered.name, 'string')
     self.failUnless('lower' in infered.locals)
Пример #5
0
 def test_python25_no_relative_import(self):
     fname = join(abspath(dirname(__file__)), 'regrtest_data', 'package',
                  'absimport.py')
     astng = builder.file_build(fname, 'absimport')
     self.failUnless(astng.absolute_import_activated(), True)
     infered = next(
         get_name_node(astng, 'import_package_subpackage_module').infer())
     # failed to import since absolute_import is activated
     self.failUnless(infered is YES)
Пример #6
0
 def test_nonregr_absolute_import(self):
     fname = join(abspath(dirname(__file__)), 'regrtest_data', 'absimp',
                  'string.py')
     astng = builder.file_build(fname, 'absimp.string')
     self.assertTrue(astng.absolute_import_activated(), True)
     infered = get_name_node(astng, 'string').infer().next()
     self.assertIsInstance(infered, nodes.Module)
     self.assertEqual(infered.name, 'string')
     self.assertIn('ascii_letters', infered.locals)
Пример #7
0
 def test_python25_no_relative_import(self):
     if sys.version_info < (2, 5):
         self.skip('require py >= 2.5')
     # data = 'import unittest_lookup; print unittest_lookup'
     # astng = builder.string_build(data, 'logilab.astng.test.unittest_inference', __file__)
     # self.failIf(astng.absolute_import_activated())
     # infered = get_name_node(astng, 'unittest_lookup').infer().next()
     # self.assertIsInstance(infered, nodes.Module)
     data = 'from __future__ import absolute_import; import unittest_lookup; print unittest_lookup'
     astng = builder.file_build(join('regrtest_data', 'absimport.py'), 'absimport')
     self.failUnless(astng.absolute_import_activated(), True)
     infered = get_name_node(astng, 'import_package_subpackage_module').infer().next()
     # failed to import since absolute_import is activated
     self.failUnless(infered is YES)
Пример #8
0
 def test_python25_no_relative_import(self):
     if sys.version_info < (2, 5):
         self.skip('require py >= 2.5')
     # data = 'import unittest_lookup; print unittest_lookup'
     # astng = builder.string_build(data, 'logilab.astng.test.unittest_inference', __file__)
     # self.failIf(astng.absolute_import_activated())
     # infered = get_name_node(astng, 'unittest_lookup').infer().next()
     # self.assertIsInstance(infered, nodes.Module)
     data = 'from __future__ import absolute_import; import unittest_lookup; print unittest_lookup'
     astng = builder.file_build(join('regrtest_data', 'absimport.py'),
                                'absimport')
     self.failUnless(astng.absolute_import_activated(), True)
     infered = get_name_node(
         astng, 'import_package_subpackage_module').infer().next()
     # failed to import since absolute_import is activated
     self.failUnless(infered is YES)
Пример #9
0
# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
"""tests for the astng variable lookup capabilities
"""
import sys
from os.path import join, abspath, dirname
from logilab.common.testlib import TestCase, unittest_main

from logilab.astng import builder, nodes, scoped_nodes, \
     InferenceError, NotFoundError, UnresolvableName
from logilab.astng.scoped_nodes import builtin_lookup
from logilab.astng.bases import YES
from unittest_inference import get_name_node

builder = builder.ASTNGBuilder()
DATA = join(dirname(abspath(__file__)), 'data')
MODULE = builder.file_build(join(DATA, 'module.py'), 'data.module')
MODULE2 = builder.file_build(join(DATA, 'module2.py'), 'data.module2')
NONREGR = builder.file_build(join(DATA, 'nonregr.py'), 'data.nonregr')

class LookupTC(TestCase):

    def test_limit(self):
        code = '''
l = [a
     for a,b in list]

a = 1
b = a
a = None

def func():
Пример #10
0
"""tests for the astng variable lookup capabilities
"""
import sys
from os.path import join, abspath, dirname

from logilab.common.testlib import TestCase, unittest_main, require_version

from logilab.astng import builder, nodes, scoped_nodes, \
     InferenceError, NotFoundError, UnresolvableName
from logilab.astng.scoped_nodes import builtin_lookup, Function
from logilab.astng.bases import YES
from unittest_inference import get_name_node

builder = builder.ASTNGBuilder()
DATA = join(dirname(abspath(__file__)), 'data')
MODULE = builder.file_build(join(DATA, 'module.py'), 'data.module')
MODULE2 = builder.file_build(join(DATA, 'module2.py'), 'data.module2')
NONREGR = builder.file_build(join(DATA, 'nonregr.py'), 'data.nonregr')


class LookupTC(TestCase):
    def test_limit(self):
        code = '''
l = [a
     for a,b in list]

a = 1
b = a
a = None

def func():
Пример #11
0
# You should have received a copy of the GNU Lesser General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""tests for the astng variable lookup capabilities
"""
import sys
from os.path import join, abspath
from logilab.common.testlib import TestCase, unittest_main

from logilab.astng import builder, nodes, scoped_nodes, \
     InferenceError, NotFoundError
from logilab.astng.scoped_nodes import builtin_lookup
from unittest_inference import get_name_node

builder = builder.ASTNGBuilder()
MODULE = builder.file_build('data/module.py', 'data.module')
MODULE2 = builder.file_build('data/module2.py', 'data.module2')
NONREGR = builder.file_build('data/nonregr.py', 'data.nonregr')

class LookupTC(TestCase):

    def test_limit(self):
        code = '''
l = [a
     for a,b in list]

a = 1
b = a
a = None

def func():