Kill the surviving mutants of the file-name import move and the mutmut crash line
This commit is contained in:
@@ -11,24 +11,23 @@ from mutate_changes.changed_lines import is_test
|
||||
|
||||
|
||||
def imported_by_file_name(top: str, grouped: dict[str, dict[str, frozenset[int]]], configs: tuple[str, ...]) -> dict[str, dict[str, frozenset[int]]]:
|
||||
"""grouped, with each file that a test beside it imports by its file name moved to its own folder, named from the checkout's top.
|
||||
"""grouped, with each file of the checkout's top group that a test beside it imports by its file name moved to its own folder.
|
||||
|
||||
A folder that holds one of configs keeps its files: the settings there decide how its tests import them."""
|
||||
regrouped: dict[str, dict[str, frozenset[int]]] = {}
|
||||
for folder, files in grouped.items():
|
||||
configured = any(os.path.isfile(os.path.join(top, folder, name)) for name in configs)
|
||||
for path, lines in files.items():
|
||||
own = posixpath.join(folder, posixpath.dirname(path))
|
||||
moved = not configured and posixpath.basename(path)[:-3] in top_level_imports(os.path.join(top, own)) and not os.path.isfile(os.path.join(top, own, "__init__.py"))
|
||||
target, name = (posixpath.normpath(own), posixpath.basename(path)) if moved else (folder, path)
|
||||
regrouped.setdefault(target, {})[name] = lines
|
||||
A file in a folder that holds one of configs stays: the settings there decide how its tests import it. So do all files where the top holds one."""
|
||||
if "." not in grouped or any(os.path.isfile(os.path.join(top, name)) for name in configs):
|
||||
return grouped
|
||||
regrouped: dict[str, dict[str, frozenset[int]]] = {name: files for name, files in grouped.items() if name != "."}
|
||||
for path, lines in grouped["."].items():
|
||||
own = posixpath.dirname(path) or "."
|
||||
moved = posixpath.basename(path)[:-3] in top_level_imports(os.path.join(top, own)) and not os.path.isfile(os.path.join(top, own, "__init__.py"))
|
||||
regrouped.setdefault(own if moved else ".", {})[posixpath.basename(path) if moved else path] = lines
|
||||
return regrouped
|
||||
|
||||
|
||||
def top_level_imports(folder: str) -> set[str]:
|
||||
"""The modules the test files in folder import by their first name. A test file that doesn't parse names none."""
|
||||
names: set[str] = set()
|
||||
for test in pathlib.Path(folder).glob("*.py"):
|
||||
for test in sorted(pathlib.Path(folder).glob("*.py")):
|
||||
if not is_test(test.name):
|
||||
continue
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user