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:
alexmandClaude committed 2026-10-19 04:32:44 -04:00
1 parent 30d310f64d
commit a8fc7237ae
76 files changed
+15564 -80

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
# 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.
"""Shared test helpers.
The repository's own vectors and fixtures are the test data: the vectors hold the exact
outputs the specification requires, and `fixtures/` holds the packages and records the
checks read.
"""
import json
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
VECTORS = ROOT / "vectors"
FIXTURES = ROOT / "fixtures"
def read_jsonl(path: Path) -> list[dict]:
"""Parse a JSON Lines file into a list of records."""
return [
json.loads(line)
for line in path.read_text(encoding="utf-8").splitlines()
if line
]
def vector_cases(name: str) -> list[dict]:
"""The cases of `vectors/<name>.jsonl`."""
return read_jsonl(VECTORS / f"{name}.jsonl")
@pytest.fixture(scope="session")
def root() -> Path:
"""The repository root, where `paperspec check` and `paperspec build` work."""
return ROOT