2016-07-22 21:22:28 +00:00
|
|
|
# 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>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2014-2017 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>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2018 Reverb C <reverbc@users.noreply.github.com>
|
2016-07-22 21:22:28 +00:00
|
|
|
|
2016-06-01 15:11:29 +00:00
|
|
|
# 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
|
2014-11-09 09:33:29 +00:00
|
|
|
|
2016-12-05 18:29:08 +00:00
|
|
|
import pylint.testutils as testutils
|
2019-03-09 10:22:36 +00:00
|
|
|
from pylint.checkers import imports, initialize
|
|
|
|
from pylint.lint import PyLinter
|
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():
|
2018-09-16 15:33:50 +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
|
|
|
|
2010-04-19 09:22:40 +00:00
|
|
|
|
2016-12-08 04:15:21 +00:00
|
|
|
def test_dependencies_graph(dest):
|
2018-09-16 15:33:50 +00:00
|
|
|
imports._dependencies_graph(dest, {"labas": ["hoho", "yep"], "hoho": ["yep"]})
|
2016-12-08 04:15:21 +00:00
|
|
|
with open(dest) as stream:
|
2018-09-16 15:33:50 +00:00
|
|
|
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
|
|
|
}
|
2018-09-16 15:33:50 +00:00
|
|
|
""".strip()
|
|
|
|
)
|
2010-04-19 09:22:40 +00:00
|
|
|
|
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
|
|
|
|
|
2010-04-19 09:22:40 +00:00
|
|
|
|
2016-12-08 04:15:21 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def remove_files():
|
|
|
|
yield
|
2018-09-16 15:33:50 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2018-03-01 08:55:05 +00:00
|
|
|
@pytest.mark.usefixtures("remove_files")
|
2016-12-08 04:15:21 +00:00
|
|
|
def test_checker_dep_graphs(linter):
|
|
|
|
l = linter
|
2018-09-16 15:33:50 +00:00
|
|
|
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")
|
2016-12-08 04:15:21 +00:00
|
|
|
# ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
|
2018-09-16 15:33:50 +00:00
|
|
|
l.global_set_option("ignore", ("func_unknown_encoding.py",))
|
|
|
|
l.check("input")
|
2016-12-08 04:15:21 +00:00
|
|
|
l.generate_reports()
|
2018-09-16 15:33:50 +00:00
|
|
|
assert exists("import.dot")
|
|
|
|
assert exists("ext_import.dot")
|
|
|
|
assert exists("int_import.dot")
|