5ae66af5d2
- Rework V2 upgrade so that it no longer resets cards in learning, or empties filtered decks. - V1 users will receive a message at the top of the deck list encouraging them to upgrade, and they can upgrade directly from that screen. - The setting in the preferences screen has been removed, so users will need to use an older Anki version if they wish to switch back to V1. - Prevent V2 exports with scheduling from being importable into a V1 collection - the code was previously allowing this when it shouldn't have been. - New collections still default to v1 at the moment. Also add helper to get map of decks and deck configs, as there were a few places in the codebase where that was required.
97 lines
2.5 KiB
Python
97 lines
2.5 KiB
Python
# coding: utf-8
|
|
|
|
import time
|
|
|
|
from anki.consts import *
|
|
from tests.shared import getEmptyCol as getEmptyColOrig
|
|
|
|
|
|
def getEmptyCol():
|
|
col = getEmptyColOrig()
|
|
col.upgrade_to_v2_scheduler()
|
|
return col
|
|
|
|
|
|
def test_op():
|
|
col = getEmptyCol()
|
|
# should have no undo by default
|
|
assert not col.undoName()
|
|
# let's adjust a study option
|
|
col.save("studyopts")
|
|
col.conf["abc"] = 5
|
|
# it should be listed as undoable
|
|
assert col.undoName() == "studyopts"
|
|
# with about 5 minutes until it's clobbered
|
|
assert time.time() - col._lastSave < 1
|
|
# undoing should restore the old value
|
|
col.undo()
|
|
assert not col.undoName()
|
|
assert "abc" not in col.conf
|
|
# an (auto)save will clear the undo
|
|
col.save("foo")
|
|
assert col.undoName() == "foo"
|
|
col.save()
|
|
assert not col.undoName()
|
|
# and a review will, too
|
|
col.save("add")
|
|
note = col.newNote()
|
|
note["Front"] = "one"
|
|
col.addNote(note)
|
|
col.reset()
|
|
assert col.undoName() == "add"
|
|
c = col.sched.getCard()
|
|
col.sched.answerCard(c, 2)
|
|
assert col.undoName() == "Review"
|
|
|
|
|
|
def test_review():
|
|
col = getEmptyCol()
|
|
col.conf["counts"] = COUNT_REMAINING
|
|
note = col.newNote()
|
|
note["Front"] = "one"
|
|
col.addNote(note)
|
|
col.reset()
|
|
assert not col.undoName()
|
|
# answer
|
|
assert col.sched.counts() == (1, 0, 0)
|
|
c = col.sched.getCard()
|
|
assert c.queue == QUEUE_TYPE_NEW
|
|
col.sched.answerCard(c, 3)
|
|
assert c.left == 1001
|
|
assert col.sched.counts() == (0, 1, 0)
|
|
assert c.queue == QUEUE_TYPE_LRN
|
|
# undo
|
|
assert col.undoName()
|
|
col.undo()
|
|
col.reset()
|
|
assert col.sched.counts() == (1, 0, 0)
|
|
c.load()
|
|
assert c.queue == QUEUE_TYPE_NEW
|
|
assert c.left != 1001
|
|
assert not col.undoName()
|
|
# we should be able to undo multiple answers too
|
|
note = col.newNote()
|
|
note["Front"] = "two"
|
|
col.addNote(note)
|
|
col.reset()
|
|
assert col.sched.counts() == (2, 0, 0)
|
|
c = col.sched.getCard()
|
|
col.sched.answerCard(c, 3)
|
|
c = col.sched.getCard()
|
|
col.sched.answerCard(c, 3)
|
|
assert col.sched.counts() == (0, 2, 0)
|
|
col.undo()
|
|
col.reset()
|
|
assert col.sched.counts() == (1, 1, 0)
|
|
col.undo()
|
|
col.reset()
|
|
assert col.sched.counts() == (2, 0, 0)
|
|
# performing a normal op will clear the review queue
|
|
c = col.sched.getCard()
|
|
col.sched.answerCard(c, 3)
|
|
assert col.undoName() == "Review"
|
|
col.save("foo")
|
|
assert col.undoName() == "foo"
|
|
col.undo()
|
|
assert not col.undoName()
|