diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-30 13:07:16 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-30 13:07:16 -0500 |
| commit | 038d59b7e548d2323f43dcd92ba14cba876d840d (patch) | |
| tree | 34f468689b3e4549918f1307d83ad8fda4eea7fa /.ai/scripts/tests | |
| parent | 23d87c187c950b047fd44ecb9c3d825b37712fc0 (diff) | |
| download | rulesets-038d59b7e548d2323f43dcd92ba14cba876d840d.tar.gz rulesets-038d59b7e548d2323f43dcd92ba14cba876d840d.zip | |
feat(drill-to-anki): default to phone sync dir and basename deck name
Two default-behavior tweaks from real use. Output now defaults to ~/sync/phone/anki/ instead of ~/sync/org/drill/. The .apkg is a mobile-Anki artifact the phone picks up from its sync dir, while the org source stays in the project. Deck name now defaults to the raw input basename, case preserved. That drops the #+TITLE preference, which leaked tool-name jargon like "DeepSat org-drill flashcards" into the Anki deck list.
The --deck and --output flags still override both. I dropped the now-unused title_from_org helper and added a test covering the two defaults. genanki is stubbed in the test since uv resolves it only at runtime.
Diffstat (limited to '.ai/scripts/tests')
| -rw-r--r-- | .ai/scripts/tests/test_drill_to_anki.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/.ai/scripts/tests/test_drill_to_anki.py b/.ai/scripts/tests/test_drill_to_anki.py new file mode 100644 index 0000000..6490e58 --- /dev/null +++ b/.ai/scripts/tests/test_drill_to_anki.py @@ -0,0 +1,44 @@ +"""Tests for drill-to-anki.py default-path and deck-name helpers. + +The script is a PEP 723 uv-run script that imports genanki, which uv resolves +at runtime but isn't installed in the test environment. The fixture stubs +genanki in sys.modules so the module loads; the pure helpers under test never +call into it. +""" +from __future__ import annotations + +import importlib.util +import sys +import types +from pathlib import Path + +import pytest + +SCRIPT = Path(__file__).resolve().parents[1] / "drill-to-anki.py" + + +@pytest.fixture(scope="module") +def drill(): + # Only stub when genanki is genuinely absent, so a real install isn't shadowed. + sys.modules.setdefault("genanki", types.ModuleType("genanki")) + spec = importlib.util.spec_from_file_location("drill_to_anki", SCRIPT) + assert spec and spec.loader + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def test_default_output_path_targets_phone_anki_dir(drill): + """The .apkg is a phone artifact, so it defaults under sync/phone/anki/.""" + result = drill.default_output_path(Path("/home/x/projects/health/health-drill.org")) + assert result == Path.home() / "sync" / "phone" / "anki" / "health-drill.apkg" + + +def test_default_deck_name_is_raw_basename(drill): + """Deck name is the input basename with case preserved; #+TITLE is ignored.""" + assert drill.default_deck_name(Path("/x/deepsat.org")) == "deepsat" + + +def test_default_deck_name_keeps_hyphens(drill): + """A hyphenated basename is kept verbatim rather than title-cased.""" + assert drill.default_deck_name(Path("/x/health-drill.org")) == "health-drill" |
