-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtest_pyreverse_functional.py
90 lines (83 loc) · 3.34 KB
/
test_pyreverse_functional.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
import os
from pathlib import Path
import pytest
from pylint.pyreverse.main import Run
from pylint.testutils.pyreverse import (
FunctionalPyreverseTestfile,
get_functional_test_files,
get_functional_test_packages,
)
FUNCTIONAL_DIR = Path(__file__).parent / "functional"
CLASS_DIAGRAMS_DIR = FUNCTIONAL_DIR / "class_diagrams"
CLASS_DIAGRAM_TESTS = get_functional_test_files(CLASS_DIAGRAMS_DIR)
CLASS_DIAGRAM_TEST_IDS = [testfile.source.stem for testfile in CLASS_DIAGRAM_TESTS]
PACKAGE_DIAGRAMS_DIR = FUNCTIONAL_DIR / "packages"
PACKAGE_DIAGRAM_TESTS = get_functional_test_packages(PACKAGE_DIAGRAMS_DIR)
PACKAGE_DIAGRAM_TEST_IDS = [
test_package.source.name for test_package in PACKAGE_DIAGRAM_TESTS
]
@pytest.mark.parametrize(
"testfile",
CLASS_DIAGRAM_TESTS,
ids=CLASS_DIAGRAM_TEST_IDS,
)
def test_class_diagrams(testfile: FunctionalPyreverseTestfile, tmp_path: Path) -> None:
input_file = testfile.source
input_path = os.path.dirname(input_file)
if testfile.options["source_roots"]:
source_roots = ",".join(
[
os.path.realpath(
os.path.expanduser(os.path.join(input_path, source_root))
)
for source_root in testfile.options["source_roots"]
]
)
else:
source_roots = ""
for output_format in testfile.options["output_formats"]:
with pytest.raises(SystemExit) as sys_exit:
args = ["-o", f"{output_format}", "-d", str(tmp_path)]
if source_roots:
args += ["--source-roots", source_roots]
args.extend(testfile.options["command_line_args"])
args += [str(input_file)]
Run(args)
assert sys_exit.value.code == 0
assert testfile.source.with_suffix(f".{output_format}").read_text(
encoding="utf8"
) == (tmp_path / f"classes.{output_format}").read_text(encoding="utf8")
@pytest.mark.parametrize(
"test_package",
PACKAGE_DIAGRAM_TESTS,
ids=PACKAGE_DIAGRAM_TEST_IDS,
)
def test_packages(test_package: FunctionalPyreverseTestfile, tmp_path: Path) -> None:
input_path = test_package.source
if test_package.options["source_roots"]:
source_roots = ",".join(
[
os.path.realpath(
os.path.expanduser(os.path.join(input_path, source_root))
)
for source_root in test_package.options["source_roots"]
]
)
else:
source_roots = ""
for output_format in test_package.options["output_formats"]:
output_file = input_path / f"{input_path.name}.{output_format}"
with pytest.raises(SystemExit) as sys_exit:
args = ["-o", f"{output_format}", "-d", str(tmp_path)]
if source_roots:
args += ["--source-roots", source_roots]
args.extend(test_package.options["command_line_args"])
args += [str(input_path)]
Run(args)
assert sys_exit.value.code == 0
assert output_file.read_text(encoding="utf8") == (
tmp_path / f"classes.{output_format}"
).read_text(encoding="utf8")