anki/tests/test_undo.py
Damien Elmes afde11671e rework sibling handling and change bury semantics
First, burying changes:

- unburying now happens on day rollover, or when manually unburying from
  overview screen

- burying is not performed when returning to deck list, or when closing
  collection, so burying now must mark cards as modified to ensure sync
  consistent

- because they're no longer temporary to a session, make sure we exclude them
  in filtered decks in -is:suspended

Sibling spacing changes:

- core behaviour now based on automatically burying related cards when we
  answer a card

- applies to reviews, optionally to new cards, and never to cards in the
  learning queue (partly because we can't suspend/bury cards in that queue at
  the moment)

- this means spacing works consistently in filtered decks now, works on
  reviews even when user is late to review, and provides better separation of
  new cards

- if burying new cards disabled, we just discard them from the current queue.
  an option to set due=ord*space+due would be nicer, but would require
  changing a lot of code and is more appropriate for a future major version
  change. discarding from queue suffers from the same issue as the new card
  cycling in that queue rebuilds may cause cards to be shown close together,
  so the default burying behaviour is preferable

- refer to them as 'related cards' rather than 'siblings'

These changes don't require any changes to the database format, so they
should hopefully coexist with older clients without issue.
2013-08-10 15:56:26 +09:00

90 lines
2.2 KiB
Python

# coding: utf-8
import time
from tests.shared import getEmptyDeck
from anki.consts import *
def test_op():
d = getEmptyDeck()
# should have no undo by default
assert not d.undoName()
# let's adjust a study option
d.save("studyopts")
d.conf['abc'] = 5
# it should be listed as undoable
assert d.undoName() == "studyopts"
# with about 5 minutes until it's clobbered
assert time.time() - d._lastSave < 1
# undoing should restore the old value
d.undo()
assert not d.undoName()
assert 'abc' not in d.conf
# an (auto)save will clear the undo
d.save("foo")
assert d.undoName() == "foo"
d.save()
assert not d.undoName()
# and a review will, too
d.save("add")
f = d.newNote()
f['Front'] = u"one"
d.addNote(f)
d.reset()
assert d.undoName() == "add"
c = d.sched.getCard()
d.sched.answerCard(c, 2)
assert d.undoName() == "Review"
def test_review():
d = getEmptyDeck()
d.conf['counts'] = COUNT_REMAINING
f = d.newNote()
f['Front'] = u"one"
d.addNote(f)
d.reset()
assert not d.undoName()
# answer
assert d.sched.counts() == (1, 0, 0)
c = d.sched.getCard()
assert c.queue == 0
d.sched.answerCard(c, 2)
assert c.left == 1001
assert d.sched.counts() == (0, 1, 0)
assert c.queue == 1
# undo
assert d.undoName()
d.undo()
d.reset()
assert d.sched.counts() == (1, 0, 0)
c.load()
assert c.queue == 0
assert c.left != 1001
assert not d.undoName()
# we should be able to undo multiple answers too
f = d.newNote()
f['Front'] = u"two"
d.addNote(f)
d.reset()
assert d.sched.counts() == (2, 0, 0)
c = d.sched.getCard()
d.sched.answerCard(c, 2)
c = d.sched.getCard()
d.sched.answerCard(c, 2)
assert d.sched.counts() == (0, 2, 0)
d.undo()
d.reset()
assert d.sched.counts() == (1, 1, 0)
d.undo()
d.reset()
assert d.sched.counts() == (2, 0, 0)
# performing a normal op will clear the review queue
c = d.sched.getCard()
d.sched.answerCard(c, 2)
assert d.undoName() == "Review"
d.save("foo")
assert d.undoName() == "foo"
d.undo()
assert not d.undoName()