blob: 6490e589c913812c6263a02c7df1f41e15319d4a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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"
|