Skip to content

Commit 578322d

Browse files
fix(test): satisfy CodeQL on the changelog-parsing test
CodeQL flagged the for/else: pytest.fail() pattern as a potentially-uninitialized-local-variable warning because it doesn't model pytest.fail as NoReturn — the analyzer sees a path where submodule_latest is referenced after the loop without ever being bound. Pulling the parse into _read_latest_spec_version_from_changelog that explicitly returns the version or raises AssertionError. Eliminates the unreachable-after-fail pattern and reads cleaner.
1 parent b8ffc43 commit 578322d

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

tests/test_smoke.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ def test_spec_version_matches_pyproject() -> None:
3030
_CHANGELOG_VERSION_RE = re.compile(r"^## \[(\d+\.\d+\.\d+)\]")
3131

3232

33+
def _read_latest_spec_version_from_changelog(path: Path) -> str:
34+
"""Return the first non-``[Unreleased]`` versioned heading from a
35+
Keep-a-Changelog file. Raises :class:`AssertionError` if no
36+
versioned heading is present (the file is malformed for our
37+
purposes).
38+
"""
39+
for line in path.read_text().splitlines():
40+
match = _CHANGELOG_VERSION_RE.match(line)
41+
if match:
42+
return match.group(1)
43+
raise AssertionError(f"no versioned heading found in {path}")
44+
45+
3346
def test_spec_version_matches_submodule_changelog() -> None:
3447
# Third value AGENTS.md flags: the submodule pin (the spec
3548
# checkout the parent repo records). We verify by reading the
@@ -41,13 +54,7 @@ def test_spec_version_matches_submodule_changelog() -> None:
4154
changelog_path = Path(__file__).resolve().parent.parent / "openarmature-spec" / "CHANGELOG.md"
4255
if not changelog_path.exists():
4356
pytest.skip("openarmature-spec/CHANGELOG.md is not present")
44-
for line in changelog_path.read_text().splitlines():
45-
match = _CHANGELOG_VERSION_RE.match(line)
46-
if match:
47-
submodule_latest = match.group(1)
48-
break
49-
else:
50-
pytest.fail("could not find a versioned heading in openarmature-spec/CHANGELOG.md")
57+
submodule_latest = _read_latest_spec_version_from_changelog(changelog_path)
5158
assert openarmature.__spec_version__ == submodule_latest, (
5259
f"submodule's CHANGELOG latest is {submodule_latest}, but "
5360
f"__spec_version__ is {openarmature.__spec_version__}"

0 commit comments

Comments
 (0)