summaryrefslogtreecommitdiff
path: root/test/unittest_pyreverse_writer.py
blob: 3ccc231f6af1b9360a82c0e4cb93ad782621a677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright (c) 2000-2008 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU 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.
"""
unittest for visitors.diadefs and extensions.diadefslib modules
"""

from os.path import abspath, dirname, join
from logilab.astng.inspector import Linker
from logilab.common.testlib import TestCase, unittest_main

from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler
from pylint.pyreverse.diagrams import set_counter
from pylint.pyreverse.writer import DotWriter

from pylint.pyreverse.utils import get_visibility
from utils import FileTC, build_file_case, get_project, Config

project = get_project(join(dirname(abspath(__file__)), 'data'))
linker = Linker(project)
set_counter(0)

config = Config()

handler = DiadefsHandler(config)
dd = DefaultDiadefGenerator(linker, handler).visit(project)
for diagram in dd:
    diagram.extract_relationships()

class DotWriterTC(FileTC):

    generated_files = ('packages_No_Name.dot', 'classes_No_Name.dot',)
    def setUp(self):
        FileTC.setUp(self)
        writer = DotWriter(config)
        writer.write(dd)
        
build_file_case(DotWriterTC)


class GetVisibilityTC(TestCase):

    def test_special(self):
        for name in ["__reduce_ex__",  "__setattr__"]:
            self.assertEqual(get_visibility(name), 'special')

    def test_private(self):
        for name in ["__g_", "____dsf", "__23_9"]:
            got = get_visibility(name)
            self.assertEqual(got, 'private',
                              'got %s instead of private for value %s' % (got, name))

    def test_public(self):
        self.assertEqual(get_visibility('simple'), 'public')

    def test_protected(self):
        for name in ["_","__", "___", "____", "_____", "___e__", "_nextsimple", "_filter_it_"]:
            got = get_visibility(name)
            self.assertEqual(got, 'protected',
                              'got %s instead of protected for value %s' % (got, name))


if __name__ == '__main__':
    unittest_main()