Kill the surviving mutants of run-tests and wait-for, and name a file wait-for cannot read
CI / tests (pull_request) Successful in 2m38s

This commit is contained in:
2026-11-12 09:04:32 +01:00
parent 22942308f6
commit 37f19d1677
2 changed files with 112 additions and 2 deletions
+65 -2
View File
@@ -10,6 +10,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from machine_load.slots import CPUS_PER_SLOT
from run_tests import main
BIN = pathlib.Path(__file__).resolve().parents[1]
@@ -31,11 +32,73 @@ class PytestArgs(unittest.TestCase):
self.assertEqual(main.pytest_args([str(test_file)]), [str(test_file)])
self.assertEqual(main.pytest_args(["-x", f"{test_file}::T::test_a"]), ["-x", f"{test_file}::T::test_a"])
def test_the_pinned_command_is_readme_tests_incantation(self):
self.assertEqual(main.PYTEST[1:], ["--python", main.PYTEST[2], "--with", "pytest-xdist==3.8.0", "pytest==9.2.0", "-n", "4"])
def test_the_command_pins_pytest_and_fills_one_heavy_slot(self):
self.assertEqual(main.PYTEST[1:], ["--python", main.PYTEST[2], "--with", "pytest-xdist==3.8.0", "pytest==9.2.0", "-n", str(CPUS_PER_SLOT)])
self.assertEqual(main.PYTEST[0], "uvx")
def errors(count: int) -> str:
return "".join(f"E line {n}\n" for n in range(count))
class Report(unittest.TestCase):
def test_prints_each_failure_and_error_with_its_errors_then_the_summary(self):
log = (
"===== test session starts =====\nE not in a section\n"
f"===== FAILURES =====\n_____ test_a _____\n\n def test_a():\n{errors(main.ERROR_LINES)}a.py:2: AssertionError\n"
f"===== ERRORS =====\n_____ ERROR at setup of test_b _____\n{errors(main.ERROR_LINES + 3)}b.py:4: ValueError\n"
"===== short test summary info =====\nFAILED a.py::test_a\nERROR b.py::test_b\n===== 1 failed, 1 error in 0.10s =====\n"
)
self.assertEqual(main.report(log), [
"_____ test_a _____", *errors(main.ERROR_LINES).splitlines(), "a.py:2: AssertionError",
"_____ ERROR at setup of test_b _____", *errors(main.ERROR_LINES).splitlines(), "E … 3 more lines in the log", "b.py:4: ValueError",
"FAILED a.py::test_a", "ERROR b.py::test_b", "===== 1 failed, 1 error in 0.10s =====",
])
def test_prints_nothing_where_pytest_printed_no_summary_line(self):
self.assertEqual(main.report("usage: pytest\nerror: unrecognized arguments\n"), [])
class RunWithAStandIn(unittest.TestCase):
"""run with a stand-in for pytest: a Python script given the arguments run passes on."""
def run_script(self, script: str, cwd: str | None = None) -> tuple[int, str, str]:
out, err = io.StringIO(), io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
code = main.run(["-x"], [sys.executable, "-c", script], cwd)
lines = out.getvalue().splitlines()
if lines and lines[-1].startswith("Full log: "):
self.addCleanup(os.unlink, lines[-1].removeprefix("Full log: "))
return code, out.getvalue(), err.getvalue()
def test_saves_the_log_as_run_tests_star_log_in_the_temp_folder_which_ci_sh_prints(self):
code, out, _ = self.run_script("print('== 1 passed in 0.1s ==')")
self.assertEqual(code, 0)
log = pathlib.Path(out.splitlines()[-1].removeprefix("Full log: "))
self.assertEqual(log.parent, pathlib.Path(tempfile.gettempdir()))
self.assertRegex(log.name, r"^run-tests-.+\.log$")
def test_runs_in_the_folder_given_and_shows_the_last_lines_of_a_log_without_a_summary(self):
with tempfile.TemporaryDirectory() as folder:
script = "import os, sys; sys.stdout.buffer.write(b'bad \\xff byte\\n'); print('\\n'.join(map(str, range(30)))); print(os.getcwd())"
code, out, _ = self.run_script(script, folder)
self.assertEqual(code, 0)
tail = [str(n) for n in range(30 - main.LOG_TAIL + 1, 30)] + [os.path.realpath(folder)]
self.assertEqual(out.splitlines()[:-1], ["run-tests: pytest printed no summary line; the log ends:", *tail])
def test_reads_a_log_that_is_not_utf_8(self):
code, out, _ = self.run_script("import sys; sys.stdout.buffer.write(b'\\xff\\n== 1 failed in 0.1s ==\\n'); sys.exit(1)")
self.assertEqual(code, 1)
self.assertIn("== 1 failed in 0.1s ==", out)
def test_says_on_stderr_that_a_command_cannot_start(self):
out, err = io.StringIO(), io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
code = main.run([], ["/no/such/uvx"])
self.assertEqual((code, out.getvalue()), (1, ""))
self.assertEqual(err.getvalue(), "run-tests: cannot start /no/such/uvx: No such file or directory\n")
@unittest.skipUnless(HAS_PYTEST, "needs pytest importable")
class Run(unittest.TestCase):
def run_in(self, folder: str, pytest: list[str], *args: str) -> tuple[int, str]: