Initial public release of pdf-tools
Command-line tools for marked-up PDFs and scanned handwritten notes: pdf-scrub, pdf-notes-md, scan-notes-md (Ollama by default, Claude on request), scan-notes-index (per-page search metadata), and scan-notes-stats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ZSvbNaLhgFuTm7wmkgbWs
This commit is contained in:
commit
e464871b69
29 changed files with 5296 additions and 0 deletions
103
tests/test_config.py
Normal file
103
tests/test_config.py
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
"""Confidential-folder declarations in the config file."""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from pdf_tools.companion import BASIC
|
||||
from pdf_tools.scan_config import load_config
|
||||
|
||||
EXAMPLE = Path(__file__).resolve().parent.parent / "scan-notes.example.toml"
|
||||
|
||||
|
||||
def cfg_from(tmp_path, text: str):
|
||||
p = tmp_path / "scan-notes.toml"
|
||||
p.write_text(text)
|
||||
return load_config(p)
|
||||
|
||||
|
||||
def test_nothing_built_in(tmp_path, monkeypatch):
|
||||
monkeypatch.delenv("PDF_TOOLS_SCAN_CONFIG", raising=False)
|
||||
monkeypatch.setattr("pdf_tools.scan_config.DEFAULT_CONFIG_PATH", tmp_path / "none.toml")
|
||||
cfg = load_config()
|
||||
assert cfg.confidential == []
|
||||
assert [h.url for h in cfg.hosts] == ["http://localhost:11434"]
|
||||
|
||||
|
||||
def test_example_file_loads():
|
||||
cfg = load_config(EXAMPLE)
|
||||
assert len(cfg.confidential) == 2
|
||||
basic, meetings = cfg.confidential
|
||||
assert basic.companion is BASIC
|
||||
assert meetings.companion.transcript_section == "Discussion"
|
||||
assert meetings.companion.fields == ["body", "committee"]
|
||||
assert [r.match for r in meetings.companion.paths][0] == "{body}/committees/{committee}/**"
|
||||
assert meetings.titles["BOD.short"] == "Board"
|
||||
|
||||
|
||||
def test_folder_without_companion_is_basic(tmp_path):
|
||||
cfg = cfg_from(tmp_path, f'[[confidential]]\nroot = "{tmp_path / "x"}"\n')
|
||||
assert cfg.confidential[0].companion is BASIC
|
||||
|
||||
|
||||
def test_transcript_section_defaults_to_first_section(tmp_path):
|
||||
cfg = cfg_from(tmp_path, f'[[confidential]]\nroot = "{tmp_path}"\n'
|
||||
'[confidential.companion]\nsections = ["Summary", "Log"]\n')
|
||||
assert cfg.confidential[0].companion.transcript_section == "Summary"
|
||||
|
||||
|
||||
def test_tilde_expanded_and_deepest_root_wins(tmp_path):
|
||||
outer, inner = tmp_path / "a", tmp_path / "a" / "b"
|
||||
cfg = cfg_from(tmp_path,
|
||||
f'[[confidential]]\nroot = "{outer}"\n\n'
|
||||
f'[[confidential]]\nroot = "{inner}"\n')
|
||||
assert cfg.confidential_folder(inner / "c" / "s.pdf").root == inner
|
||||
assert cfg.confidential_folder(outer / "s.pdf").root == outer
|
||||
assert cfg.confidential_folder(tmp_path / "other.pdf") is None
|
||||
# A sibling whose name merely starts with the root's name is not inside it.
|
||||
assert cfg.confidential_folder(tmp_path / "ab" / "s.pdf") is None
|
||||
cfg = cfg_from(tmp_path, '[[confidential]]\nroot = "~/somewhere"\n')
|
||||
assert cfg.confidential[0].root == Path.home() / "somewhere"
|
||||
|
||||
|
||||
def test_names_are_per_folder(tmp_path):
|
||||
a, b = tmp_path / "a", tmp_path / "b"
|
||||
cfg = cfg_from(tmp_path, f'names = ["Everyone"]\n'
|
||||
f'[[confidential]]\nroot = "{a}"\nnames = ["Alpha", "Everyone"]\n'
|
||||
f'[[confidential]]\nroot = "{b}"\nnames = ["Beta"]\n')
|
||||
fa, fb = cfg.confidential
|
||||
assert cfg.names_for(fa) == ["Everyone", "Alpha"]
|
||||
assert cfg.names_for(fb) == ["Everyone", "Beta"]
|
||||
assert cfg.names_for(None) == ["Everyone"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
'[[confidential]]\nnames = []\n', # no root
|
||||
'[[confidential]]\nroot = "/x"\ncompanion = "acme"\n', # old string form
|
||||
'[[confidential]]\nroot = "/x"\nnmaes = []\n', # typo
|
||||
'[[confidential]]\nroot = "/x"\n[confidential.companion]\nsectoins = []\n',
|
||||
'[[confidential]]\nroot = "/x"\n[[confidential.companion.paths]]\ntitle = "t"\n',
|
||||
# A top-level key written after a host table lands inside that table.
|
||||
'[[ollama.hosts]]\nname = "l"\nurl = "http://x"\nmodel = "m"\nprompt_extra = "x"\n',
|
||||
'[ollama]\ntimeout_s = 5\nnames = []\n',
|
||||
'prompt_extar = "x"\n',
|
||||
])
|
||||
def test_bad_entries_rejected(tmp_path, text):
|
||||
with pytest.raises(SystemExit):
|
||||
cfg_from(tmp_path, text)
|
||||
|
||||
|
||||
def test_prompt_extra_top_level_and_per_folder(tmp_path):
|
||||
a, b = tmp_path / "a", tmp_path / "b"
|
||||
cfg = cfg_from(tmp_path, 'prompt_extra = "Figures."\n'
|
||||
f'[[confidential]]\nroot = "{a}"\nprompt_extra = "Board terms."\n'
|
||||
f'[[confidential]]\nroot = "{b}"\n')
|
||||
fa, fb = cfg.confidential
|
||||
assert cfg.extras_for(fa) == ["Figures.", "Board terms."]
|
||||
assert cfg.extras_for(fb) == ["Figures."]
|
||||
assert cfg.extras_for(None) == ["Figures."]
|
||||
|
||||
|
||||
def test_example_prompt_extra_mentions_figures():
|
||||
assert "[FIGURE:" in load_config(EXAMPLE).prompt_extra
|
||||
Loading…
Add table
Add a link
Reference in a new issue