diff options
43 files changed, 608 insertions, 133 deletions
@@ -131,20 +131,12 @@ class MyBuildPy(build_py): dest = join(basedir, directory) shutil.rmtree(dest, ignore_errors=True) shutil.copytree(directory, dest) - if sys.version_info >= (3, 0): - # process manually python file in include_dirs (test data) - from distutils.util import run_2to3 - print('running 2to3 on', dest) - run_2to3([dest]) def install(**kwargs): """setup entry point""" if USE_SETUPTOOLS: if '--force-manifest' in sys.argv: sys.argv.remove('--force-manifest') - # install-layout option was introduced in 2.5.3-1~exp1 - elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: - sys.argv.remove('--install-layout=deb') if subpackage_of: package = subpackage_of + '.' + modname kwargs['package_dir'] = {package : '.'} diff --git a/test/data_py3/MyPyPa-0.1.0-py2.5.egg b/test/data_py3/MyPyPa-0.1.0-py2.5.egg Binary files differnew file mode 100644 index 00000000..f62599c7 --- /dev/null +++ b/test/data_py3/MyPyPa-0.1.0-py2.5.egg diff --git a/test/data_py3/MyPyPa-0.1.0-py2.5.zip b/test/data_py3/MyPyPa-0.1.0-py2.5.zip Binary files differnew file mode 100644 index 00000000..f62599c7 --- /dev/null +++ b/test/data_py3/MyPyPa-0.1.0-py2.5.zip diff --git a/test/data_py3/SSL1/Connection1.py b/test/data_py3/SSL1/Connection1.py new file mode 100644 index 00000000..7373271d --- /dev/null +++ b/test/data_py3/SSL1/Connection1.py @@ -0,0 +1,14 @@ +"""M2Crypto.SSL.Connection + +Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.""" + +RCS_id='$Id: Connection1.py,v 1.1 2005-06-13 20:55:22 syt Exp $' + +#Some code deleted here + +class Connection: + + """An SSL connection.""" + + def __init__(self, ctx, sock=None): + print('init Connection') diff --git a/test/data_py3/SSL1/__init__.py b/test/data_py3/SSL1/__init__.py new file mode 100644 index 00000000..c83ededc --- /dev/null +++ b/test/data_py3/SSL1/__init__.py @@ -0,0 +1 @@ +from .Connection1 import Connection diff --git a/test/data_py3/__init__.py b/test/data_py3/__init__.py new file mode 100644 index 00000000..332e2e72 --- /dev/null +++ b/test/data_py3/__init__.py @@ -0,0 +1 @@ +__revision__="$Id: __init__.py,v 1.1 2005-06-13 20:55:20 syt Exp $" diff --git a/test/data_py3/absimport.py b/test/data_py3/absimport.py new file mode 100644 index 00000000..88f9d955 --- /dev/null +++ b/test/data_py3/absimport.py @@ -0,0 +1,3 @@ + +import email +from email import message diff --git a/test/data_py3/all.py b/test/data_py3/all.py new file mode 100644 index 00000000..587765b5 --- /dev/null +++ b/test/data_py3/all.py @@ -0,0 +1,9 @@ + +name = 'a' +_bla = 2 +other = 'o' +class Aaa: pass + +def func(): print('yo') + +__all__ = 'Aaa', '_bla', 'name' diff --git a/test/data_py3/appl/__init__.py b/test/data_py3/appl/__init__.py new file mode 100644 index 00000000..d652ffd9 --- /dev/null +++ b/test/data_py3/appl/__init__.py @@ -0,0 +1,3 @@ +""" +Init +""" diff --git a/test/data_py3/appl/myConnection.py b/test/data_py3/appl/myConnection.py new file mode 100644 index 00000000..b5b206a0 --- /dev/null +++ b/test/data_py3/appl/myConnection.py @@ -0,0 +1,11 @@ +import SSL1 +class MyConnection(SSL1.Connection): + + """An SSL connection.""" + + def __init__(self, dummy): + print('MyConnection init') + +if __name__ == '__main__': + myConnection = MyConnection(' ') + input('Press Enter to continue...') diff --git a/test/data_py3/email.py b/test/data_py3/email.py new file mode 100644 index 00000000..dc593564 --- /dev/null +++ b/test/data_py3/email.py @@ -0,0 +1 @@ +"""fake email module to test absolute import doesn't grab this one""" diff --git a/test/data_py3/find_test/__init__.py b/test/data_py3/find_test/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/data_py3/find_test/__init__.py diff --git a/test/data_py3/find_test/module.py b/test/data_py3/find_test/module.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/data_py3/find_test/module.py diff --git a/test/data_py3/find_test/module2.py b/test/data_py3/find_test/module2.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/data_py3/find_test/module2.py diff --git a/test/data_py3/find_test/noendingnewline.py b/test/data_py3/find_test/noendingnewline.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/data_py3/find_test/noendingnewline.py diff --git a/test/data_py3/find_test/nonregr.py b/test/data_py3/find_test/nonregr.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/data_py3/find_test/nonregr.py diff --git a/test/data_py3/format.py b/test/data_py3/format.py new file mode 100644 index 00000000..73797061 --- /dev/null +++ b/test/data_py3/format.py @@ -0,0 +1,34 @@ +"""A multiline string +""" + +function('aeozrijz\ +earzer', hop) +# XXX write test +x = [i for i in range(5) + if i % 4] + +fonction(1, + 2, + 3, + 4) + +def definition(a, + b, + c): + return a + b + c + +class debile(dict, + object): + pass + +if aaaa: pass +else: + aaaa,bbbb = 1,2 + aaaa,bbbb = bbbb,aaaa +# XXX write test +hop = \ + aaaa + + +__revision__.lower(); + diff --git a/test/data_py3/lmfp/__init__.py b/test/data_py3/lmfp/__init__.py new file mode 100644 index 00000000..74b26b82 --- /dev/null +++ b/test/data_py3/lmfp/__init__.py @@ -0,0 +1,2 @@ +# force a "direct" python import +from . import foo diff --git a/test/data_py3/lmfp/foo.py b/test/data_py3/lmfp/foo.py new file mode 100644 index 00000000..8f7de1e8 --- /dev/null +++ b/test/data_py3/lmfp/foo.py @@ -0,0 +1,6 @@ +import sys +if not getattr(sys, 'bar', None): + sys.just_once = [] +# there used to be two numbers here because +# of a load_module_from_path bug +sys.just_once.append(42) diff --git a/test/data_py3/module.py b/test/data_py3/module.py new file mode 100644 index 00000000..ec5b64aa --- /dev/null +++ b/test/data_py3/module.py @@ -0,0 +1,89 @@ +"""test module for astroid +""" + +__revision__ = '$Id: module.py,v 1.2 2005-11-02 11:56:54 syt Exp $' +from logilab.common.shellutils import ProgressBar as pb +from astroid import modutils +from astroid.utils import * +import os.path +MY_DICT = {} + +def global_access(key, val): + """function test""" + local = 1 + MY_DICT[key] = val + for i in val: + if i: + del MY_DICT[i] + continue + else: + break + else: + print('!!!') + + +class YO: + """hehe""" + a = 1 + + def __init__(self): + try: + self.yo = 1 + except ValueError as ex: + pass + except (NameError, TypeError): + raise XXXError() + except: + raise + + + +class YOUPI(YO): + class_attr = None + + def __init__(self): + self.member = None + + def method(self): + """method test""" + global MY_DICT + try: + MY_DICT = {} + local = None + autre = [a for (a, b) in MY_DICT if b] + if b in autre: + print('yo', end=' ') + else: + if a in autre: + print('hehe') + global_access(local, val=autre) + finally: + return local + + def static_method(): + """static method test""" + assert MY_DICT, '???' + static_method = staticmethod(static_method) + + def class_method(cls): + """class method test""" + exec(a, b) + class_method = classmethod(class_method) + + +def four_args(a, b, c, d): + """four arguments (was nested_args)""" + print(a, b, c, d) + while 1: + if a: + break + a += +1 + else: + b += -2 + if c: + d = ((a) and (b)) or (c) + else: + c = ((a) and (b)) or (d) + list(map(lambda x, y: (y, x), a)) +redirect = four_args + diff --git a/test/data_py3/module1abs/__init__.py b/test/data_py3/module1abs/__init__.py new file mode 100644 index 00000000..f9d5b686 --- /dev/null +++ b/test/data_py3/module1abs/__init__.py @@ -0,0 +1,4 @@ + +from . import core +from .core import * +print(sys.version) diff --git a/test/data_py3/module1abs/core.py b/test/data_py3/module1abs/core.py new file mode 100644 index 00000000..de101117 --- /dev/null +++ b/test/data_py3/module1abs/core.py @@ -0,0 +1 @@ +import sys diff --git a/test/data_py3/module2.py b/test/data_py3/module2.py new file mode 100644 index 00000000..344800d1 --- /dev/null +++ b/test/data_py3/module2.py @@ -0,0 +1,143 @@ +from data_py3.module import YO, YOUPI +import data + + +class Specialization(YOUPI, YO): + pass + + + +class Metaclass(type): + pass + + + +class Interface: + pass + + + +class MyIFace(Interface): + pass + + + +class AnotherIFace(Interface): + pass + + + +class MyException(Exception): + pass + + + +class MyError(MyException): + pass + + + +class AbstractClass(object): + + def to_override(self, whatever): + raise NotImplementedError() + + def return_something(self, param): + if param: + return 'toto' + return + + + +class Concrete0: + __implements__ = MyIFace + + + +class Concrete1: + __implements__ = (MyIFace, AnotherIFace) + + + +class Concrete2: + __implements__ = (MyIFace, AnotherIFace) + + + +class Concrete23(Concrete1): + pass + +del YO.member +del YO +[SYN1, SYN2] = (Concrete0, Concrete1) +assert repr(1) +b = (1) | (((2) & (3)) ^ (8)) +bb = ((1) | (two)) | (6) +ccc = ((one) & (two)) & (three) +dddd = ((x) ^ (o)) ^ (r) +exec('c = 3') +exec('c = 3', {}, {}) + +def raise_string(a=2, *args, **kwargs): + raise Exception('yo') + yield 'coucou' + yield +a = (b) + (2) +c = (b) * (2) +c = (b) / (2) +c = (b) // (2) +c = (b) - (2) +c = (b) % (2) +c = (b) ** (2) +c = (b) << (2) +c = (b) >> (2) +c = ~b +c = not b +d = [c] +e = d[:] +e = d[a:b:c] +raise_string(*args, **kwargs) +print('bonjour', file=stream) +print('salut', end=' ', file=stream) + +def make_class(any, base=data.module.YO, *args, **kwargs): + """check base is correctly resolved to Concrete0""" + + + class Aaaa(base): + """dynamic class""" + + + return Aaaa +from os.path import abspath +import os as myos + + +class A: + pass + + + +class A(A): + pass + + +def generator(): + """A generator.""" + yield + +def not_a_generator(): + """A function that contains generator, but is not one.""" + + def generator(): + yield + genl = lambda : (yield) + +def with_metaclass(meta, *bases): + return meta('NewBase', bases, {}) + + +class NotMetaclass(with_metaclass(Metaclass)): + pass + + diff --git a/test/data_py3/noendingnewline.py b/test/data_py3/noendingnewline.py new file mode 100644 index 00000000..e17b92cc --- /dev/null +++ b/test/data_py3/noendingnewline.py @@ -0,0 +1,36 @@ +import unittest + + +class TestCase(unittest.TestCase): + + def setUp(self): + unittest.TestCase.setUp(self) + + + def tearDown(self): + unittest.TestCase.tearDown(self) + + def testIt(self): + self.a = 10 + self.xxx() + + + def xxx(self): + if False: + pass + print('a') + + if False: + pass + pass + + if False: + pass + print('rara') + + +if __name__ == '__main__': + print('test2') + unittest.main() + + diff --git a/test/data_py3/nonregr.py b/test/data_py3/nonregr.py new file mode 100644 index 00000000..78765c85 --- /dev/null +++ b/test/data_py3/nonregr.py @@ -0,0 +1,57 @@ + + +try: + enumerate = enumerate +except NameError: + + def enumerate(iterable): + """emulates the python2.3 enumerate() function""" + i = 0 + for val in iterable: + yield i, val + i += 1 + +def toto(value): + for k, v in value: + print(v.get('yo')) + + +import imp +fp, mpath, desc = imp.find_module('optparse',a) +s_opt = imp.load_module('std_optparse', fp, mpath, desc) + +class OptionParser(s_opt.OptionParser): + + def parse_args(self, args=None, values=None, real_optparse=False): + if real_optparse: + pass +## return super(OptionParser, self).parse_args() + else: + import optcomp + optcomp.completion(self) + + +class Aaa(object): + """docstring""" + def __init__(self): + self.__setattr__('a','b') + pass + + def one_public(self): + """docstring""" + pass + + def another_public(self): + """docstring""" + pass + +class Ccc(Aaa): + """docstring""" + + class Ddd(Aaa): + """docstring""" + pass + + class Eee(Ddd): + """docstring""" + pass diff --git a/test/data_py3/notall.py b/test/data_py3/notall.py new file mode 100644 index 00000000..9d35aa3a --- /dev/null +++ b/test/data_py3/notall.py @@ -0,0 +1,8 @@ + +name = 'a' +_bla = 2 +other = 'o' +class Aaa: pass + +def func(): print('yo') + diff --git a/test/regrtest_data/absimp/string.py b/test/regrtest_data/absimp/string.py index 07cf4605..e68e7496 100644 --- a/test/regrtest_data/absimp/string.py +++ b/test/regrtest_data/absimp/string.py @@ -1,3 +1,3 @@ -from __future__ import absolute_import +from __future__ import absolute_import, print_function import string -print string +print(string) diff --git a/test/regrtest_data/package/__init__.py b/test/regrtest_data/package/__init__.py index 3c5c0960..575d18b1 100644 --- a/test/regrtest_data/package/__init__.py +++ b/test/regrtest_data/package/__init__.py @@ -1,4 +1,4 @@ """package's __init__ file""" -import subpackage +from . import subpackage diff --git a/test/regrtest_data/package/absimport.py b/test/regrtest_data/package/absimport.py index e3730c8b..33ed117c 100644 --- a/test/regrtest_data/package/absimport.py +++ b/test/regrtest_data/package/absimport.py @@ -1,6 +1,6 @@ -from __future__ import absolute_import +from __future__ import absolute_import, print_function import import_package_subpackage_module # fail -print import_package_subpackage_module +print(import_package_subpackage_module) from . import hello as hola diff --git a/test/unittest_brain.py b/test/unittest_brain.py index 8bff3104..8fa853c3 100644 --- a/test/unittest_brain.py +++ b/test/unittest_brain.py @@ -17,14 +17,14 @@ """Tests for basic functionality in astroid.brain.""" import sys -from logilab.common.testlib import TestCase, unittest_main +import unittest from astroid import MANAGER from astroid import bases from astroid import test_utils import astroid -class HashlibTC(TestCase): +class HashlibTC(unittest.TestCase): def test_hashlib(self): """Tests that brain extensions for hashlib work.""" hashlib_module = MANAGER.ast_from_module_name('hashlib') @@ -40,7 +40,7 @@ class HashlibTC(TestCase): self.assertEqual(len(class_obj['hexdigest'].args.args), 1) -class NamedTupleTest(TestCase): +class NamedTupleTest(unittest.TestCase): def test_namedtuple_base(self): klass = test_utils.extract_node(""" from collections import namedtuple @@ -66,7 +66,7 @@ class NamedTupleTest(TestCase): for base in klass.ancestors(): if base.name == 'X': break - self.assertCountEqual(["a", "b", "c"], base.instance_attrs.keys()) + self.assertSetEqual({"a", "b", "c"}, set(base.instance_attrs)) def test_namedtuple_inference_failure(self): klass = test_utils.extract_node(""" @@ -96,4 +96,4 @@ class NamedTupleTest(TestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_builder.py b/test/unittest_builder.py index e8c2dfaa..47ae158f 100644 --- a/test/unittest_builder.py +++ b/test/unittest_builder.py @@ -22,7 +22,6 @@ import sys from os.path import join, abspath, dirname from functools import partial -from logilab.common.testlib import TestCase, unittest_main from pprint import pprint from astroid import builder, nodes, InferenceError, NotFoundError @@ -32,16 +31,25 @@ from astroid.manager import AstroidManager from astroid import test_utils MANAGER = AstroidManager() + PY3K = sys.version_info >= (3, 0) +if PY3K: + DATA = join(dirname(abspath(__file__)), 'data_py3') +else: + DATA = join(dirname(abspath(__file__)), 'data') + from unittest_inference import get_name_node -import data -from data import module as test_module +if PY3K: + import data_py3 as data + from data_py3 import module as test_module +else: + import data + from data import module as test_module -DATA = join(dirname(abspath(__file__)), 'data') -class FromToLineNoTC(TestCase): +class FromToLineNoTC(unittest.TestCase): astroid = builder.AstroidBuilder().file_build(join(DATA, 'format.py')) @@ -257,7 +265,7 @@ with file("/tmp/pouet") as f: -class BuilderTC(TestCase): +class BuilderTC(unittest.TestCase): def setUp(self): self.builder = builder.AstroidBuilder() @@ -491,14 +499,15 @@ def global_no_effect(): """) self.assertEqual(set(['print_function', 'absolute_import']), mod.future_imports) -class FileBuildTC(TestCase): - - module = builder.AstroidBuilder().file_build(join(DATA, 'module.py'), 'data.module') +class FileBuildTC(unittest.TestCase): + module = builder.AstroidBuilder().file_build( + join(DATA, 'module.py'), + '%s.module' % (data.__name__,)) def test_module_base_props(self): """test base properties and method of a astroid module""" module = self.module - self.assertEqual(module.name, 'data.module') + self.assertEqual(module.name, '%s.module' % (data.__name__)) self.assertEqual(module.doc, "test module for astroid\n") self.assertEqual(module.fromlineno, 0) self.assertIsNone(module.parent) @@ -628,7 +637,7 @@ class ModuleBuildTC(FileBuildTC): self.module = abuilder.module_build(test_module) -class MoreTC(TestCase): +class MoreTC(unittest.TestCase): def setUp(self): self.builder = builder.AstroidBuilder() @@ -720,7 +729,7 @@ class A(object): if sys.version_info < (3, 0): guess_encoding = builder._guess_encoding - class TestGuessEncoding(TestCase): + class TestGuessEncoding(unittest.TestCase): def testEmacs(self): e = guess_encoding('# -*- coding: UTF-8 -*-') @@ -769,4 +778,4 @@ if sys.version_info < (3, 0): self.assertIsNone(e) if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_inference.py b/test/unittest_inference.py index f17f1fb6..d76393e8 100644 --- a/test/unittest_inference.py +++ b/test/unittest_inference.py @@ -21,15 +21,16 @@ from os.path import join, dirname, abspath import sys from functools import partial from textwrap import dedent +import unittest import six -from logilab.common.testlib import TestCase, unittest_main, require_version - from astroid import InferenceError, builder, nodes from astroid.inference import infer_end as inference_infer_end from astroid.bases import YES, Instance, BoundMethod, UnboundMethod,\ path_wrapper, BUILTINS +from astroid.test_utils import require_version + def get_name_node(start_from, name, index=0): return [n for n in start_from.nodes_of_class(nodes.Name) if n.name == name][index] @@ -39,7 +40,7 @@ def get_node_of_class(start_from, klass): builder = builder.AstroidBuilder() -class InferenceUtilsTC(TestCase): +class InferenceUtilsTC(unittest.TestCase): def test_path_wrapper(self): def infer_default(self, *args): @@ -56,7 +57,7 @@ else: EXC_MODULE = BUILTINS -class InferenceTC(TestCase): +class InferenceTC(unittest.TestCase): CODE = ''' @@ -1378,4 +1379,4 @@ def test(*args, **kwargs): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_inspector.py b/test/unittest_inspector.py index 358dd963..5d5eaa2d 100644 --- a/test/unittest_inspector.py +++ b/test/unittest_inspector.py @@ -19,8 +19,8 @@ import sys from os.path import join, abspath, dirname +import unittest -from logilab.common.testlib import TestCase, unittest_main from astroid import nodes, inspector from astroid.bases import Instance, YES @@ -36,7 +36,7 @@ def astroid_wrapper(func, modname): DATA2 = join(dirname(abspath(__file__)), 'data2') -class LinkerTC(TestCase): +class LinkerTC(unittest.TestCase): def setUp(self): self.project = MANAGER.project_from_files([DATA2], astroid_wrapper) @@ -90,4 +90,4 @@ __all__ = ('LinkerTC', 'LinkerTC2') if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_lookup.py b/test/unittest_lookup.py index b3c81507..11b4383b 100644 --- a/test/unittest_lookup.py +++ b/test/unittest_lookup.py @@ -20,22 +20,28 @@ import sys from os.path import join, abspath, dirname from functools import partial - -from logilab.common.testlib import TestCase, unittest_main, require_version +import unittest from astroid import builder, nodes, scoped_nodes, \ InferenceError, NotFoundError, UnresolvableName from astroid.scoped_nodes import builtin_lookup, Function from astroid.bases import YES from unittest_inference import get_name_node +from astroid.test_utils import require_version builder = builder.AstroidBuilder() -DATA = join(dirname(abspath(__file__)), 'data') +PY3K = sys.version_info >= (3, 0) + +if PY3K: + DATA = join(dirname(abspath(__file__)), 'data_py3') +else: + 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): +class LookupTC(unittest.TestCase): def test_limit(self): code = ''' @@ -358,4 +364,4 @@ def run1(): self.assertEqual(len(stmts), 0) if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_manager.py b/test/unittest_manager.py index 6b3c4895..4e0abcdf 100644 --- a/test/unittest_manager.py +++ b/test/unittest_manager.py @@ -15,19 +15,23 @@ # # You should have received a copy of the GNU Lesser General Public License along # with astroid. If not, see <http://www.gnu.org/licenses/>. -from logilab.common.testlib import TestCase, unittest_main +import unittest import sys from os.path import join, abspath, dirname from astroid.manager import AstroidManager, _silent_no_wrap from astroid.bases import BUILTINS from astroid.exceptions import AstroidBuildingException -from astroid.raw_building import astroid_bootstrapping -DATA = join(dirname(abspath(__file__)), 'data') -PY3K = sys.version_info > (3, 0) +PY3K = sys.version_info >= (3, 0) -class AstroidManagerTC(TestCase): +if PY3K: + DATA = join(dirname(abspath(__file__)), 'data_py3') +else: + DATA = join(dirname(abspath(__file__)), 'data') + + +class AstroidManagerTC(unittest.TestCase): def setUp(self): self.manager = AstroidManager() self.manager.clear_cache() # take care of borg @@ -111,7 +115,7 @@ class AstroidManagerTC(TestCase): def test_zip_import_data(self): """check if zip_import_data works""" - filepath = self.datapath('MyPyPa-0.1.0-py2.5.zip/mypypa') + filepath = join(DATA, 'MyPyPa-0.1.0-py2.5.zip/mypypa') astroid = self.manager.zip_import_data(filepath) self.assertEqual(astroid.name, 'mypypa') @@ -180,12 +184,15 @@ class AstroidManagerTC(TestCase): def test_project_node(self): obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data') - expected = set(['SSL1', '__init__', 'all', 'appl', 'format', 'module', - 'module2', 'noendingnewline', 'nonregr', 'notall']) expected = [ - 'data', 'data.SSL1', 'data.SSL1.Connection1', - 'data.absimport', 'data.all', - 'data.appl', 'data.appl.myConnection', 'data.email', + 'data', + 'data.SSL1', + 'data.SSL1.Connection1', + 'data.absimport', + 'data.all', + 'data.appl', + 'data.appl.myConnection', + 'data.email', 'data.find_test', 'data.find_test.module', 'data.find_test.module2', @@ -195,12 +202,17 @@ class AstroidManagerTC(TestCase): 'data.lmfp', 'data.lmfp.foo', 'data.module', - 'data.module1abs', 'data.module1abs.core', - 'data.module2', 'data.noendingnewline', - 'data.nonregr', 'data.notall'] + 'data.module1abs', + 'data.module1abs.core', + 'data.module2', + 'data.noendingnewline', + 'data.nonregr', + 'data.notall'] + if PY3K: + expected = [e.replace('data', 'data_py3') for e in expected] self.assertListEqual(sorted(k for k in obj.keys()), expected) -class BorgAstroidManagerTC(TestCase): +class BorgAstroidManagerTC(unittest.TestCase): def test_borg(self): """test that the AstroidManager is really a borg, i.e. that two different @@ -214,6 +226,6 @@ class BorgAstroidManagerTC(TestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_modutils.py b/test/unittest_modutils.py index 7846c50f..98955c55 100644 --- a/test/unittest_modutils.py +++ b/test/unittest_modutils.py @@ -20,13 +20,13 @@ unit tests for module modutils (module manipulation utilities) """ import sys +import unittest + try: __file__ except NameError: __file__ = sys.argv[0] -from logilab.common.testlib import TestCase, unittest_main - from os import path, getcwd, sep from astroid import modutils @@ -34,7 +34,7 @@ sys.path.insert(0, path.dirname(__file__)) DATADIR = path.abspath(path.normpath(path.join(path.dirname(__file__), 'data'))) -class ModuleFileTC(TestCase): +class ModuleFileTC(unittest.TestCase): package = "mypypa" def tearDown(self): @@ -54,7 +54,7 @@ class ModuleFileTC(TestCase): self.assertEqual(mfile.split(sep)[-4:], ["test", "data", "MyPyPa-0.1.0-py2.5.egg", self.package]) -class load_module_from_name_tc(TestCase): +class load_module_from_name_tc(unittest.TestCase): """ load a python module from it's name """ def test_knownValues_load_module_from_name_1(self): @@ -68,7 +68,7 @@ class load_module_from_name_tc(TestCase): modutils.load_module_from_name, 'os.path', use_sys=0) -class get_module_part_tc(TestCase): +class get_module_part_tc(unittest.TestCase): """given a dotted name return the module part of the name""" def test_knownValues_get_module_part_1(self): @@ -97,7 +97,7 @@ class get_module_part_tc(TestCase): modutils.__file__) -class modpath_from_file_tc(TestCase): +class modpath_from_file_tc(unittest.TestCase): """ given an absolute file path return the python module's path as a list """ def test_knownValues_modpath_from_file_1(self): @@ -113,10 +113,10 @@ class modpath_from_file_tc(TestCase): self.assertRaises(Exception, modutils.modpath_from_file, '/turlututu') -class load_module_from_path_tc(TestCase): +class load_module_from_path_tc(unittest.TestCase): def test_do_not_load_twice(self): - sys.path.insert(0, self.datadir) + sys.path.insert(0, DATADIR) foo = modutils.load_module_from_modpath(['lmfp', 'foo']) lmfp = modutils.load_module_from_modpath(['lmfp']) self.assertEqual(len(sys.just_once), 1) @@ -124,7 +124,7 @@ class load_module_from_path_tc(TestCase): del sys.just_once -class file_from_modpath_tc(TestCase): +class file_from_modpath_tc(unittest.TestCase): """given a mod path (i.e. splited module / package name), return the corresponding file, giving priority to source file over precompiled file if it exists""" @@ -166,7 +166,7 @@ class file_from_modpath_tc(TestCase): modutils.file_from_modpath(["unicode_package", "core"]) -class get_source_file_tc(TestCase): +class get_source_file_tc(unittest.TestCase): def test(self): from os import path @@ -177,7 +177,7 @@ class get_source_file_tc(TestCase): self.assertRaises(modutils.NoSourceFile, modutils.get_source_file, 'whatever') -class is_standard_module_tc(TestCase): +class is_standard_module_tc(unittest.TestCase): """ return true if the module may be considered as a module from the standard library @@ -234,7 +234,7 @@ class is_standard_module_tc(TestCase): self.assertEqual(modutils.is_standard_module('logilab.whatever', common.__path__), False) -class is_relative_tc(TestCase): +class is_relative_tc(unittest.TestCase): def test_knownValues_is_relative_1(self): @@ -253,7 +253,7 @@ class is_relative_tc(TestCase): False) -class get_module_files_tc(TestCase): +class get_module_files_tc(unittest.TestCase): def test_knownValues_get_module_files_1(self): # XXXFIXME: TOWRITE """given a directory return a list of all available python module's files, even @@ -276,14 +276,5 @@ class get_module_files_tc(TestCase): self.assertTrue( m is logilab.common.fileutils ) -from logilab.common.testlib import DocTest - -class ModuleDocTest(DocTest): - """test doc test in this module""" - from astroid import modutils as module - -del DocTest # necessary if we don't want it to be executed (we don't...) - - if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py index b17004e0..e9c688cc 100644 --- a/test/unittest_nodes.py +++ b/test/unittest_nodes.py @@ -17,23 +17,28 @@ # with astroid. If not, see <http://www.gnu.org/licenses/>. """tests for specific behaviour of astroid nodes """ +from os.path import join, abspath, dirname import sys +import unittest -from logilab.common import testlib from astroid.node_classes import unpack_infer from astroid.bases import BUILTINS, YES, InferenceContext from astroid.exceptions import AstroidBuildingException, NotFoundError from astroid import builder, nodes +from astroid.test_utils import require_version -from data import module as test_module - -from os.path import join, abspath, dirname +PY3K = sys.version_info >= (3, 0) -DATA = join(dirname(abspath(__file__)), 'data') +if PY3K: + from data_py3 import module as test_module + DATA = join(dirname(abspath(__file__)), 'data_py3') +else: + from data import module as test_module + DATA = join(dirname(abspath(__file__)), 'data') abuilder = builder.AstroidBuilder() -class AsString(testlib.TestCase): +class AsString(unittest.TestCase): def test_tuple_as_string(self): def build(string): @@ -60,7 +65,7 @@ class AsString(testlib.TestCase): data = open(join(DATA, 'module2.py')).read() self.assertMultiLineEqual(MODULE2.as_string(), data) - @testlib.require_version('2.7') + @require_version('2.7') def test_2_7_as_string(self): """check as_string for python syntax >= 2.7""" code = '''one_two = {1, 2} @@ -69,7 +74,7 @@ cdd = {k for k in b}\n\n''' ast = abuilder.string_build(code) self.assertMultiLineEqual(ast.as_string(), code) - @testlib.require_version('3.0') + @require_version('3.0') def test_3k_as_string(self): """check as_string for python 3k syntax""" code = '''print() @@ -94,7 +99,7 @@ class Language(metaclass=Natural): self.assertEqual(ast.as_string(), code) -class _NodeTC(testlib.TestCase): +class _NodeTC(unittest.TestCase): """test transformation of If Node""" CODE = None @property @@ -228,7 +233,7 @@ MODULE = abuilder.module_build(test_module) MODULE2 = abuilder.file_build(join(DATA, 'module2.py'), 'data.module2') -class ImportNodeTC(testlib.TestCase): +class ImportNodeTC(unittest.TestCase): def test_import_self_resolve(self): myos = next(MODULE2.igetattr('myos')) @@ -306,29 +311,29 @@ except PickleError: excs = list(unpack_infer(handler_type)) def test_absolute_import(self): - astroid = abuilder.file_build(self.datapath('absimport.py')) + astroid = abuilder.file_build(join(DATA, 'absimport.py')) ctx = InferenceContext() # will fail if absolute import failed next(astroid['message'].infer(ctx, lookupname='message')) m = next(astroid['email'].infer(ctx, lookupname='email')) - self.assertFalse(m.file.startswith(self.datapath('email.py'))) + self.assertFalse(m.file.startswith(join(DATA, 'email.py'))) def test_more_absolute_import(self): - sys.path.insert(0, self.datapath('moreabsimport')) + sys.path.insert(0, join(DATA, 'moreabsimport')) try: - astroid = abuilder.file_build(self.datapath('module1abs/__init__.py')) + astroid = abuilder.file_build(join(DATA, 'module1abs/__init__.py')) self.assertIn('sys', astroid.locals) finally: sys.path.pop(0) -class CmpNodeTC(testlib.TestCase): +class CmpNodeTC(unittest.TestCase): def test_as_string(self): ast = abuilder.string_build("a == 2").body[0] self.assertEqual(ast.as_string(), "a == 2") -class ConstNodeTC(testlib.TestCase): +class ConstNodeTC(unittest.TestCase): def _test(self, value): node = nodes.const_factory(value) @@ -360,7 +365,7 @@ class ConstNodeTC(testlib.TestCase): self._test(u'a') -class NameNodeTC(testlib.TestCase): +class NameNodeTC(unittest.TestCase): def test_assign_to_True(self): """test that True and False assignements don't crash""" code = """True = False @@ -381,7 +386,7 @@ del True self.assertEqual(del_true.name, "True") -class ArgumentsNodeTC(testlib.TestCase): +class ArgumentsNodeTC(unittest.TestCase): def test_linenumbering(self): ast = abuilder.string_build(''' def func(a, @@ -401,7 +406,7 @@ x = lambda x: None '(no line number on function args)') -class SliceNodeTC(testlib.TestCase): +class SliceNodeTC(unittest.TestCase): def test(self): for code in ('a[0]', 'a[1:3]', 'a[:-1:step]', 'a[:,newaxis]', 'a[newaxis,:]', 'del L[::2]', 'del A[1]', 'del Br[:]'): @@ -427,10 +432,10 @@ if all[1] == bord[0:]: ast = abuilder.string_build(code) self.assertEqual(ast.as_string(), code) -class EllipsisNodeTC(testlib.TestCase): +class EllipsisNodeTC(unittest.TestCase): def test(self): ast = abuilder.string_build('a[...]').body[0] self.assertEqual(ast.as_string(), 'a[...]') if __name__ == '__main__': - testlib.unittest_main() + unittest.main() diff --git a/test/unittest_python3.py b/test/unittest_python3.py index 57cea49a..e1502937 100644 --- a/test/unittest_python3.py +++ b/test/unittest_python3.py @@ -15,18 +15,17 @@ # # You should have received a copy of the GNU Lesser General Public License along # with astroid. If not, see <http://www.gnu.org/licenses/>. - from textwrap import dedent - -from logilab.common.testlib import TestCase, unittest_main, require_version +import unittest from astroid.node_classes import Assign, Discard, YieldFrom, Name, Const from astroid.manager import AstroidManager from astroid.builder import AstroidBuilder from astroid.scoped_nodes import Class, Function +from astroid.test_utils import require_version -class Python3TC(TestCase): +class Python3TC(unittest.TestCase): def setUp(self): self.manager = AstroidManager() self.manager.clear_cache() # take care of borg @@ -218,4 +217,4 @@ class Python3TC(TestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_raw_building.py b/test/unittest_raw_building.py index 414d8bed..17057d55 100644 --- a/test/unittest_raw_building.py +++ b/test/unittest_raw_building.py @@ -1,7 +1,8 @@ -from logilab.common.testlib import TestCase, unittest_main +import unittest + from astroid.raw_building import (attach_dummy_node, build_module, build_class, build_function, build_from_import) -class RawBuildingTC(TestCase): +class RawBuildingTC(unittest.TestCase): def test_attach_dummy_node(self): node = build_module('MyModule') @@ -40,4 +41,8 @@ class RawBuildingTC(TestCase): def test_build_from_import(self): names = ['exceptions, inference, inspector'] node = build_from_import('astroid', names) - self.assertEqual(len(names), len(node.names))
\ No newline at end of file + self.assertEqual(len(names), len(node.names)) + + +if __name__ == '__main__': + unittest.main() diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py index c04ff14a..f40991ff 100644 --- a/test/unittest_regrtest.py +++ b/test/unittest_regrtest.py @@ -15,18 +15,18 @@ # # You should have received a copy of the GNU Lesser General Public License along # with astroid. If not, see <http://www.gnu.org/licenses/>. - -from logilab.common.testlib import unittest_main, TestCase, require_version +from os.path import join, abspath, dirname +import sys +import unittest from astroid import ResolveError, MANAGER, Instance, nodes, YES, InferenceError from astroid.builder import AstroidBuilder from astroid.raw_building import build_module from astroid.manager import AstroidManager +from astroid.test_utils import require_version -import sys -from os.path import join, abspath, dirname -class NonRegressionTC(TestCase): +class NonRegressionTC(unittest.TestCase): def setUp(self): sys.path.insert(0, join(dirname(abspath(__file__)), 'regrtest_data')) @@ -221,4 +221,4 @@ class Whatever(object): a = property(lambda x: x, lambda x: x) if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_scoped_nodes.py b/test/unittest_scoped_nodes.py index 4ebebd26..965def77 100644 --- a/test/unittest_scoped_nodes.py +++ b/test/unittest_scoped_nodes.py @@ -18,30 +18,31 @@ """tests for specific behaviour of astroid scoped nodes (i.e. module, class and function) """ - -from __future__ import with_statement - import sys from os.path import join, abspath, dirname from functools import partial from textwrap import dedent - -from logilab.common.testlib import TestCase, unittest_main, require_version +import unittest from astroid import YES, builder, nodes, scoped_nodes, \ InferenceError, NotFoundError, NoDefault from astroid.bases import BUILTINS, Instance, BoundMethod, UnboundMethod -from astroid.test_utils import extract_node +from astroid.test_utils import extract_node, require_version abuilder = builder.AstroidBuilder() -DATA = join(dirname(abspath(__file__)), 'data') +PY3K = sys.version_info >= (3, 0) + +if PY3K: + DATA = join(dirname(abspath(__file__)), 'data_py3') +else: + DATA = join(dirname(abspath(__file__)), 'data') + REGRTEST_DATA = join(dirname(abspath(__file__)), 'regrtest_data') MODULE = abuilder.file_build(join(DATA, 'module.py'), 'data.module') MODULE2 = abuilder.file_build(join(DATA, 'module2.py'), 'data.module2') NONREGR = abuilder.file_build(join(DATA, 'nonregr.py'), 'data.nonregr') PACK = abuilder.file_build(join(DATA, '__init__.py'), 'data') -PY3K = sys.version_info >= (3, 0) def _test_dict_interface(self, node, test_attr): self.assertIs(node[test_attr], node[test_attr]) @@ -52,7 +53,7 @@ def _test_dict_interface(self, node, test_attr): iter(node) -class ModuleNodeTC(TestCase): +class ModuleNodeTC(unittest.TestCase): def test_special_attributes(self): self.assertEqual(len(MODULE.getattr('__name__')), 1) @@ -196,7 +197,7 @@ del appli self.assertEqual(astroid.file_stream.read(), file_io.read()) -class FunctionNodeTC(TestCase): +class FunctionNodeTC(unittest.TestCase): def test_special_attributes(self): func = MODULE2['make_class'] @@ -469,7 +470,7 @@ test() 'method') -class ClassNodeTC(TestCase): +class ClassNodeTC(unittest.TestCase): def test_dict_interface(self): _test_dict_interface(self, MODULE['YOUPI'], 'method') @@ -1001,4 +1002,4 @@ def g2(): __all__ = ('ModuleNodeTC', 'ImportNodeTC', 'FunctionNodeTC', 'ClassNodeTC') if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_utils.py b/test/unittest_utils.py index fddbc5a0..999f7ed1 100644 --- a/test/unittest_utils.py +++ b/test/unittest_utils.py @@ -15,14 +15,14 @@ # # You should have received a copy of the GNU Lesser General Public License along # with astroid. If not, see <http://www.gnu.org/licenses/>. -from logilab.common.testlib import TestCase, unittest_main +import unittest from astroid import builder, nodes from astroid.node_classes import are_exclusive builder = builder.AstroidBuilder() -class AreExclusiveTC(TestCase): +class AreExclusiveTC(unittest.TestCase): def test_not_exclusive(self): astroid = builder.string_build(""" x = 10 @@ -98,5 +98,5 @@ else: self.assertEqual(are_exclusive(f4, f2), True) if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test_utils.py b/test_utils.py index f9f4d53f..7ae9361e 100644 --- a/test_utils.py +++ b/test_utils.py @@ -1,4 +1,6 @@ """Utility functions for test code that uses astroid ASTs as input.""" +import functools +import sys import textwrap from astroid import nodes @@ -180,3 +182,32 @@ def build_module(code, module_name=''): """ code = textwrap.dedent(code) return builder.AstroidBuilder(None).string_build(code, modname=module_name) + + +def require_version(minver=None, maxver=None): + """ Compare version of python interpreter to the given one. Skip the test + if older. + """ + def parse(string, default=None): + string = string or default + try: + return tuple(int(v) for v in string.split('.')) + except ValueError: + raise ValueError('%s is not a correct version : should be X.Y[.Z].' % version) + + def check_require_version(f): + current = sys.version_info[:3] + if parse(minver, "0") < current <= parse(maxver, "4"): + return f + else: + str_version = '.'.join(str(v) for v in sys.version_info) + @functools.wraps(f) + def new_f(self, *args, **kwargs): + if minver is not None: + self.skipTest('Needs Python > %s. Current version is %s.' % (minver, str_version)) + elif maxver is not None: + self.skipTest('Needs Python <= %s. Current version is %s.' % (maxver, str_version)) + return new_f + + + return check_require_version |