From 17f3cabc25fac421f16b1c899d69d850bc45ff86 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 18 Mar 2011 08:34:51 +0900 Subject: [PATCH] more unit tests, and unbury on close --- anki/deck.py | 1 + anki/sched.py | 15 ++++++++++----- tests/test_sched.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/anki/deck.py b/anki/deck.py index d9d6ab473..f2ba167ed 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -120,6 +120,7 @@ qconf=?, conf=?, data=?""", def close(self, save=True): "Disconnect from DB." + self.sched.onClose() if self.db: if save: self.save() diff --git a/anki/sched.py b/anki/sched.py index aaecd6175..164635c19 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -61,6 +61,16 @@ class Scheduler(object): def cardQueue(self, card): return card.queue + def onClose(self): + "Unbury and remove temporary suspends on close." + self.db.execute( + "update cards set queue = type where queue between -3 and -2") + + def _resetSchedBuried(self): + "Put temporarily suspended cards back into play." + self.db.execute( + "update cards set queue = type where queue = -3") + # Getting the next card ########################################################################## @@ -428,11 +438,6 @@ queue = 1 %s and due <= :lim order by %s limit %d""" % ( self.confCache[id] = self.deck.groupConf(id) return self.confCache[id] - def _resetSchedBuried(self): - "Put temporarily suspended cards back into play." - self.db.execute( - "update cards set queue = type where queue = -3") - def _groupLimit(self, type): l = self.deck.activeGroups(type) if not l: diff --git a/tests/test_sched.py b/tests/test_sched.py index 8055ddc3a..3a9b87921 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -269,3 +269,34 @@ def test_nextIvl(): # (* 100 2.5 1.3 86400)28080000.0 assert ni(c, 4) == 28080000 print d.sched.nextIvlStr(c, 4) == "10.8 months" + +def test_misc(): + d = getEmptyDeck() + f = d.newFact() + f['Front'] = u"one"; f['Back'] = u"two" + d.addFact(f) + c = f.cards()[0] + # suspending + d.reset() + assert d.sched.getCard() + d.sched.suspendCards([c.id]) + d.reset() + assert not d.sched.getCard() + # unsuspending + d.sched.unsuspendCards([c.id]) + d.reset() + assert d.sched.getCard() + # burying + d.sched.buryFact(c.fid) + d.reset() + assert not d.sched.getCard() + d.sched.onClose() + d.reset() + assert d.sched.getCard() + # counts + assert d.sched.timeToday() == 0 + assert d.sched.repsToday() == 0 + c.timerStarted = time.time() - 10 + d.sched.answerCard(c, 2) + assert d.sched.timeToday() > 0 + assert d.sched.repsToday() == 1