Add the pytest suite and fix the bugs it found
The suite takes its data from the vectors and fixtures: 3635 tests, 97.9% branch coverage, and paperspec check and paperspec stress give the same results as before. Fixed: receipts.verify_signature raised KeyError for a record without a format; traces.DOC_TAG matched a tag followed by a line feed; paperspec load and paperspec check left SQLite connections open; the site builder copied the output folder's subfolders into itself. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B8cL4zN4XpaQF5cBtASzfq
This commit is contained in:
76 files changed
+15564
-80
No files matched your search
@@ -0,0 +1,72 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright 2026 Scienting
|
||||
#
|
||||
# Source Code: https://git.scient.ing/papers/paperspec
|
||||
# See the LICENSE.md file for full license terms.
|
||||
|
||||
"""Every source file carries the license header; ruff checks the Python files, this checks the rest.
|
||||
|
||||
paperspec is an exception to Scienting's Prosperity header: its code is Apache-2.0 (LICENSE.md), so the header
|
||||
is an SPDX identifier, and the schemas, SQL and vectors, which are CC0-1.0 data, carry none.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
NOTICE = "SPDX-License-Identifier: Apache-2.0"
|
||||
SOURCE = "Source Code: https://git.scient.ing/papers/paperspec"
|
||||
|
||||
# Comment syntax by file suffix. Data, lock files, generated output and the normative CC0 data (schemas, SQL,
|
||||
# vectors, fixtures) are not source files and are not listed.
|
||||
COMMENT = {
|
||||
".py": "#",
|
||||
".sh": "#",
|
||||
".js": "//",
|
||||
".ts": "//",
|
||||
}
|
||||
# Paths (relative, forward slashes) that are generated or vendored, never source.
|
||||
EXCLUDED = ("src/paperspec/_version.py",)
|
||||
|
||||
|
||||
def tracked_sources() -> list[Path]:
|
||||
"""Return the tracked and untracked-but-not-ignored files whose suffix names a source language."""
|
||||
out = subprocess.run(
|
||||
[
|
||||
"git",
|
||||
"-C",
|
||||
str(ROOT),
|
||||
"ls-files",
|
||||
"--cached",
|
||||
"--others",
|
||||
"--exclude-standard",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.splitlines()
|
||||
return [
|
||||
ROOT / name
|
||||
for name in out
|
||||
if Path(name).suffix in COMMENT
|
||||
and not name.startswith(EXCLUDED)
|
||||
and (ROOT / name).is_file()
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path", tracked_sources(), ids=lambda p: str(p.relative_to(ROOT))
|
||||
)
|
||||
def test_file_has_the_license_header(path: Path) -> None:
|
||||
"""The first lines (after a shebang) are the SPDX notice and name this repository as the source."""
|
||||
lines = path.read_text(encoding="utf-8").splitlines()
|
||||
if lines and lines[0].startswith("#!"):
|
||||
lines = lines[1:]
|
||||
head = "\n".join(lines[:8])
|
||||
marker = COMMENT[path.suffix]
|
||||
assert f"{marker} {NOTICE}" in head, (
|
||||
f"{path.relative_to(ROOT)} lacks the license header"
|
||||
)
|
||||
assert f"{marker} {SOURCE}" in head
|
||||
Reference in new issue
Block a user