gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / test_import_graph.py @ 745
History | View | Annotate | Download (2.03 KB)
1 |
import sys |
---|---|
2 |
import os |
3 |
from os.path import exists |
4 |
import unittest |
5 |
|
6 |
import six |
7 |
|
8 |
from pylint.checkers import initialize, imports |
9 |
from pylint.lint import PyLinter |
10 |
|
11 |
from pylint.testutils import TestReporter |
12 |
|
13 |
class DependenciesGraphTC(unittest.TestCase): |
14 |
"""test the imports graph function"""
|
15 |
|
16 |
dest = 'dependencies_graph.dot'
|
17 |
def tearDown(self): |
18 |
os.remove(self.dest)
|
19 |
|
20 |
def test_dependencies_graph(self): |
21 |
imports._dependencies_graph(self.dest, {'labas': ['hoho', 'yep'], |
22 |
'hoho': ['yep']}) |
23 |
with open(self.dest) as stream: |
24 |
self.assertEqual(stream.read().strip(),
|
25 |
'''
|
26 |
digraph "dependencies_graph" {
|
27 |
rankdir=LR
|
28 |
charset="utf-8"
|
29 |
URL="." node[shape="box"]
|
30 |
"hoho" [];
|
31 |
"yep" [];
|
32 |
"labas" [];
|
33 |
"yep" -> "hoho" [];
|
34 |
"hoho" -> "labas" [];
|
35 |
"yep" -> "labas" [];
|
36 |
}
|
37 |
'''.strip())
|
38 |
|
39 |
class ImportCheckerTC(unittest.TestCase): |
40 |
def setUp(self): |
41 |
self.linter = l = PyLinter(reporter=TestReporter())
|
42 |
initialize(l) |
43 |
|
44 |
def test_checker_dep_graphs(self): |
45 |
l = self.linter
|
46 |
l.global_set_option('persistent', False) |
47 |
l.global_set_option('enable', 'imports') |
48 |
l.global_set_option('import-graph', 'import.dot') |
49 |
l.global_set_option('ext-import-graph', 'ext_import.dot') |
50 |
l.global_set_option('int-import-graph', 'int_import.dot') |
51 |
l.global_set_option('int-import-graph', 'int_import.dot') |
52 |
# ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
|
53 |
l.global_set_option('ignore', ('func_unknown_encoding.py',)) |
54 |
try:
|
55 |
l.check('input')
|
56 |
l.generate_reports() |
57 |
self.assertTrue(exists('import.dot')) |
58 |
self.assertTrue(exists('ext_import.dot')) |
59 |
self.assertTrue(exists('int_import.dot')) |
60 |
finally:
|
61 |
for fname in ('import.dot', 'ext_import.dot', 'int_import.dot'): |
62 |
try:
|
63 |
os.remove(fname) |
64 |
except:
|
65 |
pass
|
66 |
|
67 |
if __name__ == '__main__': |
68 |
unittest.main() |