mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-11-06 06:57:50 +00:00
fix(tests): escape the regex in test_verify_pdf's docstring and compile-check tests/*.py (#503)
FindNonAsciiDateRangesTests' docstring (from #498) quotes the regex `\s*`
in a non-raw string. `\s` is an invalid escape sequence, so Python 3.12+
prints a SyntaxWarning for it (CPython gh-98401) when
tests/test_verify_pdf.py is compiled. It is in this repo's own CI log
for a45bbd1 on 3.12, 3.13 and 3.14, at tests/test_verify_pdf.py:75, while
the run stays green. Under `-W error::SyntaxWarning` the module fails to
import and the whole test_verify_pdf suite drops out of the run.
Escaped in the docstring. ToolsCompileWithoutWarnings (#480) only compiled
tools/*.py, which is why this got through; it now compiles tests/*.py too.
With the unescaped docstring it fails naming tests/test_verify_pdf.py, and
it passes with the fix.
Verification on Python 3.10, 3.11, 3.12, 3.13 and 3.14, from a clean
bytecode cache: `python -W error::SyntaxWarning -m unittest discover -s
tests -t .` OK (501 tests, the same count as master),
`tools/lint_skills.py`, `tools/check_framework_version.py`,
`tools/security_guards.py`.
This commit is contained in:
3 files changed
+17
-5
No files matched your search
@@ -177,15 +177,19 @@ class ToolsCompileWithoutWarnings(unittest.TestCase):
|
||||
the warning lands in the middle of a verification report. Compiling is a
|
||||
pure `compile()` over the source text - no cache file, no temp file - so the
|
||||
check costs nothing and covers every `tools/*.py`, guarding the next
|
||||
docstring that quotes a macro too.
|
||||
docstring that quotes a macro too. It covers `tests/*.py` as well: a test
|
||||
docstring that quotes a regex (`\\s*` in `test_verify_pdf.py`) warned in CI
|
||||
on every matrix Python while the run stayed green.
|
||||
"""
|
||||
|
||||
def test_sources_have_no_invalid_escape_sequences(self):
|
||||
import warnings
|
||||
|
||||
tools_dir = Path(verify_layout.__file__).resolve().parent
|
||||
sources = sorted(tools_dir.glob("*.py"))
|
||||
tests_dir = Path(__file__).resolve().parent
|
||||
sources = sorted(tools_dir.glob("*.py")) + sorted(tests_dir.glob("*.py"))
|
||||
self.assertIn(Path(verify_layout.__file__).resolve(), sources)
|
||||
self.assertIn(Path(__file__).resolve(), sources)
|
||||
offenders: dict[str, list[str]] = {}
|
||||
for source in sources:
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
@@ -197,8 +201,8 @@ class ToolsCompileWithoutWarnings(unittest.TestCase):
|
||||
if issubclass(w.category, (SyntaxWarning, DeprecationWarning))
|
||||
]
|
||||
if syntax:
|
||||
offenders[source.name] = syntax
|
||||
self.assertEqual({}, offenders, "tools/*.py warn about invalid escapes when compiled")
|
||||
offenders[f"{source.parent.name}/{source.name}"] = syntax
|
||||
self.assertEqual({}, offenders, "tools/*.py or tests/*.py warn about invalid escapes when compiled")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user