Files
paperspec/tests/test_resources.py
T
alexmandClaude a8fc7237ae 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
2026-10-19 04:32:44 -04:00

74 lines
2.2 KiB
Python

# 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.
"""Where the schemas, SQL and vectors are on disk (paperspec.resources)."""
import pathlib
import pytest
from paperspec import resources
MARKERS = {
"schemas": "annotation.schema.json",
"sql": "doc.sql",
"vectors": "proofs.jsonl",
}
def test_the_folders_are_the_three_the_package_names():
assert resources.FOLDERS == ("schemas", "sql", "vectors")
@pytest.mark.parametrize("name", resources.FOLDERS)
def test_each_folder_is_found_and_holds_its_files(name):
folder = resources.path(name)
assert pathlib.Path(folder).is_dir()
assert (pathlib.Path(folder) / MARKERS[name]).is_file()
@pytest.mark.parametrize("name", ["tests", "", "SCHEMAS", "schemas/", "../schemas"])
def test_any_other_name_is_refused_and_the_folders_are_listed(name):
with pytest.raises(ValueError, match="there are schemas, sql, vectors"):
resources.path(name)
@pytest.fixture
def layout(tmp_path, monkeypatch):
"""A fake install under `tmp_path/root/src/paperspec`, with the checkout root `tmp_path/root`."""
package = tmp_path / "root" / "src" / "paperspec"
package.mkdir(parents=True)
monkeypatch.setattr(resources, "_PACKAGE", package)
return tmp_path / "root"
def test_a_folder_inside_the_package_is_found_first(layout):
inside = layout / "src" / "paperspec" / "sql"
inside.mkdir()
(layout / "sql").mkdir()
assert resources.path("sql") == str(inside)
def test_a_folder_at_the_root_of_the_checkout_is_found_when_the_package_has_none(
layout,
):
(layout / "vectors").mkdir()
assert resources.path("vectors") == str(layout / "vectors")
def test_a_folder_found_in_neither_place_is_an_error_naming_it(layout):
(layout / "sql").mkdir()
with pytest.raises(
FileNotFoundError, match="the schemas folder is neither in the package"
):
resources.path("schemas")
def test_a_file_in_place_of_a_folder_is_not_a_folder(layout):
(layout / "schemas").write_text("not a folder", encoding="utf-8")
with pytest.raises(FileNotFoundError):
resources.path("schemas")