root / logilab.pylintinstaller / logilab / astng / test / unittest_inspector.py

Revision 202:d67e86292521, 3.4 kB (checked in by tziade@…, 11 months ago)

added logilab.pylintinstaller

Line 
1# Copyright (c) 2003-2006 LOGILAB S.A. (Paris, FRANCE).
2# http://www.logilab.fr/ -- mailto:contact@logilab.fr
3#
4# This program is free software; you can redistribute it and/or modify it under
5# the terms of the GNU General Public License as published by the Free Software
6# Foundation; either version 2 of the License, or (at your option) any later
7# version.
8#
9# This program is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along with
14# this program; if not, write to the Free Software Foundation, Inc.,
15# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16"""
17unittest for the visitors.diadefs module
18"""
19
20import unittest
21import sys
22
23from logilab import astng
24from logilab.astng import ASTNGManager, nodes, inspector
25
26def astng_wrapper(func, modname):
27    return func(modname)
28
29       
30class LinkerTC(unittest.TestCase):
31   
32    def setUp(self):
33        self.project = ASTNGManager().project_from_files(['data2'], astng_wrapper) 
34        self.linker = inspector.Linker(self.project)
35        self.linker.visit(self.project)
36
37    def test_class_implements(self):
38        klass = self.project.get_module('data2.clientmodule_test')['Ancestor']
39        self.assert_(hasattr(klass, 'implements'))
40        self.assertEqual(len(klass.implements), 1)
41        self.assert_(isinstance(klass.implements[0], nodes.Class))
42        self.assertEqual(klass.implements[0].name, "Interface")
43        klass = self.project.get_module('data2.clientmodule_test')['Specialization']
44        self.assert_(hasattr(klass, 'implements'))
45        self.assertEqual(len(klass.implements), 0)
46       
47    def test_locals_assignment_resolution(self):
48        klass = self.project.get_module('data2.clientmodule_test')['Specialization']
49        self.assert_(hasattr(klass, 'locals_type'))
50        type_dict = klass.locals_type
51        self.assertEqual(len(type_dict), 2)
52        keys = type_dict.keys()
53        keys.sort()
54        self.assertEqual(keys, ['TYPE', 'top'])
55        self.assertEqual(len(type_dict['TYPE']), 1)
56        self.assertEqual(type_dict['TYPE'][0].value, 'final class')
57        self.assertEqual(len(type_dict['top']), 1)
58        self.assertEqual(type_dict['top'][0].value, 'class')
59       
60    def test_instance_attrs_resolution(self):
61        klass = self.project.get_module('data2.clientmodule_test')['Specialization']
62        self.assert_(hasattr(klass, 'instance_attrs_type'))
63        type_dict = klass.instance_attrs_type
64        self.assertEqual(len(type_dict), 3)
65        keys = type_dict.keys()
66        keys.sort()
67        self.assertEqual(keys, ['_id', 'relation', 'toto'])
68        self.assert_(isinstance(type_dict['relation'][0], astng.Instance), type_dict['relation'])
69        self.assertEqual(type_dict['relation'][0].name, 'DoNothing')
70        self.assert_(isinstance(type_dict['toto'][0], astng.Instance), type_dict['toto'])
71        self.assertEqual(type_dict['toto'][0].name, 'Toto')
72        self.assert_(type_dict['_id'][0] is astng.YES, type_dict['_id'])
73
74
75class LinkerTC2(LinkerTC):
76   
77    def setUp(self):
78        self.project = ASTNGManager().from_directory('data2') 
79        self.linker = inspector.Linker(self.project)
80        self.linker.visit(self.project)
81       
82__all__ = ('LinkerTC', 'LinkerTC2')
83
84       
85if __name__ == '__main__':
86    unittest.main()
Note: See TracBrowser for help on using the browser.