refactor: verify keeps its lock stack name

The --destinations branch of _main rebound held, the ExitStack that
holds the data directory locks, to the dict it writes. It is now
named destinations, and a test refuses a rebinding of the stack.
This commit is contained in:
Abdessamad Derraz committed 2026-11-06 08:19:00 +01:00
1 parent dfa1cc31d3
commit 54eac3b2df
2 files changed
+20 -3

No files matched your search

+3 -3
View File
@@ -2988,13 +2988,13 @@ def _main(held: contextlib.ExitStack) -> None:
print(_overall_summary(group_results))
if args.destinations:
held = {}
destinations = {}
for (result, names), (group, _rep) in zip(group_results, groups):
for name, key in zip(names, group):
held[name] = {
destinations[name] = {
"platform": key, "pack_destinations": result["pack_destinations"],
}
Path(args.destinations).write_text(json.dumps(held, indent=1, sort_keys=True))
Path(args.destinations).write_text(json.dumps(destinations, indent=1, sort_keys=True))
if args.json:
for r in all_results.values():
+17
View File
@@ -173,6 +173,23 @@ class TheDestinationsFlagNeedsAPack(unittest.TestCase):
self.assertEqual(result.returncode, 2, result.stdout[-300:])
self.assertIn("--destinations", result.stderr)
def test_the_lock_stack_is_not_rebound(self):
"""The --destinations branch reused `held`, the ExitStack that holds
the data directory locks, for its dict: a later enter_context in
that mode raised AttributeError."""
import ast
tree = ast.parse((REPO_ROOT / "scripts" / "verify.py").read_text(encoding="utf-8"))
body = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == "_main")
stack = body.args.args[0].arg
rebound = [
node.lineno for node in ast.walk(body)
if isinstance(node, (ast.Assign, ast.AnnAssign, ast.AugAssign))
for target in (node.targets if isinstance(node, ast.Assign) else [node.target])
if isinstance(target, ast.Name) and target.id == stack
]
self.assertEqual(rebound, [])
class EveryGapCountedIsNamed(unittest.TestCase):
"""verify --platform batocera --verbose counted 3 optional core files and