mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
update new card unit test
This commit is contained in:
parent
3f92254e1a
commit
4f2ecda980
3 changed files with 28 additions and 68 deletions
71
anki/deck.py
71
anki/deck.py
|
@ -76,6 +76,10 @@ class _Deck(object):
|
|||
self.sched = Scheduler(self)
|
||||
self.media = MediaRegistry(self)
|
||||
|
||||
def name(self):
|
||||
n = os.path.splitext(os.path.basename(self.path))[0]
|
||||
return n
|
||||
|
||||
# DB-related
|
||||
##########################################################################
|
||||
|
||||
|
@ -165,6 +169,7 @@ qconf=?, conf=?, data=?""",
|
|||
def reset(self):
|
||||
self.sched.reset()
|
||||
|
||||
|
||||
# Times
|
||||
##########################################################################
|
||||
|
||||
|
@ -1051,17 +1056,6 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
|
|||
def disableProgressHandler(self):
|
||||
self.progressHandlerEnabled = False
|
||||
|
||||
# File-related
|
||||
##########################################################################
|
||||
|
||||
def name(self):
|
||||
if not self.path:
|
||||
return u"untitled"
|
||||
n = os.path.splitext(os.path.basename(self.path))[0]
|
||||
assert '/' not in n
|
||||
assert '\\' not in n
|
||||
return n
|
||||
|
||||
# Timeboxing
|
||||
##########################################################################
|
||||
|
||||
|
@ -1088,48 +1082,6 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
|
|||
return True
|
||||
return False
|
||||
|
||||
# Failed card handling
|
||||
##########################################################################
|
||||
|
||||
def setFailedCardPolicy(self, idx):
|
||||
if idx == 5:
|
||||
# custom
|
||||
return
|
||||
self.collapseTime = 0
|
||||
self.failedCardMax = 0
|
||||
if idx == 0:
|
||||
d = 600
|
||||
self.collapseTime = 1
|
||||
self.failedCardMax = 20
|
||||
elif idx == 1:
|
||||
d = 0
|
||||
elif idx == 2:
|
||||
d = 600
|
||||
elif idx == 3:
|
||||
d = 28800
|
||||
elif idx == 4:
|
||||
d = 259200
|
||||
self.delay0 = d
|
||||
self.delay1 = 0
|
||||
|
||||
def getFailedCardPolicy(self):
|
||||
if self.delay1:
|
||||
return 5
|
||||
d = self.delay0
|
||||
if self.collapseTime == 1:
|
||||
if d == 600 and self.failedCardMax == 20:
|
||||
return 0
|
||||
return 5
|
||||
if d == 0 and self.failedCardMax == 0:
|
||||
return 1
|
||||
elif d == 600:
|
||||
return 2
|
||||
elif d == 28800:
|
||||
return 3
|
||||
elif d == 259200:
|
||||
return 4
|
||||
return 5
|
||||
|
||||
# Syncing
|
||||
##########################################################################
|
||||
|
||||
|
@ -1478,16 +1430,3 @@ seq > :s and seq <= :e order by seq desc""", s=start, e=end)
|
|||
self.db.execute("create index ix_cards_multi on cards (%s)" %
|
||||
", ".join(cols))
|
||||
self.db.execute("analyze")
|
||||
|
||||
# Shared decks
|
||||
##########################################################################
|
||||
|
||||
# sourcesTable = Table(
|
||||
# 'sources', metadata,
|
||||
# Column('id', Integer, nullable=False, primary_key=True),
|
||||
# Column('name', UnicodeText, nullable=False, default=""),
|
||||
# Column('created', Integer, nullable=False, default=intTime),
|
||||
# Column('lastSync', Integer, nullable=False, default=0),
|
||||
# # -1 = never check, 0 = always check, 1+ = number of seconds passed.
|
||||
# # not currently exposed in the GUI
|
||||
# Column('syncPeriod', Integer, nullable=False, default=0))
|
||||
|
|
|
@ -16,6 +16,10 @@ def Deck(path, queue=True):
|
|||
"Open a new or existing deck. Path must be unicode."
|
||||
path = os.path.abspath(path)
|
||||
create = not os.path.exists(path)
|
||||
if create:
|
||||
base = os.path.basename(path)
|
||||
for c in ("/", ":", "\\"):
|
||||
assert c not in base
|
||||
# connect
|
||||
db = DB(path)
|
||||
if create:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import time
|
||||
from tests.shared import assertException, getEmptyDeck
|
||||
from anki.stdmodels import BasicModel
|
||||
#from anki.db import *
|
||||
from anki.utils import stripHTML
|
||||
|
||||
def test_basics():
|
||||
d = getEmptyDeck()
|
||||
|
@ -15,7 +15,7 @@ def test_new():
|
|||
# add a fact
|
||||
f = d.newFact()
|
||||
f['Front'] = u"one"; f['Back'] = u"two"
|
||||
f = d.addFact(f)
|
||||
d.addFact(f)
|
||||
d.reset()
|
||||
assert d.sched.newCount == 1
|
||||
# fetch it
|
||||
|
@ -27,6 +27,23 @@ def test_new():
|
|||
d.sched.answerCard(c, 1)
|
||||
assert c.queue == 0
|
||||
assert c.type == 2
|
||||
# the default order should ensure siblings are not seen together, and
|
||||
# should show all cards
|
||||
m = d.currentModel()
|
||||
m.templates[1].active = True
|
||||
m.flush()
|
||||
f = d.newFact()
|
||||
f['Front'] = u"2"; f['Back'] = u"2"
|
||||
d.addFact(f)
|
||||
f = d.newFact()
|
||||
f['Front'] = u"3"; f['Back'] = u"3"
|
||||
d.addFact(f)
|
||||
d.reset()
|
||||
qs = ("2", "3", "2", "3")
|
||||
for n in range(4):
|
||||
c = d.sched.getCard()
|
||||
assert(stripHTML(c.q()) == qs[n])
|
||||
d.sched.answerCard(c, 2)
|
||||
|
||||
def test_learn():
|
||||
d = getEmptyDeck()
|
||||
|
|
Loading…
Reference in a new issue