update tests

This commit is contained in:
Damien Elmes 2018-01-14 16:58:12 +10:00
parent cf6d85baa4
commit ea82126fcb
5 changed files with 1165 additions and 5 deletions

View File

@ -12,7 +12,7 @@ def assertException(exception, func):
# Creating new decks is expensive. Just do it once, and then spin off
# copies from the master.
def getEmptyCol():
def getEmptyCol(schedVer=1):
if len(getEmptyCol.master) == 0:
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
os.close(fd)
@ -22,7 +22,11 @@ def getEmptyCol():
getEmptyCol.master = nam
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
shutil.copy(getEmptyCol.master, nam)
return aopen(nam)
from anki.collection import _Collection
_Collection.defaultSchedulerVersion = schedVer
col = aopen(nam)
_Collection.defaultSchedulerVersion = 1
return col
getEmptyCol.master = ""

View File

@ -82,7 +82,7 @@ def test_export_ankipkg():
@nose.with_setup(setup1)
def test_export_anki_due():
deck = getEmptyCol()
deck = getEmptyCol(schedVer=2)
f = deck.newNote()
f['Front'] = "foo"
deck.addNote(f)

1115
tests/test_schedv1.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,10 +4,13 @@ import time
import copy
from anki.consts import STARTING_FACTOR
from tests.shared import getEmptyCol
from tests.shared import getEmptyCol as _getEmptyCol
from anki.utils import intTime
from anki.hooks import addHook
def getEmptyCol():
return _getEmptyCol(schedVer=2)
def test_clock():
d = getEmptyCol()
if (d.sched.dayCutoff - intTime()) < 10*60:
@ -1082,3 +1085,41 @@ def test_failmult():
# so the card is reset to new
d.sched.answerCard(c, 1)
assert c.ivl == 1
def test_moveVersions():
col = _getEmptyCol(schedVer=1)
n = col.newNote()
n['Front'] = "one"
col.addNote(n)
# make it a learning card
col.reset()
c = col.sched.getCard()
col.sched.answerCard(c, 1)
# the move to v2 should reset it to new
col.changeSchedulerVer(2)
c.load()
assert c.queue == 0
assert c.type == 0
# fail it again, and manually bury it
col.reset()
c = col.sched.getCard()
col.sched.answerCard(c, 1)
col.sched.buryCards([c.id])
c.load()
assert c.queue == -3
# revert to version 1
col.changeSchedulerVer(1)
# card should have moved queues
c.load()
assert c.queue == -2
# and it should be new again when unburied
col.sched.unburyCards()
c.load()
assert c.queue == c.type == 0

View File

@ -36,7 +36,7 @@ def test_op():
assert d.undoName() == "Review"
def test_review():
d = getEmptyCol()
d = getEmptyCol(schedVer=2)
d.conf['counts'] = COUNT_REMAINING
f = d.newNote()
f['Front'] = "one"