Skip to content

Commit

Permalink
change: rename all occurrences of module to package and treat every s…
Browse files Browse the repository at this point in the history
…ubdirectory as an own testcase
  • Loading branch information
Hannoma committed Jun 15, 2024
1 parent c6452cd commit d99f984
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 22 deletions.
15 changes: 7 additions & 8 deletions pylint/testutils/pyreverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,24 @@ def get_functional_test_files(
return test_files


def get_functional_test_modules(
def get_functional_test_packages(
root_directory: Path,
) -> list[FunctionalPyreverseTestfile]:
"""Get all functional test files from the given directory."""
"""Treat every subdirectory as a package and get all functional test files."""
test_files = []
for path in root_directory.rglob("__init__.py"):
module_directory = path.parent
module_name = module_directory.name
config_file = module_directory / f"{module_name}.rc"
for package_directory in root_directory.iterdir():
package_name = package_directory.name
config_file = package_directory / f"{package_name}.rc"
if config_file.exists():
test_files.append(
FunctionalPyreverseTestfile(
source=module_directory, options=_read_config(config_file)
source=package_directory, options=_read_config(config_file)
)
)
else:
test_files.append(
FunctionalPyreverseTestfile(
source=module_directory,
source=package_directory,
options={
"source_roots": [],
"output_formats": ["mmd"],
Expand Down
28 changes: 14 additions & 14 deletions tests/pyreverse/test_pyreverse_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
from pylint.testutils.pyreverse import (
FunctionalPyreverseTestfile,
get_functional_test_files,
get_functional_test_modules,
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]
MODULE_DIAGRAMS_DIR = FUNCTIONAL_DIR / "modules"
MODULE_DIAGRAM_TESTS = get_functional_test_modules(MODULE_DIAGRAMS_DIR)
MODULE_DIAGRAM_TEST_IDS = [
testmodule.source.name for testmodule in MODULE_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
]


Expand Down Expand Up @@ -58,30 +58,30 @@ def test_class_diagrams(testfile: FunctionalPyreverseTestfile, tmp_path: Path) -


@pytest.mark.parametrize(
"testmodule",
MODULE_DIAGRAM_TESTS,
ids=MODULE_DIAGRAM_TEST_IDS,
"test_package",
PACKAGE_DIAGRAM_TESTS,
ids=PACKAGE_DIAGRAM_TEST_IDS,
)
def test_modules(testmodule: FunctionalPyreverseTestfile, tmp_path: Path) -> None:
input_path = testmodule.source
if testmodule.options["source_roots"]:
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 testmodule.options["source_roots"]
for source_root in test_package.options["source_roots"]
]
)
else:
source_roots = ""
for output_format in testmodule.options["output_formats"]:
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(testmodule.options["command_line_args"])
args.extend(test_package.options["command_line_args"])
args += [str(input_path)]
Run(args)
assert sys_exit.value.code == 0
Expand Down

0 comments on commit d99f984

Please sign in to comment.