summaryrefslogtreecommitdiff
path: root/test/unittest_regrtest.py
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-10-12 18:14:56 +0200
committerEmile Anclin <emile.anclin@logilab.fr>2010-10-12 18:14:56 +0200
commit7d157e1d185409d8468d9261f13f506e4165e061 (patch)
treedb8281ea6a531635ef29156968f2b52b11b238ee /test/unittest_regrtest.py
parent2ff443fbdacafb6cdee9b3acee943a447533ea35 (diff)
downloadastroid-7d157e1d185409d8468d9261f13f506e4165e061.tar.gz
rename regrtest.py to make sure the tests are tested (and they don't work...)
Diffstat (limited to 'test/unittest_regrtest.py')
-rw-r--r--test/unittest_regrtest.py116
1 files changed, 116 insertions, 0 deletions
diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py
new file mode 100644
index 0000000..f6a9f59
--- /dev/null
+++ b/test/unittest_regrtest.py
@@ -0,0 +1,116 @@
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+# copyright 2003-2010 Sylvain Thenault, all rights reserved.
+# contact mailto:thenault@gmail.com
+#
+# This file is part of logilab-astng.
+#
+# logilab-astng is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by the
+# Free Software Foundation, either version 2.1 of the License, or (at your
+# option) any later version.
+#
+# logilab-astng is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+# for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+
+from logilab.common.testlib import unittest_main, TestCase
+
+from logilab.astng import ResolveError, MANAGER, Instance, YES, InferenceError
+from logilab.astng.builder import ASTNGBuilder, build_module
+
+import sys
+from os.path import abspath
+sys.path.insert(1, abspath('regrtest_data'))
+
+class NonRegressionTC(TestCase):
+
+
+ def test_module_path(self):
+ mod = MANAGER.astng_from_module_name('import_package_subpackage_module')
+ package = mod.igetattr('package').next()
+ self.failUnlessEqual(package.name, 'package')
+ subpackage = package.igetattr('subpackage').next()
+ self.failUnlessEqual(subpackage.name, 'package.subpackage')
+ module = subpackage.igetattr('module').next()
+ self.failUnlessEqual(module.name, 'package.subpackage.module')
+
+
+ def test_living_property(self):
+ builder = ASTNGBuilder()
+ builder._done = {}
+ builder._module = sys.modules[__name__]
+ builder.object_build(build_module('module_name', ''), Whatever)
+
+
+ def test_new_style_class_detection(self):
+ try:
+ import pygtk
+ except ImportError:
+ self.skipTest('test skipped: pygtk is not available')
+ # XXX may fail on some pygtk version, because objects in
+ # gobject._gobject have __module__ set to gobject :(
+ builder = ASTNGBuilder()
+ data = """
+import pygtk
+pygtk.require("2.6")
+import gobject
+
+class A(gobject.GObject):
+ pass
+"""
+ astng = builder.string_build(data, __name__, __file__)
+ a = astng['A']
+ self.failUnless(a.newstyle)
+
+
+ def test_pylint_config_attr(self):
+ try:
+ from pylint import lint
+ except ImportError:
+ self.skipTest('pylint not available')
+ mod = MANAGER.astng_from_module_name('pylint.lint')
+ pylinter = mod['PyLinter']
+ expect = ['OptionsManagerMixIn', 'object', 'MessagesHandlerMixIn',
+ 'ReportsHandlerMixIn', 'BaseRawChecker', 'BaseChecker',
+ 'OptionsProviderMixIn', 'ASTWalker']
+ self.assertListEqual([c.name for c in pylinter.ancestors()],
+ expect)
+ self.assert_(list(Instance(pylinter).getattr('config')))
+ infered = list(Instance(pylinter).igetattr('config'))
+ self.assertEqual(len(infered), 2)
+ infered = [c for c in infered if not c is YES]
+ self.assertEqual(len(infered), 1)
+ self.assertEqual(infered[0].root().name, 'optparse')
+ self.assertEqual(infered[0].name, 'Values')
+
+ def test_numpy_crash(self):
+ """test don't crash on numpy"""
+ #a crash occured somewhere in the past, and an
+ # InferenceError instead of a crash was better, but now we even infer!
+ try:
+ import numpy
+ except ImportError:
+ self.skipTest('test skipped: numpy is not available')
+ builder = ASTNGBuilder()
+ data = """
+from numpy import multiply
+
+multiply(1, 2, 3)
+"""
+ astng = builder.string_build(data, __name__, __file__)
+ callfunc = astng.body[1].value.func
+ infered = callfunc.infered()
+ self.assertEqual(len(infered), 1)
+ self.assertIsInstance(infered[0], Instance)
+
+
+class Whatever(object):
+ a = property(lambda x: x, lambda x: x)
+
+if __name__ == '__main__':
+ unittest_main()