Randomize questions on every Anki regen

Also make explanation section slightly more readable
This commit is contained in:
2026-06-04 11:10:08 +02:00
parent 7bf6f98ee2
commit fdc5932d7d
5 changed files with 105 additions and 17 deletions
+46
View File
@@ -11,6 +11,7 @@ import tempfile
import unittest
import zipfile
from pathlib import Path
from unittest.mock import patch
import amateurfunk_anki as aa
@@ -108,6 +109,24 @@ def extract_collection(apkg_path: Path, tmp: Path):
return tmp / "collection.anki2", media, names
class TestResolveShuffleSeed(unittest.TestCase):
"""Unit coverage for the shuffle-seed resolution itself.
The CLI-level test patches `resolve_shuffle_seed` out, so the
actual default-seed behavior is only exercised here.
"""
def test_explicit_seed_is_passed_through(self):
self.assertEqual(aa.resolve_shuffle_seed("my-seed"), "my-seed")
def test_omitted_seed_mints_a_fresh_value_each_call(self):
first = aa.resolve_shuffle_seed(None)
second = aa.resolve_shuffle_seed(None)
self.assertIsInstance(first, str)
self.assertTrue(first)
self.assertNotEqual(first, second)
class TestAnkiBuild(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
@@ -479,6 +498,7 @@ class TestAnkiBuild(unittest.TestCase):
common = [
"--data", str(self.data_dir),
"--explanations", str(self.explanations_path),
"--seed", "stable-test-seed",
"--epoch", "1234567890",
]
aa.main([*common, "--out", str(out_a)])
@@ -488,6 +508,32 @@ class TestAnkiBuild(unittest.TestCase):
second = out_b / first.name
self.assertEqual(first.read_bytes(), second.read_bytes(), first.name)
def test_cli_without_seed_reshuffles_each_build(self):
out_a = self.root / "anki-fresh-a"
out_b = self.root / "anki-fresh-b"
common = [
"--data", str(self.data_dir),
"--explanations", str(self.explanations_path),
"--epoch", "1234567890",
]
with patch(
"amateurfunk_anki.resolve_shuffle_seed",
side_effect=["fresh-a", "fresh-b"],
) as resolve_seed:
aa.main([*common, "--out", str(out_a)])
aa.main([*common, "--out", str(out_b)])
resolved_inputs = [
call.args[0] for call in resolve_seed.call_args_list
]
self.assertEqual(resolved_inputs, [None, None])
byte_equal = [
first.read_bytes() == (out_b / first.name).read_bytes()
for first in sorted(out_a.glob("*.apkg"))
]
self.assertFalse(all(byte_equal))
class TestRealExplanationsFile(unittest.TestCase):
"""Validate the repo's actual explanations.json against the live catalog.