explicitly save deck conf after mutating it

This commit is contained in:
Damien Elmes 2020-03-30 12:27:52 +10:00
parent bf83715ee0
commit 5b26b20697
2 changed files with 57 additions and 19 deletions

View file

@ -101,11 +101,13 @@ def test_newLimits():
# limit the parent to 10 cards, meaning we get 10 in total # limit the parent to 10 cards, meaning we get 10 in total
conf1 = d.decks.confForDid(1) conf1 = d.decks.confForDid(1)
conf1["new"]["perDay"] = 10 conf1["new"]["perDay"] = 10
d.decks.save(conf1)
d.reset() d.reset()
assert d.sched.newCount == 10 assert d.sched.newCount == 10
# if we limit child to 4, we should get 9 # if we limit child to 4, we should get 9
conf2 = d.decks.confForDid(g2) conf2 = d.decks.confForDid(g2)
conf2["new"]["perDay"] = 4 conf2["new"]["perDay"] = 4
d.decks.save(conf2)
d.reset() d.reset()
assert d.sched.newCount == 9 assert d.sched.newCount == 9
@ -117,10 +119,13 @@ def test_newBoxes():
d.addNote(f) d.addNote(f)
d.reset() d.reset()
c = d.sched.getCard() 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) d.sched.answerCard(c, 2)
# should handle gracefully # should handle gracefully
d.sched._cardConf(c)["new"]["delays"] = [1] conf["new"]["delays"] = [1]
d.decks.save(conf)
d.sched.answerCard(c, 2) d.sched.answerCard(c, 2)
@ -137,7 +142,9 @@ def test_learn():
# sched.getCard should return it, since it's due in the past # sched.getCard should return it, since it's due in the past
c = d.sched.getCard() c = d.sched.getCard()
assert c 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 # fail it
d.sched.answerCard(c, 1) d.sched.answerCard(c, 1)
# it should have three reps left to graduation # it should have three reps left to graduation
@ -235,7 +242,9 @@ def test_learn_day():
f = d.addNote(f) f = d.addNote(f)
d.sched.reset() d.sched.reset()
c = d.sched.getCard() 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 # pass it
d.sched.answerCard(c, 2) d.sched.answerCard(c, 2)
# two reps to graduate, 1 more today # two reps to graduate, 1 more today
@ -279,7 +288,9 @@ def test_learn_day():
c.flush() c.flush()
d.reset() d.reset()
assert d.sched.counts() == (0, 0, 1) 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() c = d.sched.getCard()
d.sched.answerCard(c, 1) d.sched.answerCard(c, 1)
assert c.queue == CARD_TYPE_RELEARNING assert c.queue == CARD_TYPE_RELEARNING
@ -310,7 +321,9 @@ def test_reviews():
################################################## ##################################################
# different delay to new # different delay to new
d.reset() 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) d.sched.answerCard(c, 1)
assert c.queue == QUEUE_TYPE_LRN assert c.queue == QUEUE_TYPE_LRN
# it should be due tomorrow, with an interval of 1 # it should be due tomorrow, with an interval of 1
@ -471,6 +484,7 @@ def test_nextIvl():
conf = d.decks.confForDid(1) conf = d.decks.confForDid(1)
conf["new"]["delays"] = [0.5, 3, 10] conf["new"]["delays"] = [0.5, 3, 10]
conf["lapse"]["delays"] = [1, 5, 9] conf["lapse"]["delays"] = [1, 5, 9]
d.decks.save(conf)
c = d.sched.getCard() c = d.sched.getCard()
# new cards # new cards
################################################## ##################################################
@ -508,7 +522,8 @@ def test_nextIvl():
# failing it should put it at 60s # failing it should put it at 60s
assert ni(c, 1) == 60 assert ni(c, 1) == 60
# or 1 day if relearn is false # 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 assert ni(c, 1) == 1 * 86400
# (* 100 1.2 86400)10368000.0 # (* 100 1.2 86400)10368000.0
assert ni(c, 2) == 10368000 assert ni(c, 2) == 10368000
@ -941,7 +956,9 @@ def test_timing():
d.reset() d.reset()
c = d.sched.getCard() c = d.sched.getCard()
# set a a fail delay of 1 second so we don't have to wait # 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) d.sched.answerCard(c, 1)
# the next card should be another review # the next card should be another review
c = d.sched.getCard() c = d.sched.getCard()
@ -1171,7 +1188,9 @@ def test_failmult():
c.lapses = 1 c.lapses = 1
c.startTimer() c.startTimer()
c.flush() 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() c = d.sched.getCard()
d.sched.answerCard(c, 1) d.sched.answerCard(c, 1)
assert c.ivl == 50 assert c.ivl == 50

View file

@ -101,11 +101,13 @@ def test_newLimits():
# limit the parent to 10 cards, meaning we get 10 in total # limit the parent to 10 cards, meaning we get 10 in total
conf1 = d.decks.confForDid(1) conf1 = d.decks.confForDid(1)
conf1["new"]["perDay"] = 10 conf1["new"]["perDay"] = 10
d.decks.save(conf1)
d.reset() d.reset()
assert d.sched.newCount == 10 assert d.sched.newCount == 10
# if we limit child to 4, we should get 9 # if we limit child to 4, we should get 9
conf2 = d.decks.confForDid(g2) conf2 = d.decks.confForDid(g2)
conf2["new"]["perDay"] = 4 conf2["new"]["perDay"] = 4
d.decks.save(conf2)
d.reset() d.reset()
assert d.sched.newCount == 9 assert d.sched.newCount == 9
@ -117,10 +119,13 @@ def test_newBoxes():
d.addNote(f) d.addNote(f)
d.reset() d.reset()
c = d.sched.getCard() 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) d.sched.answerCard(c, 2)
# should handle gracefully # should handle gracefully
d.sched._cardConf(c)["new"]["delays"] = [1] conf["new"]["delays"] = [1]
d.decks.save(conf)
d.sched.answerCard(c, 2) d.sched.answerCard(c, 2)
@ -137,7 +142,9 @@ def test_learn():
# sched.getCard should return it, since it's due in the past # sched.getCard should return it, since it's due in the past
c = d.sched.getCard() c = d.sched.getCard()
assert c 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 # fail it
d.sched.answerCard(c, 1) d.sched.answerCard(c, 1)
# it should have three reps left to graduation # it should have three reps left to graduation
@ -270,7 +277,9 @@ def test_learn_day():
f = d.addNote(f) f = d.addNote(f)
d.sched.reset() d.sched.reset()
c = d.sched.getCard() 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 # pass it
d.sched.answerCard(c, 3) d.sched.answerCard(c, 3)
# two reps to graduate, 1 more today # two reps to graduate, 1 more today
@ -314,7 +323,9 @@ def test_learn_day():
c.flush() c.flush()
d.reset() d.reset()
assert d.sched.counts() == (0, 0, 1) 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() c = d.sched.getCard()
d.sched.answerCard(c, 1) d.sched.answerCard(c, 1)
assert c.queue == QUEUE_TYPE_DAY_LEARN_RELEARN 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 # if hard factor is <= 1, then hard may not increase
conf = d.decks.confForDid(1) conf = d.decks.confForDid(1)
conf["rev"]["hardFactor"] = 1 conf["rev"]["hardFactor"] = 1
d.decks.save(conf)
assert wo(ni(c, 2)) == "1d" assert wo(ni(c, 2)) == "1d"
@ -554,6 +566,7 @@ def test_nextIvl():
conf = d.decks.confForDid(1) conf = d.decks.confForDid(1)
conf["new"]["delays"] = [0.5, 3, 10] conf["new"]["delays"] = [0.5, 3, 10]
conf["lapse"]["delays"] = [1, 5, 9] conf["lapse"]["delays"] = [1, 5, 9]
d.decks.save(conf)
c = d.sched.getCard() c = d.sched.getCard()
# new cards # new cards
################################################## ##################################################
@ -594,7 +607,8 @@ def test_nextIvl():
# failing it should put it at 60s # failing it should put it at 60s
assert ni(c, 1) == 60 assert ni(c, 1) == 60
# or 1 day if relearn is false # 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 assert ni(c, 1) == 1 * 86400
# (* 100 1.2 86400)10368000.0 # (* 100 1.2 86400)10368000.0
assert ni(c, 2) == 10368000 assert ni(c, 2) == 10368000
@ -761,8 +775,9 @@ def test_filt_keep_lrn_state():
# fail the card outside filtered deck # fail the card outside filtered deck
c = d.sched.getCard() c = d.sched.getCard()
d.sched._cardConf(c)["new"]["delays"] = [1, 10, 61] conf = d.sched._cardConf(c)
d.decks.save() conf["new"]["delays"] = [1, 10, 61]
d.decks.save(conf)
d.sched.answerCard(c, 1) d.sched.answerCard(c, 1)
@ -1188,7 +1203,9 @@ def test_failmult():
c.lapses = 1 c.lapses = 1
c.startTimer() c.startTimer()
c.flush() 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() c = d.sched.getCard()
d.sched.answerCard(c, 1) d.sched.answerCard(c, 1)
assert c.ivl == 50 assert c.ivl == 50
@ -1242,7 +1259,9 @@ def test_moveVersions():
c.load() c.load()
c.due = 0 c.due = 0
c.flush() 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() col.sched.reset()
c = col.sched.getCard() c = col.sched.getCard()
col.sched.answerCard(c, 1) col.sched.answerCard(c, 1)