summaryrefslogtreecommitdiff
path: root/tests/test_import_graph.py
diff options
context:
space:
mode:
authorAndrew Howe <howeaj@users.noreply.github.com>2021-03-29 09:00:18 +0100
committerGitHub <noreply@github.com>2021-03-29 10:00:18 +0200
commita37c643d54ea33285e4c916a296784593af0130c (patch)
tree27bb49a2cee462ec2b69f1d6c2395ed1d8059166 /tests/test_import_graph.py
parent42bf3b0f4d2aad3e5b40153cf743021de635836d (diff)
downloadpylint-git-a37c643d54ea33285e4c916a296784593af0130c.tar.gz
Fix various problems with --import-graph filename parsing (#4259)
Avoids backwards-incompatible changes. - Raise error if graphvis is not installed (instead of reporting success) - Fix tempfile creation bug when outputfile includes directories - Fix bug when using file extension that isn't 3 characters long - Fix confusing help text - Rename deprecated .dot extension to .gv - Default to .png if no extension is specified * Add typing to modified functions (and ignore mypy thinking codecs.open() returns an int) Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests/test_import_graph.py')
-rw-r--r--tests/test_import_graph.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/test_import_graph.py b/tests/test_import_graph.py
index 14e5f387a..b918d3b29 100644
--- a/tests/test_import_graph.py
+++ b/tests/test_import_graph.py
@@ -26,8 +26,8 @@ from pylint.lint import PyLinter
@pytest.fixture
-def dest():
- dest = "dependencies_graph.dot"
+def dest(request):
+ dest = request.param
yield dest
try:
os.remove(dest)
@@ -36,13 +36,18 @@ def dest():
pass
+POSSIBLE_DOT_FILENAMES = ["foo.dot", "foo.gv", "tests/regrtest_data/foo.dot"]
+
+
+@pytest.mark.parametrize("dest", POSSIBLE_DOT_FILENAMES, indirect=True)
def test_dependencies_graph(dest):
+ """DOC files are correctly generated, and the graphname is the basename"""
imports._dependencies_graph(dest, {"labas": ["hoho", "yep"], "hoho": ["yep"]})
with open(dest) as stream:
assert (
stream.read().strip()
== """
-digraph "dependencies_graph" {
+digraph "foo" {
rankdir=LR
charset="utf-8"
URL="." node[shape="box"]
@@ -57,6 +62,13 @@ URL="." node[shape="box"]
)
+@pytest.mark.parametrize("filename", ["graph.png", "graph"])
+def test_missing_graphviz(filename):
+ """Raises if graphviz is not installed, and defaults to png if no extension given"""
+ with pytest.raises(RuntimeError, match=r"Cannot generate `graph\.png`.*"):
+ imports._dependencies_graph(filename, {"a": ["b", "c"], "b": ["c"]})
+
+
@pytest.fixture
def linter():
pylinter = PyLinter(reporter=testutils.GenericTestReporter())