Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s

This commit is contained in:
2026-11-19 12:42:03 +01:00
parent 8ca612b7a4
commit cb3135bc8c
124 changed files with 1437 additions and 793 deletions
+2 -1
View File
@@ -17,6 +17,7 @@ import shutil
import subprocess
import sys
import tempfile
import typing
from machine_load.slots import CPUS_PER_SLOT
@@ -92,7 +93,7 @@ def run(argv: list[str], pytest: list[str] = PYTEST, cwd: str | None = None) ->
return 0 if code == 0 else 1
def main(argv: list[str]) -> int:
def main(argv: list[str], run: typing.Callable[[list[str]], int]) -> int:
if argv[:1] in (["-h"], ["--help"]):
print(__doc__.strip())
return 0
+5 -7
View File
@@ -1,6 +1,5 @@
import contextlib
import io
from unittest import mock
import os
import pathlib
import re
@@ -57,13 +56,12 @@ class Main(unittest.TestCase):
for argv in (["-h"], ["--help"], ["--help", "bin/x"]):
with self.subTest(argv=argv):
out = io.StringIO()
with contextlib.redirect_stdout(out), mock.patch.object(main, "run") as run:
self.assertEqual(main.main(argv), 0)
with contextlib.redirect_stdout(out):
self.assertEqual(main.main(argv, self.fail), 0)
self.assertEqual(out.getvalue(), main.__doc__.strip() + "\n")
run.assert_not_called()
with mock.patch.object(main, "run", return_value=1) as run:
self.assertEqual(main.main(["bin/x", "-h"]), 1)
run.assert_called_once_with(["bin/x", "-h"])
ran = []
self.assertEqual(main.main(["bin/x", "-h"], lambda argv: ran.append(argv) or 1), 1)
self.assertEqual(ran, [["bin/x", "-h"]])
class RunWithAStandIn(unittest.TestCase):