summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thénault <sylvain.thenault@logilab.fr>2009-11-25 10:05:17 +0100
committerSylvain Thénault <sylvain.thenault@logilab.fr>2009-11-25 10:05:17 +0100
commite7f00c2389e5567bf04f141a33e8afb2174e7324 (patch)
treef56caa1c459fe866f4b31c57a8fee08d63846bc7
parent75c593a39d0a249ff64aad564857688b2bc5c4cc (diff)
downloadastroid-git-e7f00c2389e5567bf04f141a33e8afb2174e7324.tar.gz
d-t-w
-rw-r--r--test/unittest_scoped_nodes.py50
1 files changed, 25 insertions, 25 deletions
diff --git a/test/unittest_scoped_nodes.py b/test/unittest_scoped_nodes.py
index cda04423..196954fe 100644
--- a/test/unittest_scoped_nodes.py
+++ b/test/unittest_scoped_nodes.py
@@ -12,7 +12,7 @@ from logilab.astng import builder, nodes, scoped_nodes, \
InferenceError, NotFoundError
from logilab.astng.infutils import Instance
-abuilder = builder.ASTNGBuilder()
+abuilder = builder.ASTNGBuilder()
MODULE = abuilder.file_build('data/module.py', 'data.module')
MODULE2 = abuilder.file_build('data/module2.py', 'data.module2')
NONREGR = abuilder.file_build('data/nonregr.py', 'data.nonregr')
@@ -28,7 +28,7 @@ def _test_dict_interface(self, node, test_attr):
class ModuleNodeTC(TestCase):
-
+
def test_special_attributes(self):
self.assertEquals(len(MODULE.getattr('__name__')), 1)
self.assertIsInstance(MODULE.getattr('__name__')[0], nodes.Const)
@@ -47,7 +47,7 @@ class ModuleNodeTC(TestCase):
def test_dict_interface(self):
_test_dict_interface(self, MODULE, 'YO')
-
+
def test_getattr(self):
yo = MODULE.getattr('YO')[0]
self.assertIsInstance(yo, nodes.Class)
@@ -71,7 +71,7 @@ class ModuleNodeTC(TestCase):
self.assertEquals(len(NONREGR.getattr('enumerate')), 2)
# raise ResolveError
self.assertRaises(InferenceError, MODULE.igetattr, 'YOAA')
-
+
def test_wildard_import_names(self):
m = abuilder.file_build('data/all.py', 'all')
self.assertEquals(m.wildcard_import_names(), ['Aaa', '_bla', 'name'])
@@ -79,7 +79,7 @@ class ModuleNodeTC(TestCase):
res = m.wildcard_import_names()
res.sort()
self.assertEquals(res, ['Aaa', 'func', 'name', 'other'])
-
+
def test_module_getattr(self):
data = '''
appli = application
@@ -93,7 +93,7 @@ del appli
class FunctionNodeTC(TestCase):
-
+
def test_special_attributes(self):
func = MODULE2['make_class']
self.assertEquals(len(func.getattr('__name__')), 1)
@@ -107,7 +107,7 @@ class FunctionNodeTC(TestCase):
def test_dict_interface(self):
_test_dict_interface(self, MODULE['global_access'], 'local')
-
+
def test_default_value(self):
func = MODULE2['make_class']
self.assertIsInstance(func.args.default_value('base'), nodes.Getattr)
@@ -143,7 +143,7 @@ class FunctionNodeTC(TestCase):
local.sort()
self.assertEquals(local, ['a', 'b', 'c', 'd'])
self.assertEquals(func.type, 'function')
-
+
def test_format_args(self):
func = MODULE2['make_class']
self.assertEquals(func.args.format_args(), 'any, base=data.module.YO, *args, **kwargs')
@@ -160,15 +160,15 @@ class FunctionNodeTC(TestCase):
# non regression : test raise "string" doesn't cause an exception in is_abstract
func = MODULE2['raise_string']
self.assert_(not func.is_abstract(pass_is_abstract=False))
-
+
## def test_raises(self):
## method = MODULE2['AbstractClass']['to_override']
## self.assertEquals([str(term) for term in method.raises()],
## ["CallFunc(Name('NotImplementedError'), [], None, None)"] )
-
+
## def test_returns(self):
## method = MODULE2['AbstractClass']['return_something']
-## # use string comp since Node doesn't handle __cmp__
+## # use string comp since Node doesn't handle __cmp__
## self.assertEquals([str(term) for term in method.returns()],
## ["Const('toto')", "Const(None)"])
@@ -194,7 +194,7 @@ class A:
@staticmethod
def meth3():
return 3
-
+
def function():
return 0
@@ -214,7 +214,7 @@ def sfunction():
astng = abuilder.string_build(code, __name__, __file__)
self.assertEquals(astng['f'].argnames(), ['a', 'b', 'c', 'args', 'kwargs'])
-
+
class ClassNodeTC(TestCase):
def test_dict_interface(self):
@@ -242,7 +242,7 @@ class ClassNodeTC(TestCase):
self.assertEquals(len(cls.getattr('__module__')), 1)
self.assertEquals(len(cls.getattr('__dict__')), 1)
self.assertEquals(len(cls.getattr('__mro__')), 1)
-
+
def test_cls_special_attributes_2(self):
astng = abuilder.string_build('''
class A: pass
@@ -255,13 +255,13 @@ A.__bases__ += (B,)
self.assertIsInstance(astng['A'].getattr('__bases__')[1], nodes.AssAttr)
def test_instance_special_attributes(self):
- for inst in (Instance(MODULE['YO']), nodes.List(), nodes.Const(1)):
+ for inst in (Instance(MODULE['YO']), nodes.List(), nodes.Const(1)):
self.assertRaises(NotFoundError, inst.getattr, '__mro__')
self.assertRaises(NotFoundError, inst.getattr, '__bases__')
self.assertRaises(NotFoundError, inst.getattr, '__name__')
self.assertEquals(len(inst.getattr('__dict__')), 1)
self.assertEquals(len(inst.getattr('__doc__')), 1)
-
+
def test_navigation(self):
klass = MODULE['YO']
self.assertEquals(klass.statement(), klass)
@@ -292,7 +292,7 @@ A.__bases__ += (B,)
klass2 = MODULE['YOUPI']
it = klass2.instance_attr_ancestors('member')
self.assertRaises(StopIteration, it.next)
-
+
def test_methods(self):
klass2 = MODULE['YOUPI']
methods = [m.name for m in klass2.methods()]
@@ -315,7 +315,7 @@ A.__bases__ += (B,)
methods.sort()
self.assertEquals(methods, ['__init__', 'class_method',
'method', 'static_method'])
-
+
#def test_rhs(self):
# my_dict = MODULE['MY_DICT']
# self.assertIsInstance(my_dict.rhs(), nodes.Dict)
@@ -323,7 +323,7 @@ A.__bases__ += (B,)
# value = a.rhs()
# self.assertIsInstance(value, nodes.Const)
# self.assertEquals(value.value, 1)
-
+
def test_ancestors(self):
klass = MODULE['YOUPI']
ancs = [a.name for a in klass.ancestors()]
@@ -352,7 +352,7 @@ A.__bases__ += (B,)
klass = MODULE2[klass]
self.assertEquals([i.name for i in klass.interfaces()],
interfaces)
-
+
def test_concat_interfaces(self):
astng = abuilder.string_build('''
class IMachin: pass
@@ -360,7 +360,7 @@ class IMachin: pass
class Correct2:
"""docstring"""
__implements__ = (IMachin,)
-
+
class BadArgument:
"""docstring"""
__implements__ = (IMachin,)
@@ -372,7 +372,7 @@ class InterfaceCanNowBeFound:
''')
self.assertEquals([i.name for i in astng['InterfaceCanNowBeFound'].interfaces()],
['IMachin'])
-
+
def test_inner_classes(self):
eee = NONREGR['Ccc']['Eee']
self.assertEquals([n.name for n in eee.ancestors()], ['Ddd', 'Aaa', 'object'])
@@ -392,7 +392,7 @@ class WebAppObject(object):
cls = astng['WebAppObject']
self.assertEquals(sorted(cls.locals.keys()),
['appli', 'config', 'registered', 'schema'])
-
+
def test_class_getattr(self):
data = '''
@@ -405,7 +405,7 @@ class WebAppObject(object):
cls = astng['WebAppObject']
# test del statement not returned by getattr
self.assertEquals(len(cls.getattr('appli')), 2)
-
+
def test_instance_getattr(self):
data = '''
@@ -446,6 +446,6 @@ class Klass(Parent):
self.assertEquals(len(inst.getattr('cc')), 2, inst.getattr('cc'))
__all__ = ('ModuleNodeTC', 'ImportNodeTC', 'FunctionNodeTC', 'ClassNodeTC')
-
+
if __name__ == '__main__':
unittest_main()