From 5b26b2069751dfdccfaac3a5b73a298ff510e236 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 30 Mar 2020 12:27:52 +1000 Subject: [PATCH] explicitly save deck conf after mutating it --- pylib/tests/test_schedv1.py | 37 ++++++++++++++++++++++++++--------- pylib/tests/test_schedv2.py | 39 +++++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index 822ab9a12..f3324ac91 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -101,11 +101,13 @@ def test_newLimits(): # limit the parent to 10 cards, meaning we get 10 in total conf1 = d.decks.confForDid(1) conf1["new"]["perDay"] = 10 + d.decks.save(conf1) d.reset() assert d.sched.newCount == 10 # if we limit child to 4, we should get 9 conf2 = d.decks.confForDid(g2) conf2["new"]["perDay"] = 4 + d.decks.save(conf2) d.reset() assert d.sched.newCount == 9 @@ -117,10 +119,13 @@ def test_newBoxes(): d.addNote(f) d.reset() c = d.sched.getCard() - d.sched._cardConf(c)["new"]["delays"] = [1, 2, 3, 4, 5] + conf = d.sched._cardConf(c) + conf["new"]["delays"] = [1, 2, 3, 4, 5] + d.decks.save(conf) d.sched.answerCard(c, 2) # should handle gracefully - d.sched._cardConf(c)["new"]["delays"] = [1] + conf["new"]["delays"] = [1] + d.decks.save(conf) d.sched.answerCard(c, 2) @@ -137,7 +142,9 @@ def test_learn(): # sched.getCard should return it, since it's due in the past c = d.sched.getCard() assert c - d.sched._cardConf(c)["new"]["delays"] = [0.5, 3, 10] + conf = d.sched._cardConf(c) + conf["new"]["delays"] = [0.5, 3, 10] + d.decks.save(conf) # fail it d.sched.answerCard(c, 1) # it should have three reps left to graduation @@ -235,7 +242,9 @@ def test_learn_day(): f = d.addNote(f) d.sched.reset() c = d.sched.getCard() - d.sched._cardConf(c)["new"]["delays"] = [1, 10, 1440, 2880] + conf = d.sched._cardConf(c) + conf["new"]["delays"] = [1, 10, 1440, 2880] + d.decks.save(conf) # pass it d.sched.answerCard(c, 2) # two reps to graduate, 1 more today @@ -279,7 +288,9 @@ def test_learn_day(): c.flush() d.reset() assert d.sched.counts() == (0, 0, 1) - d.sched._cardConf(c)["lapse"]["delays"] = [1440] + conf = d.sched._cardConf(c) + conf["lapse"]["delays"] = [1440] + d.decks.save(conf) c = d.sched.getCard() d.sched.answerCard(c, 1) assert c.queue == CARD_TYPE_RELEARNING @@ -310,7 +321,9 @@ def test_reviews(): ################################################## # different delay to new d.reset() - d.sched._cardConf(c)["lapse"]["delays"] = [2, 20] + conf = d.sched._cardConf(c) + conf["lapse"]["delays"] = [2, 20] + d.decks.save(conf) d.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN # it should be due tomorrow, with an interval of 1 @@ -471,6 +484,7 @@ def test_nextIvl(): conf = d.decks.confForDid(1) conf["new"]["delays"] = [0.5, 3, 10] conf["lapse"]["delays"] = [1, 5, 9] + d.decks.save(conf) c = d.sched.getCard() # new cards ################################################## @@ -508,7 +522,8 @@ def test_nextIvl(): # failing it should put it at 60s assert ni(c, 1) == 60 # or 1 day if relearn is false - d.sched._cardConf(c)["lapse"]["delays"] = [] + conf["lapse"]["delays"] = [] + d.decks.save(conf) assert ni(c, 1) == 1 * 86400 # (* 100 1.2 86400)10368000.0 assert ni(c, 2) == 10368000 @@ -941,7 +956,9 @@ def test_timing(): d.reset() c = d.sched.getCard() # set a a fail delay of 1 second so we don't have to wait - d.sched._cardConf(c)["lapse"]["delays"][0] = 1 / 60.0 + conf = d.sched._cardConf(c) + conf["lapse"]["delays"][0] = 1 / 60.0 + d.decks.save(conf) d.sched.answerCard(c, 1) # the next card should be another review c = d.sched.getCard() @@ -1171,7 +1188,9 @@ def test_failmult(): c.lapses = 1 c.startTimer() c.flush() - d.sched._cardConf(c)["lapse"]["mult"] = 0.5 + conf = d.sched._cardConf(c) + conf["lapse"]["mult"] = 0.5 + d.decks.save(conf) c = d.sched.getCard() d.sched.answerCard(c, 1) assert c.ivl == 50 diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index aabf811c8..f18e00e8e 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -101,11 +101,13 @@ def test_newLimits(): # limit the parent to 10 cards, meaning we get 10 in total conf1 = d.decks.confForDid(1) conf1["new"]["perDay"] = 10 + d.decks.save(conf1) d.reset() assert d.sched.newCount == 10 # if we limit child to 4, we should get 9 conf2 = d.decks.confForDid(g2) conf2["new"]["perDay"] = 4 + d.decks.save(conf2) d.reset() assert d.sched.newCount == 9 @@ -117,10 +119,13 @@ def test_newBoxes(): d.addNote(f) d.reset() c = d.sched.getCard() - d.sched._cardConf(c)["new"]["delays"] = [1, 2, 3, 4, 5] + conf = d.sched._cardConf(c) + conf["new"]["delays"] = [1, 2, 3, 4, 5] + d.decks.save(conf) d.sched.answerCard(c, 2) # should handle gracefully - d.sched._cardConf(c)["new"]["delays"] = [1] + conf["new"]["delays"] = [1] + d.decks.save(conf) d.sched.answerCard(c, 2) @@ -137,7 +142,9 @@ def test_learn(): # sched.getCard should return it, since it's due in the past c = d.sched.getCard() assert c - d.sched._cardConf(c)["new"]["delays"] = [0.5, 3, 10] + conf = d.sched._cardConf(c) + conf["new"]["delays"] = [0.5, 3, 10] + d.decks.save(conf) # fail it d.sched.answerCard(c, 1) # it should have three reps left to graduation @@ -270,7 +277,9 @@ def test_learn_day(): f = d.addNote(f) d.sched.reset() c = d.sched.getCard() - d.sched._cardConf(c)["new"]["delays"] = [1, 10, 1440, 2880] + conf = d.sched._cardConf(c) + conf["new"]["delays"] = [1, 10, 1440, 2880] + d.decks.save(conf) # pass it d.sched.answerCard(c, 3) # two reps to graduate, 1 more today @@ -314,7 +323,9 @@ def test_learn_day(): c.flush() d.reset() assert d.sched.counts() == (0, 0, 1) - d.sched._cardConf(c)["lapse"]["delays"] = [1440] + conf = d.sched._cardConf(c) + conf["lapse"]["delays"] = [1440] + d.decks.save(conf) c = d.sched.getCard() d.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_DAY_LEARN_RELEARN @@ -484,6 +495,7 @@ def test_button_spacing(): # if hard factor is <= 1, then hard may not increase conf = d.decks.confForDid(1) conf["rev"]["hardFactor"] = 1 + d.decks.save(conf) assert wo(ni(c, 2)) == "1d" @@ -554,6 +566,7 @@ def test_nextIvl(): conf = d.decks.confForDid(1) conf["new"]["delays"] = [0.5, 3, 10] conf["lapse"]["delays"] = [1, 5, 9] + d.decks.save(conf) c = d.sched.getCard() # new cards ################################################## @@ -594,7 +607,8 @@ def test_nextIvl(): # failing it should put it at 60s assert ni(c, 1) == 60 # or 1 day if relearn is false - d.sched._cardConf(c)["lapse"]["delays"] = [] + conf["lapse"]["delays"] = [] + d.decks.save(conf) assert ni(c, 1) == 1 * 86400 # (* 100 1.2 86400)10368000.0 assert ni(c, 2) == 10368000 @@ -761,8 +775,9 @@ def test_filt_keep_lrn_state(): # fail the card outside filtered deck c = d.sched.getCard() - d.sched._cardConf(c)["new"]["delays"] = [1, 10, 61] - d.decks.save() + conf = d.sched._cardConf(c) + conf["new"]["delays"] = [1, 10, 61] + d.decks.save(conf) d.sched.answerCard(c, 1) @@ -1188,7 +1203,9 @@ def test_failmult(): c.lapses = 1 c.startTimer() c.flush() - d.sched._cardConf(c)["lapse"]["mult"] = 0.5 + conf = d.sched._cardConf(c) + conf["lapse"]["mult"] = 0.5 + d.decks.save(conf) c = d.sched.getCard() d.sched.answerCard(c, 1) assert c.ivl == 50 @@ -1242,7 +1259,9 @@ def test_moveVersions(): c.load() c.due = 0 c.flush() - col.sched._cardConf(c)["lapse"]["mult"] = 0.5 + conf = col.sched._cardConf(c) + conf["lapse"]["mult"] = 0.5 + col.decks.save(conf) col.sched.reset() c = col.sched.getCard() col.sched.answerCard(c, 1)