more unit tests, and unbury on close

This commit is contained in:
Damien Elmes 2011-03-18 08:34:51 +09:00
parent 5e0cc2ff5d
commit 17f3cabc25
3 changed files with 42 additions and 5 deletions

View file

@ -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()

View file

@ -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:

View file

@ -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