blob: dd6446ead28f6b67543216f0a06f0db703f20bca (
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
|
import sys
import os
import unittest
from os.path import exists
from cStringIO import StringIO
from pylint.checkers import initialize, imports
from pylint.lint import PyLinter
from utils import TestReporter
class DependenciesGraphTC(unittest.TestCase):
"""test the imports graph function"""
dest = 'dependencies_graph.dot'
def tearDown(self):
os.remove(self.dest)
def test_dependencies_graph(self):
imports.dependencies_graph(self.dest, {'labas': ['hoho', 'yep'],
'hoho': ['yep']})
self.assertEquals(open(self.dest).read().strip(),
'''
digraph g {
rankdir="LR" URL="." concentrate=false
edge[fontsize="10" ]
node[width="0" height="0" fontsize="12" fontcolor="black"]
"hoho" [ label="hoho" ];
"yep" [ label="yep" ];
"labas" [ label="labas" ];
"yep" -> "hoho" [ ] ;
"hoho" -> "labas" [ ] ;
"yep" -> "labas" [ ] ;
}
'''.strip())
class ImportCheckerTC(unittest.TestCase):
def setUp(self):
self.linter = l = PyLinter(reporter=TestReporter())
initialize(l)
l.disable_all_checkers()
def test_checker_dep_graphs(self):
l = self.linter
l.global_set_option('persistent', False)
l.global_set_option('enable-imports', True)
l.global_set_option('import-graph', 'import.dot')
l.global_set_option('ext-import-graph', 'ext_import.dot')
l.global_set_option('int-import-graph', 'int_import.dot')
try:
l.check('input')
self.assert_(exists('import.dot'))
self.assert_(exists('ext_import.dot'))
self.assert_(exists('int_import.dot'))
finally:
for fname in ('import.dot', 'ext_import.dot', 'int_import.dot'):
try:
os.remove(fname)
except:
pass
if __name__ == '__main__':
unittest.main()
|