third_party.pylibs.pylint.src/pylint/test/test_import_graph.py

82 lines
2.2 KiB
Python
Raw Normal View History

# Copyright (c) 2006-2008, 2010, 2013 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
2017-12-15 11:24:15 +00:00
# Copyright (c) 2012 FELD Boris <lothiraldan@gmail.com>
# Copyright (c) 2014-2016 Claudiu Popa <pcmanticore@gmail.com>
2017-12-15 11:24:15 +00:00
# Copyright (c) 2014 Google, Inc.
# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
# Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
2006-04-26 10:48:09 +00:00
import os
from os.path import exists
2016-12-08 04:15:21 +00:00
import pytest
2006-04-26 10:48:09 +00:00
from pylint.checkers import initialize, imports
from pylint.lint import PyLinter
2016-12-05 18:29:08 +00:00
import pylint.testutils as testutils
2006-04-26 10:48:09 +00:00
2016-12-06 15:42:53 +00:00
2016-12-08 04:15:21 +00:00
@pytest.fixture
def dest():
2006-04-26 10:48:09 +00:00
dest = 'dependencies_graph.dot'
2016-12-08 04:15:21 +00:00
yield dest
os.remove(dest)
2016-12-06 15:42:53 +00:00
2016-12-08 04:15:21 +00:00
def test_dependencies_graph(dest):
imports._dependencies_graph(dest, {'labas': ['hoho', 'yep'],
'hoho': ['yep']})
with open(dest) as stream:
assert stream.read().strip() == '''
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()
2016-12-06 15:42:53 +00:00
2016-12-08 04:15:21 +00:00
@pytest.fixture
def linter():
l = PyLinter(reporter=testutils.TestReporter())
initialize(l)
return l
2016-12-08 04:15:21 +00:00
@pytest.fixture
def remove_files():
yield
for fname in ('import.dot', 'ext_import.dot', 'int_import.dot'):
2006-04-26 10:48:09 +00:00
try:
2016-12-08 04:15:21 +00:00
os.remove(fname)
except:
pass
@pytest.mark.usefixture("remove_files")
def test_checker_dep_graphs(linter):
l = linter
l.global_set_option('persistent', False)
l.global_set_option('reports', True)
l.global_set_option('enable', 'imports')
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')
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',))
l.check('input')
l.generate_reports()
assert exists('import.dot')
assert exists('ext_import.dot')
assert exists('int_import.dot')