Test in its own module that every bin/ file compiles on the Python README names

This commit is contained in:
2026-09-26 15:31:06 +02:00
parent 04869eba24
commit e5921c7ef1
2 changed files with 18 additions and 13 deletions
-13
View File
@@ -6,7 +6,6 @@ import io
import json
import os
import pathlib
import re
import stat
import subprocess
import sys
@@ -31,18 +30,6 @@ def human(content):
return {"type": "user", "message": {"content": content}}
class PythonFloor(unittest.TestCase):
def test_every_bin_file_compiles_on_the_python_the_decision_log_names(self):
root = pathlib.Path(__file__).resolve().parents[1]
named = re.search(r"^## bin/: parses on Python (3\.\d+)$", (root / "docs" / "decisions.md").read_text(), re.MULTILINE)
self.assertIsNotNone(named, "docs/decisions.md heads the floor `bin/: parses on Python 3.N`")
tracked = subprocess.run(["git", "ls-files", "-z", "bin"], capture_output=True, check=True, cwd=root, text=True).stdout.split("\0")
self.assertTrue(tracked[0])
check = "import sys\nfor path in sys.argv[1:]:\n\tcompile(open(path).read(), path, 'exec')"
compiled = subprocess.run(["uv", "run", "--no-project", "--python", named.group(1), "python", "-c", check, *filter(None, tracked)], capture_output=True, cwd=root, text=True)
self.assertEqual(compiled.returncode, 0, compiled.stderr)
class Sections(unittest.TestCase):
def test_keeps_every_headed_section_with_its_bodies(self):
text = "# Title\n\nintro\n\n## Goals\n\n1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority\n\n## Empty\n\n## Audience\nme\n## Audience\nagain\n# Appendix\nnot audience\n"
+18
View File
@@ -0,0 +1,18 @@
import pathlib
import re
import subprocess
import unittest
ROOT = pathlib.Path(__file__).resolve().parents[1]
FLOOR = re.compile(r"Python (3\.\d+) or newer")
class PythonFloor(unittest.TestCase):
def test_every_bin_file_compiles_on_the_python_the_readme_names_as_floor(self):
named = FLOOR.search((ROOT / "README.md").read_text())
self.assertIsNotNone(named, "README.md's Install names `Python 3.N or newer`")
tracked = subprocess.run(["git", "ls-files", "-z", "bin"], capture_output=True, check=True, cwd=ROOT, text=True).stdout.split("\0")
self.assertTrue(tracked[0])
check = "import sys\nfor path in sys.argv[1:]:\n\tcompile(open(path).read(), path, 'exec')"
compiled = subprocess.run(["uv", "run", "--no-project", "--python", named.group(1), "python", "-c", check, *filter(None, tracked)], capture_output=True, cwd=ROOT, text=True)
self.assertEqual(compiled.returncode, 0, compiled.stderr)