f->note in test
Obtained by sed -i "s/\bf\b/note/g" pylib/tests/*py qt/tests/*py
This commit is contained in:
parent
6a529e51cc
commit
4c25835d27
@ -5,11 +5,11 @@ from tests.shared import getEmptyCol
|
|||||||
|
|
||||||
def test_delete():
|
def test_delete():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = "2"
|
note["Back"] = "2"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
cid = f.cards()[0].id
|
cid = note.cards()[0].id
|
||||||
deck.reset()
|
deck.reset()
|
||||||
deck.sched.answerCard(deck.sched.getCard(), 2)
|
deck.sched.answerCard(deck.sched.getCard(), 2)
|
||||||
deck.remove_cards_and_orphaned_notes([cid])
|
deck.remove_cards_and_orphaned_notes([cid])
|
||||||
@ -22,22 +22,22 @@ def test_delete():
|
|||||||
|
|
||||||
def test_misc():
|
def test_misc():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = "2"
|
note["Back"] = "2"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
id = d.models.current()["id"]
|
id = d.models.current()["id"]
|
||||||
assert c.template()["ord"] == 0
|
assert c.template()["ord"] == 0
|
||||||
|
|
||||||
|
|
||||||
def test_genrem():
|
def test_genrem():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = ""
|
note["Back"] = ""
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert len(f.cards()) == 1
|
assert len(note.cards()) == 1
|
||||||
m = d.models.current()
|
m = d.models.current()
|
||||||
mm = d.models
|
mm = d.models
|
||||||
# adding a new template should automatically create cards
|
# adding a new template should automatically create cards
|
||||||
@ -46,7 +46,7 @@ def test_genrem():
|
|||||||
t["afmt"] = ""
|
t["afmt"] = ""
|
||||||
mm.addTemplate(m, t)
|
mm.addTemplate(m, t)
|
||||||
mm.save(m, templates=True)
|
mm.save(m, templates=True)
|
||||||
assert len(f.cards()) == 2
|
assert len(note.cards()) == 2
|
||||||
# if the template is changed to remove cards, they'll be removed
|
# if the template is changed to remove cards, they'll be removed
|
||||||
t = m["tmpls"][1]
|
t = m["tmpls"][1]
|
||||||
t["qfmt"] = "{{Back}}"
|
t["qfmt"] = "{{Back}}"
|
||||||
@ -54,40 +54,40 @@ def test_genrem():
|
|||||||
rep = d.backend.get_empty_cards()
|
rep = d.backend.get_empty_cards()
|
||||||
for n in rep.notes:
|
for n in rep.notes:
|
||||||
d.remove_cards_and_orphaned_notes(n.card_ids)
|
d.remove_cards_and_orphaned_notes(n.card_ids)
|
||||||
assert len(f.cards()) == 1
|
assert len(note.cards()) == 1
|
||||||
# if we add to the note, a card should be automatically generated
|
# if we add to the note, a card should be automatically generated
|
||||||
f.load()
|
note.load()
|
||||||
f["Back"] = "1"
|
note["Back"] = "1"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert len(f.cards()) == 2
|
assert len(note.cards()) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_gendeck():
|
def test_gendeck():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
cloze = d.models.byName("Cloze")
|
cloze = d.models.byName("Cloze")
|
||||||
d.models.setCurrent(cloze)
|
d.models.setCurrent(cloze)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = "{{c1::one}}"
|
note["Text"] = "{{c1::one}}"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert d.cardCount() == 1
|
assert d.cardCount() == 1
|
||||||
assert f.cards()[0].did == 1
|
assert note.cards()[0].did == 1
|
||||||
# set the model to a new default deck
|
# set the model to a new default deck
|
||||||
newId = d.decks.id("new")
|
newId = d.decks.id("new")
|
||||||
cloze["did"] = newId
|
cloze["did"] = newId
|
||||||
d.models.save(cloze, updateReqs=False)
|
d.models.save(cloze, updateReqs=False)
|
||||||
# a newly generated card should share the first card's deck
|
# a newly generated card should share the first card's deck
|
||||||
f["Text"] += "{{c2::two}}"
|
note["Text"] += "{{c2::two}}"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert f.cards()[1].did == 1
|
assert note.cards()[1].did == 1
|
||||||
# and same with multiple cards
|
# and same with multiple cards
|
||||||
f["Text"] += "{{c3::three}}"
|
note["Text"] += "{{c3::three}}"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert f.cards()[2].did == 1
|
assert note.cards()[2].did == 1
|
||||||
# if one of the cards is in a different deck, it should revert to the
|
# if one of the cards is in a different deck, it should revert to the
|
||||||
# model default
|
# model default
|
||||||
c = f.cards()[1]
|
c = note.cards()[1]
|
||||||
c.did = newId
|
c.did = newId
|
||||||
c.flush()
|
c.flush()
|
||||||
f["Text"] += "{{c4::four}}"
|
note["Text"] += "{{c4::four}}"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert f.cards()[3].did == newId
|
assert note.cards()[3].did == newId
|
||||||
|
@ -47,10 +47,10 @@ def test_create_open():
|
|||||||
def test_noteAddDelete():
|
def test_noteAddDelete():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
n = deck.addNote(f)
|
n = deck.addNote(note)
|
||||||
assert n == 1
|
assert n == 1
|
||||||
# test multiple cards - add another template
|
# test multiple cards - add another template
|
||||||
m = deck.models.current()
|
m = deck.models.current()
|
||||||
@ -62,17 +62,17 @@ def test_noteAddDelete():
|
|||||||
mm.save(m)
|
mm.save(m)
|
||||||
assert deck.cardCount() == 2
|
assert deck.cardCount() == 2
|
||||||
# creating new notes should use both cards
|
# creating new notes should use both cards
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
f["Back"] = "four"
|
note["Back"] = "four"
|
||||||
n = deck.addNote(f)
|
n = deck.addNote(note)
|
||||||
assert n == 2
|
assert n == 2
|
||||||
assert deck.cardCount() == 4
|
assert deck.cardCount() == 4
|
||||||
# check q/a generation
|
# check q/a generation
|
||||||
c0 = f.cards()[0]
|
c0 = note.cards()[0]
|
||||||
assert "three" in c0.q()
|
assert "three" in c0.q()
|
||||||
# it should not be a duplicate
|
# it should not be a duplicate
|
||||||
assert not f.dupeOrEmpty()
|
assert not note.dupeOrEmpty()
|
||||||
# now let's make a duplicate
|
# now let's make a duplicate
|
||||||
f2 = deck.newNote()
|
f2 = deck.newNote()
|
||||||
f2["Front"] = "one"
|
f2["Front"] = "one"
|
||||||
@ -85,36 +85,36 @@ def test_noteAddDelete():
|
|||||||
|
|
||||||
def test_fieldChecksum():
|
def test_fieldChecksum():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "new"
|
note["Front"] = "new"
|
||||||
f["Back"] = "new2"
|
note["Back"] = "new2"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
assert deck.db.scalar("select csum from notes") == int("c2a6b03f", 16)
|
assert deck.db.scalar("select csum from notes") == int("c2a6b03f", 16)
|
||||||
# changing the val should change the checksum
|
# changing the val should change the checksum
|
||||||
f["Front"] = "newx"
|
note["Front"] = "newx"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert deck.db.scalar("select csum from notes") == int("302811ae", 16)
|
assert deck.db.scalar("select csum from notes") == int("302811ae", 16)
|
||||||
|
|
||||||
|
|
||||||
def test_addDelTags():
|
def test_addDelTags():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
f2 = deck.newNote()
|
f2 = deck.newNote()
|
||||||
f2["Front"] = "2"
|
f2["Front"] = "2"
|
||||||
deck.addNote(f2)
|
deck.addNote(f2)
|
||||||
# adding for a given id
|
# adding for a given id
|
||||||
deck.tags.bulkAdd([f.id], "foo")
|
deck.tags.bulkAdd([note.id], "foo")
|
||||||
f.load()
|
note.load()
|
||||||
f2.load()
|
f2.load()
|
||||||
assert "foo" in f.tags
|
assert "foo" in note.tags
|
||||||
assert "foo" not in f2.tags
|
assert "foo" not in f2.tags
|
||||||
# should be canonified
|
# should be canonified
|
||||||
deck.tags.bulkAdd([f.id], "foo aaa")
|
deck.tags.bulkAdd([note.id], "foo aaa")
|
||||||
f.load()
|
note.load()
|
||||||
assert f.tags[0] == "aaa"
|
assert note.tags[0] == "aaa"
|
||||||
assert len(f.tags) == 2
|
assert len(note.tags) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_timestamps():
|
def test_timestamps():
|
||||||
|
@ -47,11 +47,11 @@ def test_remove():
|
|||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
# create a new deck, and add a note/card to it
|
# create a new deck, and add a note/card to it
|
||||||
g1 = deck.decks.id("g1")
|
g1 = deck.decks.id("g1")
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f.model()["did"] = g1
|
note.model()["did"] = g1
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
assert c.did == g1
|
assert c.did == g1
|
||||||
assert deck.cardCount() == 1
|
assert deck.cardCount() == 1
|
||||||
deck.decks.rem(g1)
|
deck.decks.rem(g1)
|
||||||
|
@ -24,17 +24,17 @@ testDir = os.path.dirname(__file__)
|
|||||||
def setup1():
|
def setup1():
|
||||||
global deck
|
global deck
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "foo"
|
note["Front"] = "foo"
|
||||||
f["Back"] = "bar<br>"
|
note["Back"] = "bar<br>"
|
||||||
f.tags = ["tag", "tag2"]
|
note.tags = ["tag", "tag2"]
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
# with a different deck
|
# with a different deck
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "baz"
|
note["Front"] = "baz"
|
||||||
f["Back"] = "qux"
|
note["Back"] = "qux"
|
||||||
f.model()["did"] = deck.decks.id("new deck")
|
note.model()["did"] = deck.decks.id("new deck")
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@ -85,8 +85,8 @@ def test_export_anki():
|
|||||||
def test_export_ankipkg():
|
def test_export_ankipkg():
|
||||||
setup1()
|
setup1()
|
||||||
# add a test file to the media folder
|
# add a test file to the media folder
|
||||||
with open(os.path.join(deck.media.dir(), "今日.mp3"), "w") as f:
|
with open(os.path.join(deck.media.dir(), "今日.mp3"), "w") as note:
|
||||||
f.write("test")
|
note.write("test")
|
||||||
n = deck.newNote()
|
n = deck.newNote()
|
||||||
n["Front"] = "[sound:今日.mp3]"
|
n["Front"] = "[sound:今日.mp3]"
|
||||||
deck.addNote(n)
|
deck.addNote(n)
|
||||||
@ -102,9 +102,9 @@ def test_export_ankipkg():
|
|||||||
def test_export_anki_due():
|
def test_export_anki_due():
|
||||||
setup1()
|
setup1()
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "foo"
|
note["Front"] = "foo"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
deck.crt -= 86400 * 10
|
deck.crt -= 86400 * 10
|
||||||
deck.flush()
|
deck.flush()
|
||||||
deck.sched.reset()
|
deck.sched.reset()
|
||||||
@ -136,27 +136,27 @@ def test_export_anki_due():
|
|||||||
# def test_export_textcard():
|
# def test_export_textcard():
|
||||||
# setup1()
|
# setup1()
|
||||||
# e = TextCardExporter(deck)
|
# e = TextCardExporter(deck)
|
||||||
# f = unicode(tempfile.mkstemp(prefix="ankitest")[1])
|
# note = unicode(tempfile.mkstemp(prefix="ankitest")[1])
|
||||||
# os.unlink(f)
|
# os.unlink(note)
|
||||||
# e.exportInto(f)
|
# e.exportInto(note)
|
||||||
# e.includeTags = True
|
# e.includeTags = True
|
||||||
# e.exportInto(f)
|
# e.exportInto(note)
|
||||||
|
|
||||||
|
|
||||||
def test_export_textnote():
|
def test_export_textnote():
|
||||||
setup1()
|
setup1()
|
||||||
e = TextNoteExporter(deck)
|
e = TextNoteExporter(deck)
|
||||||
fd, f = tempfile.mkstemp(prefix="ankitest")
|
fd, note = tempfile.mkstemp(prefix="ankitest")
|
||||||
f = str(f)
|
note = str(note)
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
os.unlink(f)
|
os.unlink(note)
|
||||||
e.exportInto(f)
|
e.exportInto(note)
|
||||||
with open(f) as file:
|
with open(note) as file:
|
||||||
assert file.readline() == "foo\tbar<br>\ttag tag2\n"
|
assert file.readline() == "foo\tbar<br>\ttag tag2\n"
|
||||||
e.includeTags = False
|
e.includeTags = False
|
||||||
e.includeHTML = False
|
e.includeHTML = False
|
||||||
e.exportInto(f)
|
e.exportInto(note)
|
||||||
with open(f) as file:
|
with open(note) as file:
|
||||||
assert file.readline() == "foo\tbar\n"
|
assert file.readline() == "foo\tbar\n"
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,24 +13,24 @@ class DummyCollection:
|
|||||||
|
|
||||||
def test_findCards():
|
def test_findCards():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "dog"
|
note["Front"] = "dog"
|
||||||
f["Back"] = "cat"
|
note["Back"] = "cat"
|
||||||
f.tags.append("monkey animal_1 * %")
|
note.tags.append("monkey animal_1 * %")
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
f1id = f.id
|
f1id = note.id
|
||||||
firstCardId = f.cards()[0].id
|
firstCardId = note.cards()[0].id
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "goats are fun"
|
note["Front"] = "goats are fun"
|
||||||
f["Back"] = "sheep"
|
note["Back"] = "sheep"
|
||||||
f.tags.append("sheep goat horse animal11")
|
note.tags.append("sheep goat horse animal11")
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
f2id = f.id
|
f2id = note.id
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "cat"
|
note["Front"] = "cat"
|
||||||
f["Back"] = "sheep"
|
note["Back"] = "sheep"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
catCard = f.cards()[0]
|
catCard = note.cards()[0]
|
||||||
m = deck.models.current()
|
m = deck.models.current()
|
||||||
m = deck.models.copy(m)
|
m = deck.models.copy(m)
|
||||||
mm = deck.models
|
mm = deck.models
|
||||||
@ -39,12 +39,12 @@ def test_findCards():
|
|||||||
t["afmt"] = "{{Front}}"
|
t["afmt"] = "{{Front}}"
|
||||||
mm.addTemplate(m, t)
|
mm.addTemplate(m, t)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "test"
|
note["Front"] = "test"
|
||||||
f["Back"] = "foo bar"
|
note["Back"] = "foo bar"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
deck.save()
|
deck.save()
|
||||||
latestCardIds = [c.id for c in f.cards()]
|
latestCardIds = [c.id for c in note.cards()]
|
||||||
# tag searches
|
# tag searches
|
||||||
assert len(deck.findCards("tag:*")) == 5
|
assert len(deck.findCards("tag:*")) == 5
|
||||||
assert len(deck.findCards("tag:\\*")) == 1
|
assert len(deck.findCards("tag:\\*")) == 1
|
||||||
@ -72,7 +72,7 @@ def test_findCards():
|
|||||||
assert len(deck.findCards('"are goats"')) == 0
|
assert len(deck.findCards('"are goats"')) == 0
|
||||||
assert len(deck.findCards('"goats are"')) == 1
|
assert len(deck.findCards('"goats are"')) == 1
|
||||||
# card states
|
# card states
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.queue = c.type = CARD_TYPE_REV
|
c.queue = c.type = CARD_TYPE_REV
|
||||||
assert deck.findCards("is:review") == []
|
assert deck.findCards("is:review") == []
|
||||||
c.flush()
|
c.flush()
|
||||||
@ -90,7 +90,7 @@ def test_findCards():
|
|||||||
assert deck.findCards("is:suspended") == [c.id]
|
assert deck.findCards("is:suspended") == [c.id]
|
||||||
# nids
|
# nids
|
||||||
assert deck.findCards("nid:54321") == []
|
assert deck.findCards("nid:54321") == []
|
||||||
assert len(deck.findCards("nid:%d" % f.id)) == 2
|
assert len(deck.findCards("nid:%d" % note.id)) == 2
|
||||||
assert len(deck.findCards("nid:%d,%d" % (f1id, f2id))) == 2
|
assert len(deck.findCards("nid:%d,%d" % (f1id, f2id))) == 2
|
||||||
# templates
|
# templates
|
||||||
assert len(deck.findCards("card:foo")) == 0
|
assert len(deck.findCards("card:foo")) == 0
|
||||||
@ -142,16 +142,16 @@ def test_findCards():
|
|||||||
assert len(deck.findCards("deck:*EFAULT")) == 5
|
assert len(deck.findCards("deck:*EFAULT")) == 5
|
||||||
assert len(deck.findCards("deck:*cefault")) == 0
|
assert len(deck.findCards("deck:*cefault")) == 0
|
||||||
# full search
|
# full search
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "hello<b>world</b>"
|
note["Front"] = "hello<b>world</b>"
|
||||||
f["Back"] = "abc"
|
note["Back"] = "abc"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
# as it's the sort field, it matches
|
# as it's the sort field, it matches
|
||||||
assert len(deck.findCards("helloworld")) == 2
|
assert len(deck.findCards("helloworld")) == 2
|
||||||
# assert len(deck.findCards("helloworld", full=True)) == 2
|
# assert len(deck.findCards("helloworld", full=True)) == 2
|
||||||
# if we put it on the back, it won't
|
# if we put it on the back, it won't
|
||||||
(f["Front"], f["Back"]) = (f["Back"], f["Front"])
|
(note["Front"], note["Back"]) = (note["Back"], note["Front"])
|
||||||
f.flush()
|
note.flush()
|
||||||
assert len(deck.findCards("helloworld")) == 0
|
assert len(deck.findCards("helloworld")) == 0
|
||||||
# assert len(deck.findCards("helloworld", full=True)) == 2
|
# assert len(deck.findCards("helloworld", full=True)) == 2
|
||||||
# assert len(deck.findCards("back:helloworld", full=True)) == 2
|
# assert len(deck.findCards("back:helloworld", full=True)) == 2
|
||||||
@ -213,10 +213,10 @@ def test_findCards():
|
|||||||
print("some find tests disabled near cutoff")
|
print("some find tests disabled near cutoff")
|
||||||
# empty field
|
# empty field
|
||||||
assert len(deck.findCards("front:")) == 0
|
assert len(deck.findCards("front:")) == 0
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = ""
|
note["Front"] = ""
|
||||||
f["Back"] = "abc2"
|
note["Back"] = "abc2"
|
||||||
assert deck.addNote(f) == 1
|
assert deck.addNote(note) == 1
|
||||||
assert len(deck.findCards("front:")) == 1
|
assert len(deck.findCards("front:")) == 1
|
||||||
# OR searches and nesting
|
# OR searches and nesting
|
||||||
assert len(deck.findCards("tag:monkey or tag:sheep")) == 2
|
assert len(deck.findCards("tag:monkey or tag:sheep")) == 2
|
||||||
@ -231,44 +231,44 @@ def test_findCards():
|
|||||||
|
|
||||||
def test_findReplace():
|
def test_findReplace():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "foo"
|
note["Front"] = "foo"
|
||||||
f["Back"] = "bar"
|
note["Back"] = "bar"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
f2 = deck.newNote()
|
f2 = deck.newNote()
|
||||||
f2["Front"] = "baz"
|
f2["Front"] = "baz"
|
||||||
f2["Back"] = "foo"
|
f2["Back"] = "foo"
|
||||||
deck.addNote(f2)
|
deck.addNote(f2)
|
||||||
nids = [f.id, f2.id]
|
nids = [note.id, f2.id]
|
||||||
# should do nothing
|
# should do nothing
|
||||||
assert deck.findReplace(nids, "abc", "123") == 0
|
assert deck.findReplace(nids, "abc", "123") == 0
|
||||||
# global replace
|
# global replace
|
||||||
assert deck.findReplace(nids, "foo", "qux") == 2
|
assert deck.findReplace(nids, "foo", "qux") == 2
|
||||||
f.load()
|
note.load()
|
||||||
assert f["Front"] == "qux"
|
assert note["Front"] == "qux"
|
||||||
f2.load()
|
f2.load()
|
||||||
assert f2["Back"] == "qux"
|
assert f2["Back"] == "qux"
|
||||||
# single field replace
|
# single field replace
|
||||||
assert deck.findReplace(nids, "qux", "foo", field="Front") == 1
|
assert deck.findReplace(nids, "qux", "foo", field="Front") == 1
|
||||||
f.load()
|
note.load()
|
||||||
assert f["Front"] == "foo"
|
assert note["Front"] == "foo"
|
||||||
f2.load()
|
f2.load()
|
||||||
assert f2["Back"] == "qux"
|
assert f2["Back"] == "qux"
|
||||||
# regex replace
|
# regex replace
|
||||||
assert deck.findReplace(nids, "B.r", "reg") == 0
|
assert deck.findReplace(nids, "B.r", "reg") == 0
|
||||||
f.load()
|
note.load()
|
||||||
assert f["Back"] != "reg"
|
assert note["Back"] != "reg"
|
||||||
assert deck.findReplace(nids, "B.r", "reg", regex=True) == 1
|
assert deck.findReplace(nids, "B.r", "reg", regex=True) == 1
|
||||||
f.load()
|
note.load()
|
||||||
assert f["Back"] == "reg"
|
assert note["Back"] == "reg"
|
||||||
|
|
||||||
|
|
||||||
def test_findDupes():
|
def test_findDupes():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "foo"
|
note["Front"] = "foo"
|
||||||
f["Back"] = "bar"
|
note["Back"] = "bar"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
f2 = deck.newNote()
|
f2 = deck.newNote()
|
||||||
f2["Front"] = "baz"
|
f2["Front"] = "baz"
|
||||||
f2["Back"] = "bar"
|
f2["Back"] = "bar"
|
||||||
|
@ -37,8 +37,8 @@ def test_anki2_mediadupes():
|
|||||||
mid = n.model()["id"]
|
mid = n.model()["id"]
|
||||||
tmp.addNote(n)
|
tmp.addNote(n)
|
||||||
# add that sound to media folder
|
# add that sound to media folder
|
||||||
with open(os.path.join(tmp.media.dir(), "foo.mp3"), "w") as f:
|
with open(os.path.join(tmp.media.dir(), "foo.mp3"), "w") as note:
|
||||||
f.write("foo")
|
note.write("foo")
|
||||||
tmp.close()
|
tmp.close()
|
||||||
# it should be imported correctly into an empty deck
|
# it should be imported correctly into an empty deck
|
||||||
empty = getEmptyCol()
|
empty = getEmptyCol()
|
||||||
@ -55,8 +55,8 @@ def test_anki2_mediadupes():
|
|||||||
# if the local file content is different, and import should trigger a
|
# if the local file content is different, and import should trigger a
|
||||||
# rename
|
# rename
|
||||||
empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards"))
|
empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards"))
|
||||||
with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as f:
|
with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as note:
|
||||||
f.write("bar")
|
note.write("bar")
|
||||||
imp = Anki2Importer(empty, tmp.path)
|
imp = Anki2Importer(empty, tmp.path)
|
||||||
imp.run()
|
imp.run()
|
||||||
assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid]
|
assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid]
|
||||||
@ -65,8 +65,8 @@ def test_anki2_mediadupes():
|
|||||||
# if the localized media file already exists, we rewrite the note and
|
# if the localized media file already exists, we rewrite the note and
|
||||||
# media
|
# media
|
||||||
empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards"))
|
empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards"))
|
||||||
with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as f:
|
with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as note:
|
||||||
f.write("bar")
|
note.write("bar")
|
||||||
imp = Anki2Importer(empty, tmp.path)
|
imp = Anki2Importer(empty, tmp.path)
|
||||||
imp.run()
|
imp.run()
|
||||||
assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid]
|
assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid]
|
||||||
@ -89,8 +89,8 @@ def test_apkg():
|
|||||||
assert os.listdir(tmp.media.dir()) == ["foo.wav"]
|
assert os.listdir(tmp.media.dir()) == ["foo.wav"]
|
||||||
# but if the local file has different data, it will rename
|
# but if the local file has different data, it will rename
|
||||||
tmp.remove_cards_and_orphaned_notes(tmp.db.list("select id from cards"))
|
tmp.remove_cards_and_orphaned_notes(tmp.db.list("select id from cards"))
|
||||||
with open(os.path.join(tmp.media.dir(), "foo.wav"), "w") as f:
|
with open(os.path.join(tmp.media.dir(), "foo.wav"), "w") as note:
|
||||||
f.write("xyz")
|
note.write("xyz")
|
||||||
imp = AnkiPackageImporter(tmp, apkg)
|
imp = AnkiPackageImporter(tmp, apkg)
|
||||||
imp.run()
|
imp.run()
|
||||||
assert len(os.listdir(tmp.media.dir())) == 2
|
assert len(os.listdir(tmp.media.dir())) == 2
|
||||||
@ -185,8 +185,8 @@ def test_csv2():
|
|||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
mm = deck.models
|
mm = deck.models
|
||||||
m = mm.current()
|
m = mm.current()
|
||||||
f = mm.newField("Three")
|
note = mm.newField("Three")
|
||||||
mm.addField(m, f)
|
mm.addField(m, note)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
n = deck.newNote()
|
n = deck.newNote()
|
||||||
n["Front"] = "1"
|
n["Front"] = "1"
|
||||||
@ -209,8 +209,8 @@ def test_tsv_tag_modified():
|
|||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
mm = deck.models
|
mm = deck.models
|
||||||
m = mm.current()
|
m = mm.current()
|
||||||
f = mm.newField("Top")
|
note = mm.newField("Top")
|
||||||
mm.addField(m, f)
|
mm.addField(m, note)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
n = deck.newNote()
|
n = deck.newNote()
|
||||||
n["Front"] = "1"
|
n["Front"] = "1"
|
||||||
@ -245,8 +245,8 @@ def test_tsv_tag_multiple_tags():
|
|||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
mm = deck.models
|
mm = deck.models
|
||||||
m = mm.current()
|
m = mm.current()
|
||||||
f = mm.newField("Top")
|
note = mm.newField("Top")
|
||||||
mm.addField(m, f)
|
mm.addField(m, note)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
n = deck.newNote()
|
n = deck.newNote()
|
||||||
n["Front"] = "1"
|
n["Front"] = "1"
|
||||||
@ -279,8 +279,8 @@ def test_csv_tag_only_if_modified():
|
|||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
mm = deck.models
|
mm = deck.models
|
||||||
m = mm.current()
|
m = mm.current()
|
||||||
f = mm.newField("Left")
|
note = mm.newField("Left")
|
||||||
mm.addField(m, f)
|
mm.addField(m, note)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
n = deck.newNote()
|
n = deck.newNote()
|
||||||
n["Front"] = "1"
|
n["Front"] = "1"
|
||||||
|
@ -13,13 +13,13 @@ def test_latex():
|
|||||||
|
|
||||||
anki.latex.pngCommands[0][0] = "nolatex"
|
anki.latex.pngCommands[0][0] = "nolatex"
|
||||||
# add a note with latex
|
# add a note with latex
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "[latex]hello[/latex]"
|
note["Front"] = "[latex]hello[/latex]"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# but since latex couldn't run, there's nothing there
|
# but since latex couldn't run, there's nothing there
|
||||||
assert len(os.listdir(d.media.dir())) == 0
|
assert len(os.listdir(d.media.dir())) == 0
|
||||||
# check the error message
|
# check the error message
|
||||||
msg = f.cards()[0].q()
|
msg = note.cards()[0].q()
|
||||||
assert "executing nolatex" in msg
|
assert "executing nolatex" in msg
|
||||||
assert "installed" in msg
|
assert "installed" in msg
|
||||||
# check if we have latex installed, and abort test if we don't
|
# check if we have latex installed, and abort test if we don't
|
||||||
@ -31,26 +31,26 @@ def test_latex():
|
|||||||
# check media db should cause latex to be generated
|
# check media db should cause latex to be generated
|
||||||
d.media.render_all_latex()
|
d.media.render_all_latex()
|
||||||
assert len(os.listdir(d.media.dir())) == 1
|
assert len(os.listdir(d.media.dir())) == 1
|
||||||
assert ".png" in f.cards()[0].q()
|
assert ".png" in note.cards()[0].q()
|
||||||
# adding new notes should cause generation on question display
|
# adding new notes should cause generation on question display
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "[latex]world[/latex]"
|
note["Front"] = "[latex]world[/latex]"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
f.cards()[0].q()
|
note.cards()[0].q()
|
||||||
assert len(os.listdir(d.media.dir())) == 2
|
assert len(os.listdir(d.media.dir())) == 2
|
||||||
# another note with the same media should reuse
|
# another note with the same media should reuse
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = " [latex]world[/latex]"
|
note["Front"] = " [latex]world[/latex]"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert len(os.listdir(d.media.dir())) == 2
|
assert len(os.listdir(d.media.dir())) == 2
|
||||||
oldcard = f.cards()[0]
|
oldcard = note.cards()[0]
|
||||||
assert ".png" in oldcard.q()
|
assert ".png" in oldcard.q()
|
||||||
# if we turn off building, then previous cards should work, but cards with
|
# if we turn off building, then previous cards should work, but cards with
|
||||||
# missing media will show a broken image
|
# missing media will show a broken image
|
||||||
anki.latex.build = False
|
anki.latex.build = False
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "[latex]foo[/latex]"
|
note["Front"] = "[latex]foo[/latex]"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert len(os.listdir(d.media.dir())) == 2
|
assert len(os.listdir(d.media.dir())) == 2
|
||||||
assert ".png" in oldcard.q()
|
assert ".png" in oldcard.q()
|
||||||
# turn it on again so other test don't suffer
|
# turn it on again so other test don't suffer
|
||||||
@ -88,8 +88,8 @@ def test_latex():
|
|||||||
|
|
||||||
def _test_includes_bad_command(bad):
|
def _test_includes_bad_command(bad):
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "[latex]%s[/latex]" % bad
|
note["Front"] = "[latex]%s[/latex]" % bad
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
q = f.cards()[0].q()
|
q = note.cards()[0].q()
|
||||||
return ("'%s' is not allowed on cards" % bad in q, "Card content: %s" % q)
|
return ("'%s' is not allowed on cards" % bad in q, "Card content: %s" % q)
|
||||||
|
@ -11,15 +11,15 @@ def test_add():
|
|||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
dir = tempfile.mkdtemp(prefix="anki")
|
dir = tempfile.mkdtemp(prefix="anki")
|
||||||
path = os.path.join(dir, "foo.jpg")
|
path = os.path.join(dir, "foo.jpg")
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as note:
|
||||||
f.write("hello")
|
note.write("hello")
|
||||||
# new file, should preserve name
|
# new file, should preserve name
|
||||||
assert d.media.addFile(path) == "foo.jpg"
|
assert d.media.addFile(path) == "foo.jpg"
|
||||||
# adding the same file again should not create a duplicate
|
# adding the same file again should not create a duplicate
|
||||||
assert d.media.addFile(path) == "foo.jpg"
|
assert d.media.addFile(path) == "foo.jpg"
|
||||||
# but if it has a different sha1, it should
|
# but if it has a different sha1, it should
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as note:
|
||||||
f.write("world")
|
note.write("world")
|
||||||
assert d.media.addFile(path) == "foo-7c211433f02071597741e6ff5a8ea34789abbf43.jpg"
|
assert d.media.addFile(path) == "foo-7c211433f02071597741e6ff5a8ea34789abbf43.jpg"
|
||||||
|
|
||||||
|
|
||||||
@ -60,18 +60,18 @@ def test_deckIntegration():
|
|||||||
file = str(os.path.join(testDir, "support/fake.png"))
|
file = str(os.path.join(testDir, "support/fake.png"))
|
||||||
d.media.addFile(file)
|
d.media.addFile(file)
|
||||||
# add a note which references it
|
# add a note which references it
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "<img src='fake.png'>"
|
note["Back"] = "<img src='fake.png'>"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and one which references a non-existent file
|
# and one which references a non-existent file
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "<img src='fake2.png'>"
|
note["Back"] = "<img src='fake2.png'>"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and add another file which isn't used
|
# and add another file which isn't used
|
||||||
with open(os.path.join(d.media.dir(), "foo.jpg"), "w") as f:
|
with open(os.path.join(d.media.dir(), "foo.jpg"), "w") as note:
|
||||||
f.write("test")
|
note.write("test")
|
||||||
# check media
|
# check media
|
||||||
ret = d.media.check()
|
ret = d.media.check()
|
||||||
assert ret.missing == ["fake2.png"]
|
assert ret.missing == ["fake2.png"]
|
||||||
|
@ -9,10 +9,10 @@ from tests.shared import getEmptyCol
|
|||||||
|
|
||||||
def test_modelDelete():
|
def test_modelDelete():
|
||||||
deck = getEmptyCol()
|
deck = getEmptyCol()
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = "2"
|
note["Back"] = "2"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
assert deck.cardCount() == 1
|
assert deck.cardCount() == 1
|
||||||
deck.models.rem(deck.models.current())
|
deck.models.rem(deck.models.current())
|
||||||
assert deck.cardCount() == 0
|
assert deck.cardCount() == 0
|
||||||
@ -34,23 +34,23 @@ def test_modelCopy():
|
|||||||
|
|
||||||
def test_fields():
|
def test_fields():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = "2"
|
note["Back"] = "2"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
m = d.models.current()
|
m = d.models.current()
|
||||||
# make sure renaming a field updates the templates
|
# make sure renaming a field updates the templates
|
||||||
d.models.renameField(m, m["flds"][0], "NewFront")
|
d.models.renameField(m, m["flds"][0], "NewFront")
|
||||||
assert "{{NewFront}}" in m["tmpls"][0]["qfmt"]
|
assert "{{NewFront}}" in m["tmpls"][0]["qfmt"]
|
||||||
h = d.models.scmhash(m)
|
h = d.models.scmhash(m)
|
||||||
# add a field
|
# add a field
|
||||||
f = d.models.newField("foo")
|
note = d.models.newField("foo")
|
||||||
d.models.addField(m, f)
|
d.models.addField(m, note)
|
||||||
assert d.getNote(d.models.nids(m)[0]).fields == ["1", "2", ""]
|
assert d.getNote(d.models.nids(m)[0]).fields == ["1", "2", ""]
|
||||||
assert d.models.scmhash(m) != h
|
assert d.models.scmhash(m) != h
|
||||||
# rename it
|
# rename it
|
||||||
f = m["flds"][2]
|
note = m["flds"][2]
|
||||||
d.models.renameField(m, f, "bar")
|
d.models.renameField(m, note, "bar")
|
||||||
assert d.getNote(d.models.nids(m)[0])["bar"] == ""
|
assert d.getNote(d.models.nids(m)[0])["bar"] == ""
|
||||||
# delete back
|
# delete back
|
||||||
d.models.remField(m, m["flds"][1])
|
d.models.remField(m, m["flds"][1])
|
||||||
@ -62,11 +62,11 @@ def test_fields():
|
|||||||
d.models.moveField(m, m["flds"][1], 0)
|
d.models.moveField(m, m["flds"][1], 0)
|
||||||
assert d.getNote(d.models.nids(m)[0]).fields == ["1", ""]
|
assert d.getNote(d.models.nids(m)[0]).fields == ["1", ""]
|
||||||
# add another and put in middle
|
# add another and put in middle
|
||||||
f = d.models.newField("baz")
|
note = d.models.newField("baz")
|
||||||
d.models.addField(m, f)
|
d.models.addField(m, note)
|
||||||
f = d.getNote(d.models.nids(m)[0])
|
note = d.getNote(d.models.nids(m)[0])
|
||||||
f["baz"] = "2"
|
note["baz"] = "2"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert d.getNote(d.models.nids(m)[0]).fields == ["1", "", "2"]
|
assert d.getNote(d.models.nids(m)[0]).fields == ["1", "", "2"]
|
||||||
# move 2 -> 1
|
# move 2 -> 1
|
||||||
d.models.moveField(m, m["flds"][2], 1)
|
d.models.moveField(m, m["flds"][2], 1)
|
||||||
@ -88,12 +88,12 @@ def test_templates():
|
|||||||
t["afmt"] = "{{Front}}"
|
t["afmt"] = "{{Front}}"
|
||||||
mm.addTemplate(m, t)
|
mm.addTemplate(m, t)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = "2"
|
note["Back"] = "2"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert d.cardCount() == 2
|
assert d.cardCount() == 2
|
||||||
(c, c2) = f.cards()
|
(c, c2) = note.cards()
|
||||||
# first card should have first ord
|
# first card should have first ord
|
||||||
assert c.ord == 0
|
assert c.ord == 0
|
||||||
assert c2.ord == 1
|
assert c2.ord == 1
|
||||||
@ -107,7 +107,7 @@ def test_templates():
|
|||||||
d.models.remTemplate(m, m["tmpls"][0])
|
d.models.remTemplate(m, m["tmpls"][0])
|
||||||
assert d.cardCount() == 1
|
assert d.cardCount() == 1
|
||||||
# and should have updated the other cards' ordinals
|
# and should have updated the other cards' ordinals
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
assert c.ord == 0
|
assert c.ord == 0
|
||||||
assert stripHTML(c.q()) == "1"
|
assert stripHTML(c.q()) == "1"
|
||||||
# it shouldn't be possible to orphan notes by removing templates
|
# it shouldn't be possible to orphan notes by removing templates
|
||||||
@ -134,11 +134,11 @@ def test_cloze_ordinals():
|
|||||||
mm.save(m)
|
mm.save(m)
|
||||||
d.models.remTemplate(m, m["tmpls"][0])
|
d.models.remTemplate(m, m["tmpls"][0])
|
||||||
|
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = "{{c1::firstQ::firstA}}{{c2::secondQ::secondA}}"
|
note["Text"] = "{{c1::firstQ::firstA}}{{c2::secondQ::secondA}}"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert d.cardCount() == 2
|
assert d.cardCount() == 2
|
||||||
(c, c2) = f.cards()
|
(c, c2) = note.cards()
|
||||||
# first card should have first ord
|
# first card should have first ord
|
||||||
assert c.ord == 0
|
assert c.ord == 0
|
||||||
assert c2.ord == 1
|
assert c2.ord == 1
|
||||||
@ -149,79 +149,83 @@ def test_text():
|
|||||||
m = d.models.current()
|
m = d.models.current()
|
||||||
m["tmpls"][0]["qfmt"] = "{{text:Front}}"
|
m["tmpls"][0]["qfmt"] = "{{text:Front}}"
|
||||||
d.models.save(m)
|
d.models.save(m)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "hello<b>world"
|
note["Front"] = "hello<b>world"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert "helloworld" in f.cards()[0].q()
|
assert "helloworld" in note.cards()[0].q()
|
||||||
|
|
||||||
|
|
||||||
def test_cloze():
|
def test_cloze():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
d.models.setCurrent(d.models.byName("Cloze"))
|
d.models.setCurrent(d.models.byName("Cloze"))
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
assert f.model()["name"] == "Cloze"
|
assert note.model()["name"] == "Cloze"
|
||||||
# a cloze model with no clozes is not empty
|
# a cloze model with no clozes is not empty
|
||||||
f["Text"] = "nothing"
|
note["Text"] = "nothing"
|
||||||
assert d.addNote(f)
|
assert d.addNote(note)
|
||||||
# try with one cloze
|
# try with one cloze
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = "hello {{c1::world}}"
|
note["Text"] = "hello {{c1::world}}"
|
||||||
assert d.addNote(f) == 1
|
assert d.addNote(note) == 1
|
||||||
assert "hello <span class=cloze>[...]</span>" in f.cards()[0].q()
|
assert "hello <span class=cloze>[...]</span>" in note.cards()[0].q()
|
||||||
assert "hello <span class=cloze>world</span>" in f.cards()[0].a()
|
assert "hello <span class=cloze>world</span>" in note.cards()[0].a()
|
||||||
# and with a comment
|
# and with a comment
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = "hello {{c1::world::typical}}"
|
note["Text"] = "hello {{c1::world::typical}}"
|
||||||
assert d.addNote(f) == 1
|
assert d.addNote(note) == 1
|
||||||
assert "<span class=cloze>[typical]</span>" in f.cards()[0].q()
|
assert "<span class=cloze>[typical]</span>" in note.cards()[0].q()
|
||||||
assert "<span class=cloze>world</span>" in f.cards()[0].a()
|
assert "<span class=cloze>world</span>" in note.cards()[0].a()
|
||||||
# and with 2 clozes
|
# and with 2 clozes
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = "hello {{c1::world}} {{c2::bar}}"
|
note["Text"] = "hello {{c1::world}} {{c2::bar}}"
|
||||||
assert d.addNote(f) == 2
|
assert d.addNote(note) == 2
|
||||||
(c1, c2) = f.cards()
|
(c1, c2) = note.cards()
|
||||||
assert "<span class=cloze>[...]</span> bar" in c1.q()
|
assert "<span class=cloze>[...]</span> bar" in c1.q()
|
||||||
assert "<span class=cloze>world</span> bar" in c1.a()
|
assert "<span class=cloze>world</span> bar" in c1.a()
|
||||||
assert "world <span class=cloze>[...]</span>" in c2.q()
|
assert "world <span class=cloze>[...]</span>" in c2.q()
|
||||||
assert "world <span class=cloze>bar</span>" in c2.a()
|
assert "world <span class=cloze>bar</span>" in c2.a()
|
||||||
# if there are multiple answers for a single cloze, they are given in a
|
# if there are multiple answers for a single cloze, they are given in a
|
||||||
# list
|
# list
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = "a {{c1::b}} {{c1::c}}"
|
note["Text"] = "a {{c1::b}} {{c1::c}}"
|
||||||
assert d.addNote(f) == 1
|
assert d.addNote(note) == 1
|
||||||
assert "<span class=cloze>b</span> <span class=cloze>c</span>" in (f.cards()[0].a())
|
assert "<span class=cloze>b</span> <span class=cloze>c</span>" in (
|
||||||
|
note.cards()[0].a()
|
||||||
|
)
|
||||||
# if we add another cloze, a card should be generated
|
# if we add another cloze, a card should be generated
|
||||||
cnt = d.cardCount()
|
cnt = d.cardCount()
|
||||||
f["Text"] = "{{c2::hello}} {{c1::foo}}"
|
note["Text"] = "{{c2::hello}} {{c1::foo}}"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert d.cardCount() == cnt + 1
|
assert d.cardCount() == cnt + 1
|
||||||
# 0 or negative indices are not supported
|
# 0 or negative indices are not supported
|
||||||
f["Text"] += "{{c0::zero}} {{c-1:foo}}"
|
note["Text"] += "{{c0::zero}} {{c-1:foo}}"
|
||||||
f.flush()
|
note.flush()
|
||||||
assert len(f.cards()) == 2
|
assert len(note.cards()) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_cloze_mathjax():
|
def test_cloze_mathjax():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
d.models.setCurrent(d.models.byName("Cloze"))
|
d.models.setCurrent(d.models.byName("Cloze"))
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f[
|
note[
|
||||||
"Text"
|
"Text"
|
||||||
] = r"{{c1::ok}} \(2^2\) {{c2::not ok}} \(2^{{c3::2}}\) \(x^3\) {{c4::blah}} {{c5::text with \(x^2\) jax}}"
|
] = r"{{c1::ok}} \(2^2\) {{c2::not ok}} \(2^{{c3::2}}\) \(x^3\) {{c4::blah}} {{c5::text with \(x^2\) jax}}"
|
||||||
assert d.addNote(f)
|
assert d.addNote(note)
|
||||||
assert len(f.cards()) == 5
|
assert len(note.cards()) == 5
|
||||||
assert "class=cloze" in f.cards()[0].q()
|
assert "class=cloze" in note.cards()[0].q()
|
||||||
assert "class=cloze" in f.cards()[1].q()
|
assert "class=cloze" in note.cards()[1].q()
|
||||||
assert "class=cloze" not in f.cards()[2].q()
|
assert "class=cloze" not in note.cards()[2].q()
|
||||||
assert "class=cloze" in f.cards()[3].q()
|
assert "class=cloze" in note.cards()[3].q()
|
||||||
assert "class=cloze" in f.cards()[4].q()
|
assert "class=cloze" in note.cards()[4].q()
|
||||||
|
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = r"\(a\) {{c1::b}} \[ {{c1::c}} \]"
|
note["Text"] = r"\(a\) {{c1::b}} \[ {{c1::c}} \]"
|
||||||
assert d.addNote(f)
|
assert d.addNote(note)
|
||||||
assert len(f.cards()) == 1
|
assert len(note.cards()) == 1
|
||||||
assert (
|
assert (
|
||||||
f.cards()[0].q().endswith(r"\(a\) <span class=cloze>[...]</span> \[ [...] \]")
|
note.cards()[0]
|
||||||
|
.q()
|
||||||
|
.endswith(r"\(a\) <span class=cloze>[...]</span> \[ [...] \]")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -231,10 +235,10 @@ def test_typecloze():
|
|||||||
d.models.setCurrent(m)
|
d.models.setCurrent(m)
|
||||||
m["tmpls"][0]["qfmt"] = "{{cloze:Text}}{{type:cloze:Text}}"
|
m["tmpls"][0]["qfmt"] = "{{cloze:Text}}{{type:cloze:Text}}"
|
||||||
d.models.save(m)
|
d.models.save(m)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Text"] = "hello {{c1::world}}"
|
note["Text"] = "hello {{c1::world}}"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert "[[type:cloze:Text]]" in f.cards()[0].q()
|
assert "[[type:cloze:Text]]" in note.cards()[0].q()
|
||||||
|
|
||||||
|
|
||||||
def test_chained_mods():
|
def test_chained_mods():
|
||||||
@ -251,25 +255,25 @@ def test_chained_mods():
|
|||||||
mm.save(m)
|
mm.save(m)
|
||||||
d.models.remTemplate(m, m["tmpls"][0])
|
d.models.remTemplate(m, m["tmpls"][0])
|
||||||
|
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
q1 = '<span style="color:red">phrase</span>'
|
q1 = '<span style="color:red">phrase</span>'
|
||||||
a1 = "<b>sentence</b>"
|
a1 = "<b>sentence</b>"
|
||||||
q2 = '<span style="color:red">en chaine</span>'
|
q2 = '<span style="color:red">en chaine</span>'
|
||||||
a2 = "<i>chained</i>"
|
a2 = "<i>chained</i>"
|
||||||
f["Text"] = "This {{c1::%s::%s}} demonstrates {{c1::%s::%s}} clozes." % (
|
note["Text"] = "This {{c1::%s::%s}} demonstrates {{c1::%s::%s}} clozes." % (
|
||||||
q1,
|
q1,
|
||||||
a1,
|
a1,
|
||||||
q2,
|
q2,
|
||||||
a2,
|
a2,
|
||||||
)
|
)
|
||||||
assert d.addNote(f) == 1
|
assert d.addNote(note) == 1
|
||||||
assert (
|
assert (
|
||||||
"This <span class=cloze>[sentence]</span> demonstrates <span class=cloze>[chained]</span> clozes."
|
"This <span class=cloze>[sentence]</span> demonstrates <span class=cloze>[chained]</span> clozes."
|
||||||
in f.cards()[0].q()
|
in note.cards()[0].q()
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
"This <span class=cloze>phrase</span> demonstrates <span class=cloze>en chaine</span> clozes."
|
"This <span class=cloze>phrase</span> demonstrates <span class=cloze>en chaine</span> clozes."
|
||||||
in f.cards()[0].a()
|
in note.cards()[0].a()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -285,40 +289,40 @@ def test_modelChange():
|
|||||||
mm.addTemplate(m, t)
|
mm.addTemplate(m, t)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
basic = m
|
basic = m
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "f"
|
note["Front"] = "note"
|
||||||
f["Back"] = "b123"
|
note["Back"] = "b123"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
# switch fields
|
# switch fields
|
||||||
map = {0: 1, 1: 0}
|
map = {0: 1, 1: 0}
|
||||||
deck.models.change(basic, [f.id], basic, map, None)
|
deck.models.change(basic, [note.id], basic, map, None)
|
||||||
f.load()
|
note.load()
|
||||||
assert f["Front"] == "b123"
|
assert note["Front"] == "b123"
|
||||||
assert f["Back"] == "f"
|
assert note["Back"] == "note"
|
||||||
# switch cards
|
# switch cards
|
||||||
c0 = f.cards()[0]
|
c0 = note.cards()[0]
|
||||||
c1 = f.cards()[1]
|
c1 = note.cards()[1]
|
||||||
assert "b123" in c0.q()
|
assert "b123" in c0.q()
|
||||||
assert "f" in c1.q()
|
assert "note" in c1.q()
|
||||||
assert c0.ord == 0
|
assert c0.ord == 0
|
||||||
assert c1.ord == 1
|
assert c1.ord == 1
|
||||||
deck.models.change(basic, [f.id], basic, None, map)
|
deck.models.change(basic, [note.id], basic, None, map)
|
||||||
f.load()
|
note.load()
|
||||||
c0.load()
|
c0.load()
|
||||||
c1.load()
|
c1.load()
|
||||||
assert "f" in c0.q()
|
assert "note" in c0.q()
|
||||||
assert "b123" in c1.q()
|
assert "b123" in c1.q()
|
||||||
assert c0.ord == 1
|
assert c0.ord == 1
|
||||||
assert c1.ord == 0
|
assert c1.ord == 0
|
||||||
# .cards() returns cards in order
|
# .cards() returns cards in order
|
||||||
assert f.cards()[0].id == c1.id
|
assert note.cards()[0].id == c1.id
|
||||||
# delete first card
|
# delete first card
|
||||||
map = {0: None, 1: 1}
|
map = {0: None, 1: 1}
|
||||||
if isWin:
|
if isWin:
|
||||||
# The low precision timer on Windows reveals a race condition
|
# The low precision timer on Windows reveals a race condition
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
deck.models.change(basic, [f.id], basic, None, map)
|
deck.models.change(basic, [note.id], basic, None, map)
|
||||||
f.load()
|
note.load()
|
||||||
c0.load()
|
c0.load()
|
||||||
# the card was deleted
|
# the card was deleted
|
||||||
try:
|
try:
|
||||||
@ -327,33 +331,33 @@ def test_modelChange():
|
|||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
pass
|
pass
|
||||||
# but we have two cards, as a new one was generated
|
# but we have two cards, as a new one was generated
|
||||||
assert len(f.cards()) == 2
|
assert len(note.cards()) == 2
|
||||||
# an unmapped field becomes blank
|
# an unmapped field becomes blank
|
||||||
assert f["Front"] == "b123"
|
assert note["Front"] == "b123"
|
||||||
assert f["Back"] == "f"
|
assert note["Back"] == "note"
|
||||||
deck.models.change(basic, [f.id], basic, map, None)
|
deck.models.change(basic, [note.id], basic, map, None)
|
||||||
f.load()
|
note.load()
|
||||||
assert f["Front"] == ""
|
assert note["Front"] == ""
|
||||||
assert f["Back"] == "f"
|
assert note["Back"] == "note"
|
||||||
# another note to try model conversion
|
# another note to try model conversion
|
||||||
f = deck.newNote()
|
note = deck.newNote()
|
||||||
f["Front"] = "f2"
|
note["Front"] = "f2"
|
||||||
f["Back"] = "b2"
|
note["Back"] = "b2"
|
||||||
deck.addNote(f)
|
deck.addNote(note)
|
||||||
counts = deck.models.all_use_counts()
|
counts = deck.models.all_use_counts()
|
||||||
assert next(c.use_count for c in counts if c.name == "Basic") == 2
|
assert next(c.use_count for c in counts if c.name == "Basic") == 2
|
||||||
assert next(c.use_count for c in counts if c.name == "Cloze") == 0
|
assert next(c.use_count for c in counts if c.name == "Cloze") == 0
|
||||||
map = {0: 0, 1: 1}
|
map = {0: 0, 1: 1}
|
||||||
deck.models.change(basic, [f.id], cloze, map, map)
|
deck.models.change(basic, [note.id], cloze, map, map)
|
||||||
f.load()
|
note.load()
|
||||||
assert f["Text"] == "f2"
|
assert note["Text"] == "f2"
|
||||||
assert len(f.cards()) == 2
|
assert len(note.cards()) == 2
|
||||||
# back the other way, with deletion of second ord
|
# back the other way, with deletion of second ord
|
||||||
deck.models.remTemplate(basic, basic["tmpls"][1])
|
deck.models.remTemplate(basic, basic["tmpls"][1])
|
||||||
assert deck.db.scalar("select count() from cards where nid = ?", f.id) == 2
|
assert deck.db.scalar("select count() from cards where nid = ?", note.id) == 2
|
||||||
map = {0: 0}
|
map = {0: 0}
|
||||||
deck.models.change(cloze, [f.id], basic, map, map)
|
deck.models.change(cloze, [note.id], basic, map, map)
|
||||||
assert deck.db.scalar("select count() from cards where nid = ?", f.id) == 1
|
assert deck.db.scalar("select count() from cards where nid = ?", note.id) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_req():
|
def test_req():
|
||||||
|
@ -37,10 +37,10 @@ def test_new():
|
|||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.newCount == 0
|
assert d.sched.newCount == 0
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.newCount == 1
|
assert d.sched.newCount == 1
|
||||||
# fetch it
|
# fetch it
|
||||||
@ -64,12 +64,12 @@ def test_new():
|
|||||||
# t['afmt'] = "{{Front}}"
|
# t['afmt'] = "{{Front}}"
|
||||||
# mm.addTemplate(m, t)
|
# mm.addTemplate(m, t)
|
||||||
# mm.save(m)
|
# mm.save(m)
|
||||||
# f = d.newNote()
|
# note = d.newNote()
|
||||||
# f['Front'] = u"2"; f['Back'] = u"2"
|
# note['Front'] = u"2"; note['Back'] = u"2"
|
||||||
# d.addNote(f)
|
# d.addNote(note)
|
||||||
# f = d.newNote()
|
# note = d.newNote()
|
||||||
# f['Front'] = u"3"; f['Back'] = u"3"
|
# note['Front'] = u"3"; note['Back'] = u"3"
|
||||||
# d.addNote(f)
|
# d.addNote(note)
|
||||||
# d.reset()
|
# d.reset()
|
||||||
# qs = ("2", "3", "2", "3")
|
# qs = ("2", "3", "2", "3")
|
||||||
# for n in range(4):
|
# for n in range(4):
|
||||||
@ -83,11 +83,11 @@ def test_newLimits():
|
|||||||
# add some notes
|
# add some notes
|
||||||
g2 = d.decks.id("Default::foo")
|
g2 = d.decks.id("Default::foo")
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = str(i)
|
note["Front"] = str(i)
|
||||||
if i > 4:
|
if i > 4:
|
||||||
f.model()["did"] = g2
|
note.model()["did"] = g2
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# give the child deck a different configuration
|
# give the child deck a different configuration
|
||||||
c2 = d.decks.add_config_returning_id("new conf")
|
c2 = d.decks.add_config_returning_id("new conf")
|
||||||
d.decks.setConf(d.decks.get(g2), c2)
|
d.decks.setConf(d.decks.get(g2), c2)
|
||||||
@ -113,9 +113,9 @@ def test_newLimits():
|
|||||||
|
|
||||||
def test_newBoxes():
|
def test_newBoxes():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
conf = d.sched._cardConf(c)
|
conf = d.sched._cardConf(c)
|
||||||
@ -131,10 +131,10 @@ def test_newBoxes():
|
|||||||
def test_learn():
|
def test_learn():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
# set as a learn card and rebuild queues
|
# set as a learn card and rebuild queues
|
||||||
d.db.execute("update cards set queue=0, type=0")
|
d.db.execute("update cards set queue=0, type=0")
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -209,12 +209,12 @@ def test_learn():
|
|||||||
def test_learn_collapsed():
|
def test_learn_collapsed():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add 2 notes
|
# add 2 notes
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "2"
|
note["Front"] = "2"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
# set as a learn card and rebuild queues
|
# set as a learn card and rebuild queues
|
||||||
d.db.execute("update cards set queue=0, type=0")
|
d.db.execute("update cards set queue=0, type=0")
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -236,9 +236,9 @@ def test_learn_collapsed():
|
|||||||
def test_learn_day():
|
def test_learn_day():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
d.sched.reset()
|
d.sched.reset()
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
conf = d.sched._cardConf(c)
|
conf = d.sched._cardConf(c)
|
||||||
@ -299,12 +299,12 @@ def test_learn_day():
|
|||||||
def test_reviews():
|
def test_reviews():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# set the card up as a review card, due 8 days ago
|
# set the card up as a review card, due 8 days ago
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = d.sched.today - 8
|
c.due = d.sched.today - 8
|
||||||
@ -379,11 +379,11 @@ def test_reviews():
|
|||||||
|
|
||||||
def test_button_spacing():
|
def test_button_spacing():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# 1 day ivl review card due now
|
# 1 day ivl review card due now
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = d.sched.today
|
c.due = d.sched.today
|
||||||
@ -404,11 +404,11 @@ def test_overdue_lapse():
|
|||||||
return
|
return
|
||||||
d = getEmptyCol() # pylint: disable=unreachable
|
d = getEmptyCol() # pylint: disable=unreachable
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# simulate a review that was lapsed and is now due for its normal review
|
# simulate a review that was lapsed and is now due for its normal review
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = 1
|
c.queue = 1
|
||||||
c.due = -1
|
c.due = -1
|
||||||
@ -440,15 +440,15 @@ def test_finished():
|
|||||||
# nothing due
|
# nothing due
|
||||||
assert "Congratulations" in d.sched.finishedMsg()
|
assert "Congratulations" in d.sched.finishedMsg()
|
||||||
assert "limit" not in d.sched.finishedMsg()
|
assert "limit" not in d.sched.finishedMsg()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# have a new card
|
# have a new card
|
||||||
assert "new cards available" in d.sched.finishedMsg()
|
assert "new cards available" in d.sched.finishedMsg()
|
||||||
# turn it into a review
|
# turn it into a review
|
||||||
d.reset()
|
d.reset()
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.startTimer()
|
c.startTimer()
|
||||||
d.sched.answerCard(c, 3)
|
d.sched.answerCard(c, 3)
|
||||||
# nothing should be due tomorrow, as it's due in a week
|
# nothing should be due tomorrow, as it's due in a week
|
||||||
@ -458,10 +458,10 @@ def test_finished():
|
|||||||
|
|
||||||
def test_nextIvl():
|
def test_nextIvl():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
conf = d.decks.confForDid(1)
|
conf = d.decks.confForDid(1)
|
||||||
conf["new"]["delays"] = [0.5, 3, 10]
|
conf["new"]["delays"] = [0.5, 3, 10]
|
||||||
@ -518,10 +518,10 @@ def test_nextIvl():
|
|||||||
|
|
||||||
def test_misc():
|
def test_misc():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
# burying
|
# burying
|
||||||
d.sched.buryNote(c.nid)
|
d.sched.buryNote(c.nid)
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -533,10 +533,10 @@ def test_misc():
|
|||||||
|
|
||||||
def test_suspend():
|
def test_suspend():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
# suspending
|
# suspending
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.getCard()
|
assert d.sched.getCard()
|
||||||
@ -581,10 +581,10 @@ def test_suspend():
|
|||||||
|
|
||||||
def test_cram():
|
def test_cram():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
c.queue = CARD_TYPE_REV
|
c.queue = CARD_TYPE_REV
|
||||||
c.type = QUEUE_TYPE_REV
|
c.type = QUEUE_TYPE_REV
|
||||||
@ -693,10 +693,10 @@ def test_cram():
|
|||||||
|
|
||||||
def test_cram_rem():
|
def test_cram_rem():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
oldDue = f.cards()[0].due
|
oldDue = note.cards()[0].due
|
||||||
did = d.decks.newDyn("Cram")
|
did = d.decks.newDyn("Cram")
|
||||||
d.sched.rebuildDyn(did)
|
d.sched.rebuildDyn(did)
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -715,9 +715,9 @@ def test_cram_rem():
|
|||||||
def test_cram_resched():
|
def test_cram_resched():
|
||||||
# add card
|
# add card
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# cram deck
|
# cram deck
|
||||||
did = d.decks.newDyn("Cram")
|
did = d.decks.newDyn("Cram")
|
||||||
cram = d.decks.get(did)
|
cram = d.decks.get(did)
|
||||||
@ -835,10 +835,10 @@ def test_ordcycle():
|
|||||||
mm.addTemplate(m, t)
|
mm.addTemplate(m, t)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
# create a new note; it should have 3 cards
|
# create a new note; it should have 3 cards
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = "1"
|
note["Back"] = "1"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert d.cardCount() == 3
|
assert d.cardCount() == 3
|
||||||
d.reset()
|
d.reset()
|
||||||
# ordinals should arrive in order
|
# ordinals should arrive in order
|
||||||
@ -849,10 +849,10 @@ def test_ordcycle():
|
|||||||
|
|
||||||
def test_counts_idx():
|
def test_counts_idx():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.counts() == (1, 0, 0)
|
assert d.sched.counts() == (1, 0, 0)
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
@ -873,9 +873,9 @@ def test_counts_idx():
|
|||||||
|
|
||||||
def test_repCounts():
|
def test_repCounts():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
# lrnReps should be accurate on pass/fail
|
# lrnReps should be accurate on pass/fail
|
||||||
assert d.sched.counts() == (1, 0, 0)
|
assert d.sched.counts() == (1, 0, 0)
|
||||||
@ -891,9 +891,9 @@ def test_repCounts():
|
|||||||
assert d.sched.counts() == (0, 1, 0)
|
assert d.sched.counts() == (0, 1, 0)
|
||||||
d.sched.answerCard(d.sched.getCard(), 2)
|
d.sched.answerCard(d.sched.getCard(), 2)
|
||||||
assert d.sched.counts() == (0, 0, 0)
|
assert d.sched.counts() == (0, 0, 0)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
# initial pass should be correct too
|
# initial pass should be correct too
|
||||||
d.sched.answerCard(d.sched.getCard(), 2)
|
d.sched.answerCard(d.sched.getCard(), 2)
|
||||||
@ -903,17 +903,17 @@ def test_repCounts():
|
|||||||
d.sched.answerCard(d.sched.getCard(), 3)
|
d.sched.answerCard(d.sched.getCard(), 3)
|
||||||
assert d.sched.counts() == (0, 0, 0)
|
assert d.sched.counts() == (0, 0, 0)
|
||||||
# immediate graduate should work
|
# immediate graduate should work
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
d.sched.answerCard(d.sched.getCard(), 3)
|
d.sched.answerCard(d.sched.getCard(), 3)
|
||||||
assert d.sched.counts() == (0, 0, 0)
|
assert d.sched.counts() == (0, 0, 0)
|
||||||
# and failing a review should too
|
# and failing a review should too
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = d.sched.today
|
c.due = d.sched.today
|
||||||
@ -928,10 +928,10 @@ def test_timing():
|
|||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a few review cards, due today
|
# add a few review cards, due today
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "num" + str(i)
|
note["Front"] = "num" + str(i)
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = 0
|
c.due = 0
|
||||||
@ -962,9 +962,9 @@ def test_timing():
|
|||||||
def test_collapse():
|
def test_collapse():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
# test collapsing
|
# test collapsing
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
@ -977,29 +977,29 @@ def test_collapse():
|
|||||||
def test_deckDue():
|
def test_deckDue():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note with default deck
|
# add a note with default deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and one that's a child
|
# and one that's a child
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
default1 = f.model()["did"] = d.decks.id("Default::1")
|
default1 = note.model()["did"] = d.decks.id("Default::1")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# make it a review card
|
# make it a review card
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = 0
|
c.due = 0
|
||||||
c.flush()
|
c.flush()
|
||||||
# add one more with a new deck
|
# add one more with a new deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
foobar = f.model()["did"] = d.decks.id("foo::bar")
|
foobar = note.model()["did"] = d.decks.id("foo::bar")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and one that's a sibling
|
# and one that's a sibling
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
foobaz = f.model()["did"] = d.decks.id("foo::baz")
|
foobaz = note.model()["did"] = d.decks.id("foo::baz")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert len(d.decks.all_names_and_ids()) == 5
|
assert len(d.decks.all_names_and_ids()) == 5
|
||||||
tree = d.sched.deck_due_tree().children
|
tree = d.sched.deck_due_tree().children
|
||||||
@ -1023,19 +1023,19 @@ def test_deckDue():
|
|||||||
def test_deckFlow():
|
def test_deckFlow():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note with default deck
|
# add a note with default deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and one that's a child
|
# and one that's a child
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
default1 = f.model()["did"] = d.decks.id("Default::2")
|
default1 = note.model()["did"] = d.decks.id("Default::2")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and another that's higher up
|
# and another that's higher up
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
default1 = f.model()["did"] = d.decks.id("Default::1")
|
default1 = note.model()["did"] = d.decks.id("Default::1")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# should get top level one first, then ::1, then ::2
|
# should get top level one first, then ::1, then ::2
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.counts() == (3, 0, 0)
|
assert d.sched.counts() == (3, 0, 0)
|
||||||
@ -1048,9 +1048,9 @@ def test_deckFlow():
|
|||||||
def test_reorder():
|
def test_reorder():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note with default deck
|
# add a note with default deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
f2 = d.newNote()
|
f2 = d.newNote()
|
||||||
f2["Front"] = "two"
|
f2["Front"] = "two"
|
||||||
d.addNote(f2)
|
d.addNote(f2)
|
||||||
@ -1059,12 +1059,12 @@ def test_reorder():
|
|||||||
# 50/50 chance of being reordered
|
# 50/50 chance of being reordered
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
d.sched.randomizeCards(1)
|
d.sched.randomizeCards(1)
|
||||||
if f.cards()[0].due != f.id:
|
if note.cards()[0].due != note.id:
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
assert found
|
assert found
|
||||||
d.sched.orderCards(1)
|
d.sched.orderCards(1)
|
||||||
assert f.cards()[0].due == 1
|
assert note.cards()[0].due == 1
|
||||||
# shifting
|
# shifting
|
||||||
f3 = d.newNote()
|
f3 = d.newNote()
|
||||||
f3["Front"] = "three"
|
f3["Front"] = "three"
|
||||||
@ -1072,12 +1072,12 @@ def test_reorder():
|
|||||||
f4 = d.newNote()
|
f4 = d.newNote()
|
||||||
f4["Front"] = "four"
|
f4["Front"] = "four"
|
||||||
d.addNote(f4)
|
d.addNote(f4)
|
||||||
assert f.cards()[0].due == 1
|
assert note.cards()[0].due == 1
|
||||||
assert f2.cards()[0].due == 2
|
assert f2.cards()[0].due == 2
|
||||||
assert f3.cards()[0].due == 3
|
assert f3.cards()[0].due == 3
|
||||||
assert f4.cards()[0].due == 4
|
assert f4.cards()[0].due == 4
|
||||||
d.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True)
|
d.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True)
|
||||||
assert f.cards()[0].due == 3
|
assert note.cards()[0].due == 3
|
||||||
assert f2.cards()[0].due == 4
|
assert f2.cards()[0].due == 4
|
||||||
assert f3.cards()[0].due == 1
|
assert f3.cards()[0].due == 1
|
||||||
assert f4.cards()[0].due == 2
|
assert f4.cards()[0].due == 2
|
||||||
@ -1085,10 +1085,10 @@ def test_reorder():
|
|||||||
|
|
||||||
def test_forget():
|
def test_forget():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
@ -1103,10 +1103,10 @@ def test_forget():
|
|||||||
|
|
||||||
def test_resched():
|
def test_resched():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
d.sched.reschedCards([c.id], 0, 0)
|
d.sched.reschedCards([c.id], 0, 0)
|
||||||
c.load()
|
c.load()
|
||||||
assert c.due == d.sched.today
|
assert c.due == d.sched.today
|
||||||
@ -1121,10 +1121,10 @@ def test_resched():
|
|||||||
def test_norelearn():
|
def test_norelearn():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = 0
|
c.due = 0
|
||||||
@ -1142,11 +1142,11 @@ def test_norelearn():
|
|||||||
|
|
||||||
def test_failmult():
|
def test_failmult():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
|
@ -38,10 +38,10 @@ def test_new():
|
|||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.newCount == 0
|
assert d.sched.newCount == 0
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.newCount == 1
|
assert d.sched.newCount == 1
|
||||||
# fetch it
|
# fetch it
|
||||||
@ -65,12 +65,12 @@ def test_new():
|
|||||||
# t['afmt'] = "{{Front}}"
|
# t['afmt'] = "{{Front}}"
|
||||||
# mm.addTemplate(m, t)
|
# mm.addTemplate(m, t)
|
||||||
# mm.save(m)
|
# mm.save(m)
|
||||||
# f = d.newNote()
|
# note = d.newNote()
|
||||||
# f['Front'] = u"2"; f['Back'] = u"2"
|
# note['Front'] = u"2"; note['Back'] = u"2"
|
||||||
# d.addNote(f)
|
# d.addNote(note)
|
||||||
# f = d.newNote()
|
# note = d.newNote()
|
||||||
# f['Front'] = u"3"; f['Back'] = u"3"
|
# note['Front'] = u"3"; note['Back'] = u"3"
|
||||||
# d.addNote(f)
|
# d.addNote(note)
|
||||||
# d.reset()
|
# d.reset()
|
||||||
# qs = ("2", "3", "2", "3")
|
# qs = ("2", "3", "2", "3")
|
||||||
# for n in range(4):
|
# for n in range(4):
|
||||||
@ -84,11 +84,11 @@ def test_newLimits():
|
|||||||
# add some notes
|
# add some notes
|
||||||
g2 = d.decks.id("Default::foo")
|
g2 = d.decks.id("Default::foo")
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = str(i)
|
note["Front"] = str(i)
|
||||||
if i > 4:
|
if i > 4:
|
||||||
f.model()["did"] = g2
|
note.model()["did"] = g2
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# give the child deck a different configuration
|
# give the child deck a different configuration
|
||||||
c2 = d.decks.add_config_returning_id("new conf")
|
c2 = d.decks.add_config_returning_id("new conf")
|
||||||
d.decks.setConf(d.decks.get(g2), c2)
|
d.decks.setConf(d.decks.get(g2), c2)
|
||||||
@ -114,9 +114,9 @@ def test_newLimits():
|
|||||||
|
|
||||||
def test_newBoxes():
|
def test_newBoxes():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
conf = d.sched._cardConf(c)
|
conf = d.sched._cardConf(c)
|
||||||
@ -132,10 +132,10 @@ def test_newBoxes():
|
|||||||
def test_learn():
|
def test_learn():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
# set as a learn card and rebuild queues
|
# set as a learn card and rebuild queues
|
||||||
d.db.execute("update cards set queue=0, type=0")
|
d.db.execute("update cards set queue=0, type=0")
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -194,10 +194,10 @@ def test_learn():
|
|||||||
|
|
||||||
def test_relearn():
|
def test_relearn():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
c.due = d.sched.today
|
c.due = d.sched.today
|
||||||
c.queue = CARD_TYPE_REV
|
c.queue = CARD_TYPE_REV
|
||||||
@ -221,10 +221,10 @@ def test_relearn():
|
|||||||
|
|
||||||
def test_relearn_no_steps():
|
def test_relearn_no_steps():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
c.due = d.sched.today
|
c.due = d.sched.today
|
||||||
c.queue = CARD_TYPE_REV
|
c.queue = CARD_TYPE_REV
|
||||||
@ -245,12 +245,12 @@ def test_relearn_no_steps():
|
|||||||
def test_learn_collapsed():
|
def test_learn_collapsed():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add 2 notes
|
# add 2 notes
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "2"
|
note["Front"] = "2"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
# set as a learn card and rebuild queues
|
# set as a learn card and rebuild queues
|
||||||
d.db.execute("update cards set queue=0, type=0")
|
d.db.execute("update cards set queue=0, type=0")
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -272,9 +272,9 @@ def test_learn_collapsed():
|
|||||||
def test_learn_day():
|
def test_learn_day():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f = d.addNote(f)
|
note = d.addNote(note)
|
||||||
d.sched.reset()
|
d.sched.reset()
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
conf = d.sched._cardConf(c)
|
conf = d.sched._cardConf(c)
|
||||||
@ -335,12 +335,12 @@ def test_learn_day():
|
|||||||
def test_reviews():
|
def test_reviews():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# set the card up as a review card, due 8 days ago
|
# set the card up as a review card, due 8 days ago
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = d.sched.today - 8
|
c.due = d.sched.today - 8
|
||||||
@ -431,13 +431,13 @@ def test_review_limits():
|
|||||||
|
|
||||||
# add some cards
|
# add some cards
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
|
|
||||||
# make them reviews
|
# make them reviews
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.queue = CARD_TYPE_REV
|
c.queue = CARD_TYPE_REV
|
||||||
c.type = QUEUE_TYPE_REV
|
c.type = QUEUE_TYPE_REV
|
||||||
c.due = 0
|
c.due = 0
|
||||||
@ -465,11 +465,11 @@ def test_review_limits():
|
|||||||
|
|
||||||
def test_button_spacing():
|
def test_button_spacing():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# 1 day ivl review card due now
|
# 1 day ivl review card due now
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = d.sched.today
|
c.due = d.sched.today
|
||||||
@ -496,11 +496,11 @@ def test_overdue_lapse():
|
|||||||
return
|
return
|
||||||
d = getEmptyCol() # pylint: disable=unreachable
|
d = getEmptyCol() # pylint: disable=unreachable
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# simulate a review that was lapsed and is now due for its normal review
|
# simulate a review that was lapsed and is now due for its normal review
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = 1
|
c.queue = 1
|
||||||
c.due = -1
|
c.due = -1
|
||||||
@ -532,15 +532,15 @@ def test_finished():
|
|||||||
# nothing due
|
# nothing due
|
||||||
assert "Congratulations" in d.sched.finishedMsg()
|
assert "Congratulations" in d.sched.finishedMsg()
|
||||||
assert "limit" not in d.sched.finishedMsg()
|
assert "limit" not in d.sched.finishedMsg()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# have a new card
|
# have a new card
|
||||||
assert "new cards available" in d.sched.finishedMsg()
|
assert "new cards available" in d.sched.finishedMsg()
|
||||||
# turn it into a review
|
# turn it into a review
|
||||||
d.reset()
|
d.reset()
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.startTimer()
|
c.startTimer()
|
||||||
d.sched.answerCard(c, 3)
|
d.sched.answerCard(c, 3)
|
||||||
# nothing should be due tomorrow, as it's due in a week
|
# nothing should be due tomorrow, as it's due in a week
|
||||||
@ -550,10 +550,10 @@ def test_finished():
|
|||||||
|
|
||||||
def test_nextIvl():
|
def test_nextIvl():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
conf = d.decks.confForDid(1)
|
conf = d.decks.confForDid(1)
|
||||||
conf["new"]["delays"] = [0.5, 3, 10]
|
conf["new"]["delays"] = [0.5, 3, 10]
|
||||||
@ -613,14 +613,14 @@ def test_nextIvl():
|
|||||||
|
|
||||||
def test_bury():
|
def test_bury():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c2 = f.cards()[0]
|
c2 = note.cards()[0]
|
||||||
# burying
|
# burying
|
||||||
d.sched.buryCards([c.id], manual=True) # pylint: disable=unexpected-keyword-arg
|
d.sched.buryCards([c.id], manual=True) # pylint: disable=unexpected-keyword-arg
|
||||||
c.load()
|
c.load()
|
||||||
@ -654,10 +654,10 @@ def test_bury():
|
|||||||
|
|
||||||
def test_suspend():
|
def test_suspend():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
# suspending
|
# suspending
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.getCard()
|
assert d.sched.getCard()
|
||||||
@ -704,10 +704,10 @@ def test_suspend():
|
|||||||
|
|
||||||
def test_filt_reviewing_early_normal():
|
def test_filt_reviewing_early_normal():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
c.queue = CARD_TYPE_REV
|
c.queue = CARD_TYPE_REV
|
||||||
c.type = QUEUE_TYPE_REV
|
c.type = QUEUE_TYPE_REV
|
||||||
@ -761,9 +761,9 @@ def test_filt_reviewing_early_normal():
|
|||||||
def test_filt_keep_lrn_state():
|
def test_filt_keep_lrn_state():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
|
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
|
|
||||||
# fail the card outside filtered deck
|
# fail the card outside filtered deck
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
@ -805,10 +805,10 @@ def test_filt_keep_lrn_state():
|
|||||||
def test_preview():
|
def test_preview():
|
||||||
# add cards
|
# add cards
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
orig = copy.copy(c)
|
orig = copy.copy(c)
|
||||||
f2 = d.newNote()
|
f2 = d.newNote()
|
||||||
f2["Front"] = "two"
|
f2["Front"] = "two"
|
||||||
@ -867,10 +867,10 @@ def test_ordcycle():
|
|||||||
mm.addTemplate(m, t)
|
mm.addTemplate(m, t)
|
||||||
mm.save(m)
|
mm.save(m)
|
||||||
# create a new note; it should have 3 cards
|
# create a new note; it should have 3 cards
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "1"
|
note["Front"] = "1"
|
||||||
f["Back"] = "1"
|
note["Back"] = "1"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
assert d.cardCount() == 3
|
assert d.cardCount() == 3
|
||||||
d.reset()
|
d.reset()
|
||||||
# ordinals should arrive in order
|
# ordinals should arrive in order
|
||||||
@ -881,10 +881,10 @@ def test_ordcycle():
|
|||||||
|
|
||||||
def test_counts_idx():
|
def test_counts_idx():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.counts() == (1, 0, 0)
|
assert d.sched.counts() == (1, 0, 0)
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
@ -905,9 +905,9 @@ def test_counts_idx():
|
|||||||
|
|
||||||
def test_repCounts():
|
def test_repCounts():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
# lrnReps should be accurate on pass/fail
|
# lrnReps should be accurate on pass/fail
|
||||||
assert d.sched.counts() == (1, 0, 0)
|
assert d.sched.counts() == (1, 0, 0)
|
||||||
@ -923,9 +923,9 @@ def test_repCounts():
|
|||||||
assert d.sched.counts() == (0, 1, 0)
|
assert d.sched.counts() == (0, 1, 0)
|
||||||
d.sched.answerCard(d.sched.getCard(), 3)
|
d.sched.answerCard(d.sched.getCard(), 3)
|
||||||
assert d.sched.counts() == (0, 0, 0)
|
assert d.sched.counts() == (0, 0, 0)
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
# initial pass should be correct too
|
# initial pass should be correct too
|
||||||
d.sched.answerCard(d.sched.getCard(), 3)
|
d.sched.answerCard(d.sched.getCard(), 3)
|
||||||
@ -935,17 +935,17 @@ def test_repCounts():
|
|||||||
d.sched.answerCard(d.sched.getCard(), 4)
|
d.sched.answerCard(d.sched.getCard(), 4)
|
||||||
assert d.sched.counts() == (0, 0, 0)
|
assert d.sched.counts() == (0, 0, 0)
|
||||||
# immediate graduate should work
|
# immediate graduate should work
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
d.sched.answerCard(d.sched.getCard(), 4)
|
d.sched.answerCard(d.sched.getCard(), 4)
|
||||||
assert d.sched.counts() == (0, 0, 0)
|
assert d.sched.counts() == (0, 0, 0)
|
||||||
# and failing a review should too
|
# and failing a review should too
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = d.sched.today
|
c.due = d.sched.today
|
||||||
@ -960,10 +960,10 @@ def test_timing():
|
|||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a few review cards, due today
|
# add a few review cards, due today
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "num" + str(i)
|
note["Front"] = "num" + str(i)
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = 0
|
c.due = 0
|
||||||
@ -986,9 +986,9 @@ def test_timing():
|
|||||||
def test_collapse():
|
def test_collapse():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
# test collapsing
|
# test collapsing
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
@ -1001,29 +1001,29 @@ def test_collapse():
|
|||||||
def test_deckDue():
|
def test_deckDue():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note with default deck
|
# add a note with default deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and one that's a child
|
# and one that's a child
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
default1 = f.model()["did"] = d.decks.id("Default::1")
|
default1 = note.model()["did"] = d.decks.id("Default::1")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# make it a review card
|
# make it a review card
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = 0
|
c.due = 0
|
||||||
c.flush()
|
c.flush()
|
||||||
# add one more with a new deck
|
# add one more with a new deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
foobar = f.model()["did"] = d.decks.id("foo::bar")
|
foobar = note.model()["did"] = d.decks.id("foo::bar")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and one that's a sibling
|
# and one that's a sibling
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
foobaz = f.model()["did"] = d.decks.id("foo::baz")
|
foobaz = note.model()["did"] = d.decks.id("foo::baz")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert len(d.decks.all_names_and_ids()) == 5
|
assert len(d.decks.all_names_and_ids()) == 5
|
||||||
tree = d.sched.deck_due_tree().children
|
tree = d.sched.deck_due_tree().children
|
||||||
@ -1057,19 +1057,19 @@ def test_deckTree():
|
|||||||
def test_deckFlow():
|
def test_deckFlow():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note with default deck
|
# add a note with default deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and one that's a child
|
# and one that's a child
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
default1 = f.model()["did"] = d.decks.id("Default::2")
|
default1 = note.model()["did"] = d.decks.id("Default::2")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# and another that's higher up
|
# and another that's higher up
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "three"
|
note["Front"] = "three"
|
||||||
default1 = f.model()["did"] = d.decks.id("Default::1")
|
default1 = note.model()["did"] = d.decks.id("Default::1")
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
# should get top level one first, then ::1, then ::2
|
# should get top level one first, then ::1, then ::2
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.counts() == (3, 0, 0)
|
assert d.sched.counts() == (3, 0, 0)
|
||||||
@ -1082,9 +1082,9 @@ def test_deckFlow():
|
|||||||
def test_reorder():
|
def test_reorder():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note with default deck
|
# add a note with default deck
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
f2 = d.newNote()
|
f2 = d.newNote()
|
||||||
f2["Front"] = "two"
|
f2["Front"] = "two"
|
||||||
d.addNote(f2)
|
d.addNote(f2)
|
||||||
@ -1093,12 +1093,12 @@ def test_reorder():
|
|||||||
# 50/50 chance of being reordered
|
# 50/50 chance of being reordered
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
d.sched.randomizeCards(1)
|
d.sched.randomizeCards(1)
|
||||||
if f.cards()[0].due != f.id:
|
if note.cards()[0].due != note.id:
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
assert found
|
assert found
|
||||||
d.sched.orderCards(1)
|
d.sched.orderCards(1)
|
||||||
assert f.cards()[0].due == 1
|
assert note.cards()[0].due == 1
|
||||||
# shifting
|
# shifting
|
||||||
f3 = d.newNote()
|
f3 = d.newNote()
|
||||||
f3["Front"] = "three"
|
f3["Front"] = "three"
|
||||||
@ -1106,12 +1106,12 @@ def test_reorder():
|
|||||||
f4 = d.newNote()
|
f4 = d.newNote()
|
||||||
f4["Front"] = "four"
|
f4["Front"] = "four"
|
||||||
d.addNote(f4)
|
d.addNote(f4)
|
||||||
assert f.cards()[0].due == 1
|
assert note.cards()[0].due == 1
|
||||||
assert f2.cards()[0].due == 2
|
assert f2.cards()[0].due == 2
|
||||||
assert f3.cards()[0].due == 3
|
assert f3.cards()[0].due == 3
|
||||||
assert f4.cards()[0].due == 4
|
assert f4.cards()[0].due == 4
|
||||||
d.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True)
|
d.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True)
|
||||||
assert f.cards()[0].due == 3
|
assert note.cards()[0].due == 3
|
||||||
assert f2.cards()[0].due == 4
|
assert f2.cards()[0].due == 4
|
||||||
assert f3.cards()[0].due == 1
|
assert f3.cards()[0].due == 1
|
||||||
assert f4.cards()[0].due == 2
|
assert f4.cards()[0].due == 2
|
||||||
@ -1119,10 +1119,10 @@ def test_reorder():
|
|||||||
|
|
||||||
def test_forget():
|
def test_forget():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
@ -1137,10 +1137,10 @@ def test_forget():
|
|||||||
|
|
||||||
def test_resched():
|
def test_resched():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
d.sched.reschedCards([c.id], 0, 0)
|
d.sched.reschedCards([c.id], 0, 0)
|
||||||
c.load()
|
c.load()
|
||||||
assert c.due == d.sched.today
|
assert c.due == d.sched.today
|
||||||
@ -1155,10 +1155,10 @@ def test_resched():
|
|||||||
def test_norelearn():
|
def test_norelearn():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
# add a note
|
# add a note
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.due = 0
|
c.due = 0
|
||||||
@ -1176,11 +1176,11 @@ def test_norelearn():
|
|||||||
|
|
||||||
def test_failmult():
|
def test_failmult():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.type = CARD_TYPE_REV
|
c.type = CARD_TYPE_REV
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
@ -1264,11 +1264,11 @@ def test_negativeDueFilter():
|
|||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
|
|
||||||
# card due prior to collection date
|
# card due prior to collection date
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
c.due = -5
|
c.due = -5
|
||||||
c.queue = QUEUE_TYPE_REV
|
c.queue = QUEUE_TYPE_REV
|
||||||
c.ivl = 5
|
c.ivl = 5
|
||||||
@ -1288,10 +1288,10 @@ def test_negativeDueFilter():
|
|||||||
# and it should be logged properly
|
# and it should be logged properly
|
||||||
def test_initial_repeat():
|
def test_initial_repeat():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
f["Back"] = "two"
|
note["Back"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
|
|
||||||
d.reset()
|
d.reset()
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
|
@ -9,10 +9,10 @@ from tests.shared import getEmptyCol
|
|||||||
|
|
||||||
def test_stats():
|
def test_stats():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "foo"
|
note["Front"] = "foo"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
c = f.cards()[0]
|
c = note.cards()[0]
|
||||||
# card stats
|
# card stats
|
||||||
assert d.cardStats(c)
|
assert d.cardStats(c)
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -32,6 +32,6 @@ def test_graphs():
|
|||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
g = d.stats()
|
g = d.stats()
|
||||||
rep = g.report()
|
rep = g.report()
|
||||||
with open(os.path.join(dir, "test.html"), "w", encoding="UTF-8") as f:
|
with open(os.path.join(dir, "test.html"), "w", encoding="UTF-8") as note:
|
||||||
f.write(rep)
|
note.write(rep)
|
||||||
return
|
return
|
||||||
|
@ -7,9 +7,9 @@ def test_deferred_frontside():
|
|||||||
m["tmpls"][0]["qfmt"] = "{{custom:Front}}"
|
m["tmpls"][0]["qfmt"] = "{{custom:Front}}"
|
||||||
d.models.save(m)
|
d.models.save(m)
|
||||||
|
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "xxtest"
|
note["Front"] = "xxtest"
|
||||||
f["Back"] = ""
|
note["Back"] = ""
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
|
|
||||||
assert "xxtest" in f.cards()[0].a()
|
assert "xxtest" in note.cards()[0].a()
|
||||||
|
@ -34,9 +34,9 @@ def test_op():
|
|||||||
assert not d.undoName()
|
assert not d.undoName()
|
||||||
# and a review will, too
|
# and a review will, too
|
||||||
d.save("add")
|
d.save("add")
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.undoName() == "add"
|
assert d.undoName() == "add"
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
@ -47,9 +47,9 @@ def test_op():
|
|||||||
def test_review():
|
def test_review():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
d.conf["counts"] = COUNT_REMAINING
|
d.conf["counts"] = COUNT_REMAINING
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "one"
|
note["Front"] = "one"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert not d.undoName()
|
assert not d.undoName()
|
||||||
# answer
|
# answer
|
||||||
@ -70,9 +70,9 @@ def test_review():
|
|||||||
assert c.left != 1001
|
assert c.left != 1001
|
||||||
assert not d.undoName()
|
assert not d.undoName()
|
||||||
# we should be able to undo multiple answers too
|
# we should be able to undo multiple answers too
|
||||||
f = d.newNote()
|
note = d.newNote()
|
||||||
f["Front"] = "two"
|
note["Front"] = "two"
|
||||||
d.addNote(f)
|
d.addNote(note)
|
||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.counts() == (2, 0, 0)
|
assert d.sched.counts() == (2, 0, 0)
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
|
Loading…
Reference in New Issue
Block a user