# 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")