From c3054bef4ce95fa053b5aaef4f68948772924dcd Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:48:32 +0100 Subject: [PATCH] feat: catch patch.object on a command --- scripts/fileless_audit.py | 6 +++--- scripts/release_notes.py | 4 ++-- tests/test_fileless_audit.py | 2 +- tests/test_layers.py | 6 ++++++ tests/test_release_packs.py | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/fileless_audit.py b/scripts/fileless_audit.py index 68b1918b8..3d566f7c7 100644 --- a/scripts/fileless_audit.py +++ b/scripts/fileless_audit.py @@ -26,7 +26,7 @@ sys.path.insert(0, os.path.dirname(__file__)) from core import upstream from core.cli import add_repo_inputs, require_directory from model.profiles import ProfileSelectionError, load_emulator_profiles, resolve_profile_name -from profiling.fileless import audit, unanswered_profiles +from profiling import fileless def main() -> None: @@ -59,12 +59,12 @@ def main() -> None: except ProfileSelectionError as exc: raise SystemExit(f"ERROR: {exc}") from None if args.all: - names = unanswered_profiles(args.emulators_dir) + names = fileless.unanswered_profiles(args.emulators_dir) flagged = unreachable = 0 for name in names: try: - hits = audit(name, args.emulators_dir, args.cache_dir, args.offline) + hits = fileless.audit(name, args.emulators_dir, args.cache_dir, args.offline) except upstream.UpstreamError as exc: print(f"{name}: unreachable, {exc}", file=sys.stderr) unreachable += 1 diff --git a/scripts/release_notes.py b/scripts/release_notes.py index 249999671..99becf175 100644 --- a/scripts/release_notes.py +++ b/scripts/release_notes.py @@ -34,10 +34,10 @@ from model import releaserecord from core.cli import require_directory from core.paths import PLATFORMS_DIR from core.artifacts import write_text_atomic +from release import notes from release.notes import ( changelog_url, closing_lines, - gather_thanks, previous_record_commit, refused_words, render, @@ -79,7 +79,7 @@ def main() -> int: thanks = [line for line in args.thanks.read_text(encoding="utf-8").splitlines() if line.strip()] else: - thanks = gather_thanks() + thanks = notes.gather_thanks() except (subprocess.CalledProcessError, ValueError, KeyError, OSError) as exc: detail = getattr(exc, "stderr", "") or exc print(f"Error: cannot gather the thanks: {str(detail).strip()}. Pass a checked list" diff --git a/tests/test_fileless_audit.py b/tests/test_fileless_audit.py index 081c7913d..9ae60df41 100644 --- a/tests/test_fileless_audit.py +++ b/tests/test_fileless_audit.py @@ -131,7 +131,7 @@ class TestCommandLine(unittest.TestCase): with mock.patch.object(sys, "argv", ["fileless.py", *argv, "--emulators-dir", self.tmp.name]), \ - mock.patch.object(fileless_audit, "audit", side_effect=fake), \ + mock.patch.object(fileless, "audit", side_effect=fake), \ mock.patch("sys.stderr"), mock.patch("sys.stdout"), self.assertRaises(SystemExit) as caught: fileless_audit.main() return caught.exception.code, read diff --git a/tests/test_layers.py b/tests/test_layers.py index bc3a38611..3c41ddbf7 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -324,6 +324,12 @@ class ThinCommands(unittest.TestCase): if (module in names and attr.isidentifier() and attr not in FILE_SUFFIXES and attr not in COMMAND_DEFINITIONS): found.append(f"{path.name}: {node.value}") + if (isinstance(node, ast.Call) and len(node.args) >= 2 + and isinstance(node.args[0], ast.Name) and node.args[0].id in bound + and isinstance(node.args[1], ast.Constant) and isinstance(node.args[1].value, str) + and node.args[1].value not in COMMAND_DEFINITIONS): + # mock.patch.object(verify, "x") and setattr(verify, "x", ...) name it apart. + found.append(f"{path.name}: {bound[node.args[0].id]}.{node.args[1].value}") if (isinstance(node, ast.Attribute) and isinstance(node.value, ast.Name) and node.value.id in bound and node.attr not in COMMAND_DEFINITIONS and not node.attr.startswith("__")): diff --git a/tests/test_release_packs.py b/tests/test_release_packs.py index c1dbabfbc..b5bb3c2e9 100644 --- a/tests/test_release_packs.py +++ b/tests/test_release_packs.py @@ -470,7 +470,7 @@ class TheReleaseNotesThankPeople(unittest.TestCase): "--platforms-dir", PLATFORMS, "--output", str(tmp / "notes.md")] with mock.patch.object(sys, "argv", argv), \ mock.patch.object(notes, "_run", self.fake), \ - mock.patch.object(release_notes, "gather_thanks", + mock.patch.object(notes, "gather_thanks", side_effect=AssertionError("gh read")), \ contextlib.redirect_stdout(io.StringIO()): self.assertEqual(release_notes.main(), 0)