mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
more unit tests, and unbury on close
This commit is contained in:
parent
5e0cc2ff5d
commit
17f3cabc25
3 changed files with 42 additions and 5 deletions
|
@ -120,6 +120,7 @@ qconf=?, conf=?, data=?""",
|
||||||
|
|
||||||
def close(self, save=True):
|
def close(self, save=True):
|
||||||
"Disconnect from DB."
|
"Disconnect from DB."
|
||||||
|
self.sched.onClose()
|
||||||
if self.db:
|
if self.db:
|
||||||
if save:
|
if save:
|
||||||
self.save()
|
self.save()
|
||||||
|
|
|
@ -61,6 +61,16 @@ class Scheduler(object):
|
||||||
def cardQueue(self, card):
|
def cardQueue(self, card):
|
||||||
return card.queue
|
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
|
# 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)
|
self.confCache[id] = self.deck.groupConf(id)
|
||||||
return self.confCache[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):
|
def _groupLimit(self, type):
|
||||||
l = self.deck.activeGroups(type)
|
l = self.deck.activeGroups(type)
|
||||||
if not l:
|
if not l:
|
||||||
|
|
|
@ -269,3 +269,34 @@ def test_nextIvl():
|
||||||
# (* 100 2.5 1.3 86400)28080000.0
|
# (* 100 2.5 1.3 86400)28080000.0
|
||||||
assert ni(c, 4) == 28080000
|
assert ni(c, 4) == 28080000
|
||||||
print d.sched.nextIvlStr(c, 4) == "10.8 months"
|
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
|
||||||
|
|
Loading…
Reference in a new issue