The style and licence tests skip the files that git ignores

Both tests walk scripts/ with rglob, so they also read the MeshCore
checkout that build-firmware.sh makes in scripts/picocalc-lyra/
xiao-radio/_meshcore-build. Its third-party code and libraries have
contractions and no SPDX lines, and every developer who followed the
PicoCalc guide got three failures. conftest.not_ignored asks git
check-ignore which paths it ignores and removes them; a tracked file
is never ignored, and without git the tests examine everything, as
before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-10-08 20:26:27 -04:00
1 parent 3f7180b866
commit 2bb563605f
3 files changed
+46 -4

No files matched your search

+39 -1
View File
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
"""Shared fixtures and helpers: plain-text screen reading, and fixed path rendering.
"""Shared fixtures and helpers: plain-text screen reading, fixed path rendering, project files.
:func:`plain` is the only way that a test reads a rendered screen. Each screen test must
first remove the ANSI colour escapes and join the rendered lines. Only then can it make
@@ -18,13 +18,18 @@ powerline pass explicit modes, or they patch the widget's own switch with
and keeps attributes. This silently makes each colour assertion in the suite useless (a
shell that an agent harness runs sets it). The autouse fixture below deletes it. Thus the
tests always see the colours that the app really sends.
:func:`not_ignored` keeps a test that walks a folder to the files of the project. Git
ignores the other files in the checkout, and these files are not ours to examine.
"""
from __future__ import annotations
import os
import re
import subprocess
from collections.abc import Callable, Iterable, Iterator
from pathlib import Path
import pytest
@@ -47,6 +52,39 @@ def plain(rendered: str | Iterable[str]) -> str:
return _ANSI.sub("", rendered)
#: The root of the checkout.
_ROOT = Path(__file__).resolve().parent.parent
def not_ignored(paths: Iterable[Path]) -> list[Path]:
"""The paths in ``paths`` that git does not ignore, in their order.
A test that walks a folder of the checkout must examine only the files of the project.
A folder can also hold files that git ignores. An example is the MeshCore checkout that
``build-firmware.sh`` makes in ``scripts/``, with its third-party code and its build
tree. Git never ignores a tracked file. When git is not available (for example, in an
unpacked source archive), the function returns all the paths, and the test examines
each file, as it did before.
"""
paths = list(paths)
relative = [path.resolve().relative_to(_ROOT).as_posix() for path in paths]
try:
result = subprocess.run(
["git", "check-ignore", "--stdin", "-z"],
cwd=_ROOT,
input="\0".join(relative),
capture_output=True,
encoding="utf-8",
check=False,
)
except OSError:
return paths
if result.returncode not in (0, 1): # 1 is "nothing ignored", 128 is "not a repository"
return paths
ignored = set(result.stdout.split("\0"))
return [path for path, name in zip(paths, relative, strict=True) if name not in ignored]
@pytest.fixture(autouse=True)
def _plain_path_rendering(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
monkeypatch.setenv("MESHTERM_POWERLINE", "0")
+3 -1
View File
@@ -10,6 +10,8 @@ identifier. Thus this gate makes sure that no file has no marking.
from pathlib import Path
from tests.conftest import not_ignored
def test_spdx_headers():
"""Each Python file must have an SPDX-License-Identifier header."""
@@ -33,7 +35,7 @@ def test_spdx_headers():
python_files.append(spi_bridge)
missing_spdx = []
for filepath in sorted(python_files):
for filepath in not_ignored(sorted(python_files)):
# A file that MeshTerm cannot read as UTF-8 is a finding. The test must not skip it.
# Each source file here is UTF-8, and a skip with no message lets a file with no
# marking pass.
+4 -2
View File
@@ -20,6 +20,8 @@ import re
import tokenize
from pathlib import Path
from tests.conftest import not_ignored
ROOT = Path(__file__).resolve().parent.parent
#: The folders whose Python files are examined.
@@ -81,7 +83,7 @@ def _blank_quotes(text: str) -> str:
def _python_files() -> list[Path]:
files = [p for d in PYTHON_DIRS for p in (ROOT / d).rglob("*.py")]
files += [ROOT / p for p in PYTHON_EXTRA]
return sorted(p for p in files if p.exists() and "__pycache__" not in p.parts)
return not_ignored(sorted(p for p in files if p.exists() and "__pycache__" not in p.parts))
def _python_prose(path: Path) -> list[tuple[int, str]]:
@@ -125,7 +127,7 @@ def _documents() -> list[Path]:
for name in DOCUMENTS:
path = ROOT / name
files += sorted(path.rglob("*.md")) if path.is_dir() else [path]
return files
return not_ignored(files)
def _markdown_prose(path: Path) -> list[tuple[int, str]]: