2006-04-26 10:48:09 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from os.path import exists
|
2014-07-26 15:11:14 +00:00
|
|
|
import unittest
|
2006-04-26 10:48:09 +00:00
|
|
|
|
2014-11-09 09:33:29 +00:00
|
|
|
import six
|
|
|
|
|
2006-04-26 10:48:09 +00:00
|
|
|
from pylint.checkers import initialize, imports
|
|
|
|
from pylint.lint import PyLinter
|
|
|
|
|
2012-07-04 11:12:18 +00:00
|
|
|
from pylint.testutils import TestReporter
|
2006-04-26 10:48:09 +00:00
|
|
|
|
2014-07-26 15:11:14 +00:00
|
|
|
class DependenciesGraphTC(unittest.TestCase):
|
2006-04-26 10:48:09 +00:00
|
|
|
"""test the imports graph function"""
|
|
|
|
|
|
|
|
dest = 'dependencies_graph.dot'
|
|
|
|
def tearDown(self):
|
|
|
|
os.remove(self.dest)
|
2010-04-19 09:22:40 +00:00
|
|
|
|
2006-04-26 10:48:09 +00:00
|
|
|
def test_dependencies_graph(self):
|
2015-12-01 08:33:33 +00:00
|
|
|
imports._dependencies_graph(self.dest, {'labas': ['hoho', 'yep'],
|
|
|
|
'hoho': ['yep']})
|
2014-09-30 16:33:58 +00:00
|
|
|
with open(self.dest) as stream:
|
|
|
|
self.assertEqual(stream.read().strip(),
|
2006-04-26 10:48:09 +00:00
|
|
|
'''
|
2008-09-10 08:19:26 +00:00
|
|
|
digraph "dependencies_graph" {
|
|
|
|
rankdir=LR
|
|
|
|
charset="utf-8"
|
2008-09-15 10:21:13 +00:00
|
|
|
URL="." node[shape="box"]
|
2008-09-10 08:19:26 +00:00
|
|
|
"hoho" [];
|
|
|
|
"yep" [];
|
|
|
|
"labas" [];
|
2008-12-16 16:15:59 +00:00
|
|
|
"yep" -> "hoho" [];
|
|
|
|
"hoho" -> "labas" [];
|
|
|
|
"yep" -> "labas" [];
|
2006-04-26 10:48:09 +00:00
|
|
|
}
|
|
|
|
'''.strip())
|
2010-04-19 09:22:40 +00:00
|
|
|
|
2014-07-26 15:11:14 +00:00
|
|
|
class ImportCheckerTC(unittest.TestCase):
|
2006-04-26 10:48:09 +00:00
|
|
|
def setUp(self):
|
|
|
|
self.linter = l = PyLinter(reporter=TestReporter())
|
|
|
|
initialize(l)
|
2010-04-19 09:22:40 +00:00
|
|
|
|
2006-04-26 10:48:09 +00:00
|
|
|
def test_checker_dep_graphs(self):
|
|
|
|
l = self.linter
|
|
|
|
l.global_set_option('persistent', False)
|
2010-04-19 09:18:08 +00:00
|
|
|
l.global_set_option('enable', 'imports')
|
2006-04-26 10:48:09 +00:00
|
|
|
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')
|
2009-03-18 17:44:35 +00:00
|
|
|
l.global_set_option('int-import-graph', 'int_import.dot')
|
|
|
|
# ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
|
|
|
|
l.global_set_option('ignore', ('func_unknown_encoding.py',))
|
2006-04-26 10:48:09 +00:00
|
|
|
try:
|
|
|
|
l.check('input')
|
2014-10-15 11:30:13 +00:00
|
|
|
l.generate_reports()
|
2013-12-20 11:07:15 +00:00
|
|
|
self.assertTrue(exists('import.dot'))
|
|
|
|
self.assertTrue(exists('ext_import.dot'))
|
|
|
|
self.assertTrue(exists('int_import.dot'))
|
2006-04-26 10:48:09 +00:00
|
|
|
finally:
|
|
|
|
for fname in ('import.dot', 'ext_import.dot', 'int_import.dot'):
|
|
|
|
try:
|
|
|
|
os.remove(fname)
|
|
|
|
except:
|
|
|
|
pass
|
2010-04-19 09:18:08 +00:00
|
|
|
|
2006-04-26 10:48:09 +00:00
|
|
|
if __name__ == '__main__':
|
2014-07-26 15:11:14 +00:00
|
|
|
unittest.main()
|