From 2c73dcb2e547c44d9e02c20a00f3c52419dc277b Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Fri, 17 Jul 2020 05:21:12 +0200 Subject: [PATCH] d->col in tests obtained by ``` sed -i "s/\bd\b/col/g" pylib/tests/*py qt/tests/*py ``` --- pylib/tests/test_cards.py | 39 +- pylib/tests/test_collection.py | 8 +- pylib/tests/test_decks.py | 68 +-- pylib/tests/test_find.py | 4 +- pylib/tests/test_latex.py | 36 +- pylib/tests/test_media.py | 36 +- pylib/tests/test_models.py | 176 +++--- pylib/tests/test_schedv1.py | 944 ++++++++++++++++---------------- pylib/tests/test_schedv2.py | 956 +++++++++++++++++---------------- pylib/tests/test_stats.py | 26 +- pylib/tests/test_template.py | 10 +- pylib/tests/test_undo.py | 116 ++-- 12 files changed, 1212 insertions(+), 1207 deletions(-) diff --git a/pylib/tests/test_cards.py b/pylib/tests/test_cards.py index 7c94aa0eb..8ed06fa17 100644 --- a/pylib/tests/test_cards.py +++ b/pylib/tests/test_cards.py @@ -21,25 +21,25 @@ def test_delete(): def test_misc(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "1" note["Back"] = "2" - d.addNote(note) + col.addNote(note) c = note.cards()[0] - id = d.models.current()["id"] + id = col.models.current()["id"] assert c.template()["ord"] == 0 def test_genrem(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "1" note["Back"] = "" - d.addNote(note) + col.addNote(note) assert len(note.cards()) == 1 - m = d.models.current() - mm = d.models + m = col.models.current() + mm = col.models # adding a new template should automatically create cards t = mm.newTemplate("rev") t["qfmt"] = "{{Front}}" @@ -51,9 +51,10 @@ def test_genrem(): t = m["tmpls"][1] t["qfmt"] = "{{Back}}" mm.save(m, templates=True) - rep = d.backend.get_empty_cards() + rep = col.backend.get_empty_cards() + rep = col.backend.get_empty_cards() for n in rep.notes: - d.remove_cards_and_orphaned_notes(n.card_ids) + col.remove_cards_and_orphaned_notes(n.card_ids) assert len(note.cards()) == 1 # if we add to the note, a card should be automatically generated note.load() @@ -63,18 +64,18 @@ def test_genrem(): def test_gendeck(): - d = getEmptyCol() - cloze = d.models.byName("Cloze") - d.models.setCurrent(cloze) - note = d.newNote() + col = getEmptyCol() + cloze = col.models.byName("Cloze") + col.models.setCurrent(cloze) + note = col.newNote() note["Text"] = "{{c1::one}}" - d.addNote(note) - assert d.cardCount() == 1 + col.addNote(note) + assert col.cardCount() == 1 assert note.cards()[0].did == 1 # set the model to a new default col - newId = d.decks.id("new") + newId = col.decks.id("new") cloze["did"] = newId - d.models.save(cloze, updateReqs=False) + col.models.save(cloze, updateReqs=False) # a newly generated card should share the first card's col note["Text"] += "{{c2::two}}" note.flush() diff --git a/pylib/tests/test_collection.py b/pylib/tests/test_collection.py index 00f199788..601ca9dc2 100644 --- a/pylib/tests/test_collection.py +++ b/pylib/tests/test_collection.py @@ -148,15 +148,15 @@ def test_furigana(): def test_translate(): - d = getEmptyCol() + col = getEmptyCol() no_uni = without_unicode_isolation assert ( - d.tr(TR.CARD_TEMPLATE_RENDERING_FRONT_SIDE_PROBLEM) + col.tr(TR.CARD_TEMPLATE_RENDERING_FRONT_SIDE_PROBLEM) == "Front template has a problem:" ) - assert no_uni(d.tr(TR.STATISTICS_REVIEWS, reviews=1)) == "1 review" - assert no_uni(d.tr(TR.STATISTICS_REVIEWS, reviews=2)) == "2 reviews" + assert no_uni(col.tr(TR.STATISTICS_REVIEWS, reviews=1)) == "1 review" + assert no_uni(col.tr(TR.STATISTICS_REVIEWS, reviews=2)) == "2 reviews" def test_db_named_args(capsys): diff --git a/pylib/tests/test_decks.py b/pylib/tests/test_decks.py index ab2d0b677..005d46aa3 100644 --- a/pylib/tests/test_decks.py +++ b/pylib/tests/test_decks.py @@ -61,85 +61,85 @@ def test_remove(): def test_rename(): - d = getEmptyCol() - id = d.decks.id("hello::world") + col = getEmptyCol() + id = col.decks.id("hello::world") # should be able to rename into a completely different branch, creating # parents as necessary - d.decks.rename(d.decks.get(id), "foo::bar") - names = [n.name for n in d.decks.all_names_and_ids()] + col.decks.rename(col.decks.get(id), "foo::bar") + names = [n.name for n in col.decks.all_names_and_ids()] assert "foo" in names assert "foo::bar" in names assert "hello::world" not in names # create another col - id = d.decks.id("tmp") + id = col.decks.id("tmp") # automatically adjusted if a duplicate name - d.decks.rename(d.decks.get(id), "FOO") - names = [n.name for n in d.decks.all_names_and_ids()] + col.decks.rename(col.decks.get(id), "FOO") + names = [n.name for n in col.decks.all_names_and_ids()] assert "FOO+" in names # when renaming, the children should be renamed too - d.decks.id("one::two::three") - id = d.decks.id("one") - d.decks.rename(d.decks.get(id), "yo") - names = [n.name for n in d.decks.all_names_and_ids()] + col.decks.id("one::two::three") + id = col.decks.id("one") + col.decks.rename(col.decks.get(id), "yo") + names = [n.name for n in col.decks.all_names_and_ids()] for n in "yo", "yo::two", "yo::two::three": assert n in names # over filtered - filteredId = d.decks.newDyn("filtered") - filtered = d.decks.get(filteredId) - childId = d.decks.id("child") - child = d.decks.get(childId) - assertException(DeckRenameError, lambda: d.decks.rename(child, "filtered::child")) - assertException(DeckRenameError, lambda: d.decks.rename(child, "FILTERED::child")) + filteredId = col.decks.newDyn("filtered") + filtered = col.decks.get(filteredId) + childId = col.decks.id("child") + child = col.decks.get(childId) + assertException(DeckRenameError, lambda: col.decks.rename(child, "filtered::child")) + assertException(DeckRenameError, lambda: col.decks.rename(child, "FILTERED::child")) def test_renameForDragAndDrop(): - d = getEmptyCol() + col = getEmptyCol() def deckNames(): - return [n.name for n in d.decks.all_names_and_ids(skip_empty_default=True)] + return [n.name for n in col.decks.all_names_and_ids(skip_empty_default=True)] - languages_did = d.decks.id("Languages") - chinese_did = d.decks.id("Chinese") - hsk_did = d.decks.id("Chinese::HSK") + languages_did = col.decks.id("Languages") + chinese_did = col.decks.id("Chinese") + hsk_did = col.decks.id("Chinese::HSK") # Renaming also renames children - d.decks.renameForDragAndDrop(chinese_did, languages_did) + col.decks.renameForDragAndDrop(chinese_did, languages_did) assert deckNames() == ["Languages", "Languages::Chinese", "Languages::Chinese::HSK"] # Dragging a col onto itself is a no-op - d.decks.renameForDragAndDrop(languages_did, languages_did) + col.decks.renameForDragAndDrop(languages_did, languages_did) assert deckNames() == ["Languages", "Languages::Chinese", "Languages::Chinese::HSK"] # Dragging a col onto its parent is a no-op - d.decks.renameForDragAndDrop(hsk_did, chinese_did) + col.decks.renameForDragAndDrop(hsk_did, chinese_did) assert deckNames() == ["Languages", "Languages::Chinese", "Languages::Chinese::HSK"] # Dragging a col onto a descendant is a no-op - d.decks.renameForDragAndDrop(languages_did, hsk_did) + col.decks.renameForDragAndDrop(languages_did, hsk_did) assert deckNames() == ["Languages", "Languages::Chinese", "Languages::Chinese::HSK"] # Can drag a grandchild onto its grandparent. It becomes a child - d.decks.renameForDragAndDrop(hsk_did, languages_did) + col.decks.renameForDragAndDrop(hsk_did, languages_did) assert deckNames() == ["Languages", "Languages::Chinese", "Languages::HSK"] # Can drag a col onto its sibling - d.decks.renameForDragAndDrop(hsk_did, chinese_did) + col.decks.renameForDragAndDrop(hsk_did, chinese_did) assert deckNames() == ["Languages", "Languages::Chinese", "Languages::Chinese::HSK"] # Can drag a col back to the top level - d.decks.renameForDragAndDrop(chinese_did, None) + col.decks.renameForDragAndDrop(chinese_did, None) assert deckNames() == ["Chinese", "Chinese::HSK", "Languages"] # Dragging a top level col to the top level is a no-op - d.decks.renameForDragAndDrop(chinese_did, None) + col.decks.renameForDragAndDrop(chinese_did, None) assert deckNames() == ["Chinese", "Chinese::HSK", "Languages"] # decks are renamed if necessary - new_hsk_did = d.decks.id("hsk") - d.decks.renameForDragAndDrop(new_hsk_did, chinese_did) + new_hsk_did = col.decks.id("hsk") + col.decks.renameForDragAndDrop(new_hsk_did, chinese_did) assert deckNames() == ["Chinese", "Chinese::HSK", "Chinese::hsk+", "Languages"] - d.decks.rem(new_hsk_did) + col.decks.rem(new_hsk_did) # '' is a convenient alias for the top level DID - d.decks.renameForDragAndDrop(hsk_did, "") + col.decks.renameForDragAndDrop(hsk_did, "") assert deckNames() == ["Chinese", "HSK", "Languages"] diff --git a/pylib/tests/test_find.py b/pylib/tests/test_find.py index 573f94726..1372a9885 100644 --- a/pylib/tests/test_find.py +++ b/pylib/tests/test_find.py @@ -90,8 +90,8 @@ def test_findCards(): assert col.findCards("is:suspended") == [c.id] # nids assert col.findCards("nid:54321") == [] - assert len(col.findCards("nid:%d" % note.id)) == 2 - assert len(col.findCards("nid:%d,%d" % (f1id, f2id))) == 2 + assert len(col.findCards(f"nid:{note.id}")) == 2 + assert len(col.findCards(f"nid:{f1id},{f2id}")) == 2 # templates assert len(col.findCards("card:foo")) == 0 assert len(col.findCards('"card:card 1"')) == 4 diff --git a/pylib/tests/test_latex.py b/pylib/tests/test_latex.py index e21022f55..befd063ea 100644 --- a/pylib/tests/test_latex.py +++ b/pylib/tests/test_latex.py @@ -7,17 +7,17 @@ from tests.shared import getEmptyCol def test_latex(): - d = getEmptyCol() + col = getEmptyCol() # change latex cmd to simulate broken build import anki.latex anki.latex.pngCommands[0][0] = "nolatex" # add a note with latex - note = d.newNote() + note = col.newNote() note["Front"] = "[latex]hello[/latex]" - d.addNote(note) + col.addNote(note) # but since latex couldn't run, there's nothing there - assert len(os.listdir(d.media.dir())) == 0 + assert len(os.listdir(col.media.dir())) == 0 # check the error message msg = note.cards()[0].q() assert "executing nolatex" in msg @@ -29,29 +29,29 @@ def test_latex(): # fix path anki.latex.pngCommands[0][0] = "latex" # check media db should cause latex to be generated - d.media.render_all_latex() - assert len(os.listdir(d.media.dir())) == 1 + col.media.render_all_latex() + assert len(os.listdir(col.media.dir())) == 1 assert ".png" in note.cards()[0].q() # adding new notes should cause generation on question display - note = d.newNote() + note = col.newNote() note["Front"] = "[latex]world[/latex]" - d.addNote(note) + col.addNote(note) note.cards()[0].q() - assert len(os.listdir(d.media.dir())) == 2 + assert len(os.listdir(col.media.dir())) == 2 # another note with the same media should reuse - note = d.newNote() + note = col.newNote() note["Front"] = " [latex]world[/latex]" - d.addNote(note) - assert len(os.listdir(d.media.dir())) == 2 + col.addNote(note) + assert len(os.listdir(col.media.dir())) == 2 oldcard = note.cards()[0] assert ".png" in oldcard.q() # if we turn off building, then previous cards should work, but cards with # missing media will show a broken image anki.latex.build = False - note = d.newNote() + note = col.newNote() note["Front"] = "[latex]foo[/latex]" - d.addNote(note) - assert len(os.listdir(d.media.dir())) == 2 + col.addNote(note) + assert len(os.listdir(col.media.dir())) == 2 assert ".png" in oldcard.q() # turn it on again so other test don't suffer anki.latex.build = True @@ -87,9 +87,9 @@ def test_latex(): def _test_includes_bad_command(bad): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "[latex]%s[/latex]" % bad - d.addNote(note) + col.addNote(note) q = note.cards()[0].q() return ("'%s' is not allowed on cards" % bad in q, "Card content: %s" % q) diff --git a/pylib/tests/test_media.py b/pylib/tests/test_media.py index d7fc6b332..5f17af373 100644 --- a/pylib/tests/test_media.py +++ b/pylib/tests/test_media.py @@ -8,25 +8,25 @@ from .shared import getEmptyCol, testDir # copying files to media folder def test_add(): - d = getEmptyCol() + col = getEmptyCol() dir = tempfile.mkdtemp(prefix="anki") path = os.path.join(dir, "foo.jpg") with open(path, "w") as note: note.write("hello") # new file, should preserve name - assert d.media.addFile(path) == "foo.jpg" + assert col.media.addFile(path) == "foo.jpg" # adding the same file again should not create a duplicate - assert d.media.addFile(path) == "foo.jpg" + assert col.media.addFile(path) == "foo.jpg" # but if it has a different sha1, it should with open(path, "w") as note: note.write("world") - assert d.media.addFile(path) == "foo-7c211433f02071597741e6ff5a8ea34789abbf43.jpg" + assert col.media.addFile(path) == "foo-7c211433f02071597741e6ff5a8ea34789abbf43.jpg" def test_strings(): - d = getEmptyCol() - mf = d.media.filesInStr - mid = d.models.current()["id"] + col = getEmptyCol() + mf = col.media.filesInStr + mid = col.models.current()["id"] assert mf(mid, "aoeu") == [] assert mf(mid, "aoeuao") == ["foo.jpg"] assert mf(mid, "aoeuao") == ["foo.jpg"] @@ -42,37 +42,37 @@ def test_strings(): "fo", ] assert mf(mid, "aou[sound:foo.mp3]aou") == ["foo.mp3"] - sp = d.media.strip + sp = col.media.strip assert sp("aoeu") == "aoeu" assert sp("aoeu[sound:foo.mp3]aoeu") == "aoeuaoeu" assert sp("aoeu") == "aoeu" - es = d.media.escapeImages + es = col.media.escapeImages assert es("aoeu") == "aoeu" assert es("") == "" assert es('') == '' def test_deckIntegration(): - d = getEmptyCol() + col = getEmptyCol() # create a media dir - d.media.dir() + col.media.dir() # put a file into it file = str(os.path.join(testDir, "support/fake.png")) - d.media.addFile(file) + col.media.addFile(file) # add a note which references it - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "" - d.addNote(note) + col.addNote(note) # and one which references a non-existent file - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "" - d.addNote(note) + col.addNote(note) # and add another file which isn't used - with open(os.path.join(d.media.dir(), "foo.jpg"), "w") as note: + with open(os.path.join(col.media.dir(), "foo.jpg"), "w") as note: note.write("test") # check media - ret = d.media.check() + ret = col.media.check() assert ret.missing == ["fake2.png"] assert ret.unused == ["foo.jpg"] diff --git a/pylib/tests/test_models.py b/pylib/tests/test_models.py index 7afaf4ca9..5f2827cc6 100644 --- a/pylib/tests/test_models.py +++ b/pylib/tests/test_models.py @@ -33,79 +33,79 @@ def test_modelCopy(): def test_fields(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "1" note["Back"] = "2" - d.addNote(note) - m = d.models.current() + col.addNote(note) + m = col.models.current() # make sure renaming a field updates the templates - d.models.renameField(m, m["flds"][0], "NewFront") + col.models.renameField(m, m["flds"][0], "NewFront") assert "{{NewFront}}" in m["tmpls"][0]["qfmt"] - h = d.models.scmhash(m) + h = col.models.scmhash(m) # add a field - note = d.models.newField("foo") - d.models.addField(m, note) - assert d.getNote(d.models.nids(m)[0]).fields == ["1", "2", ""] - assert d.models.scmhash(m) != h + note = col.models.newField("foo") + col.models.addField(m, note) + assert col.getNote(col.models.nids(m)[0]).fields == ["1", "2", ""] + assert col.models.scmhash(m) != h # rename it note = m["flds"][2] - d.models.renameField(m, note, "bar") - assert d.getNote(d.models.nids(m)[0])["bar"] == "" + col.models.renameField(m, note, "bar") + assert col.getNote(col.models.nids(m)[0])["bar"] == "" # delete back - d.models.remField(m, m["flds"][1]) - assert d.getNote(d.models.nids(m)[0]).fields == ["1", ""] + col.models.remField(m, m["flds"][1]) + assert col.getNote(col.models.nids(m)[0]).fields == ["1", ""] # move 0 -> 1 - d.models.moveField(m, m["flds"][0], 1) - assert d.getNote(d.models.nids(m)[0]).fields == ["", "1"] + col.models.moveField(m, m["flds"][0], 1) + assert col.getNote(col.models.nids(m)[0]).fields == ["", "1"] # move 1 -> 0 - d.models.moveField(m, m["flds"][1], 0) - assert d.getNote(d.models.nids(m)[0]).fields == ["1", ""] + col.models.moveField(m, m["flds"][1], 0) + assert col.getNote(col.models.nids(m)[0]).fields == ["1", ""] # add another and put in middle - note = d.models.newField("baz") - d.models.addField(m, note) - note = d.getNote(d.models.nids(m)[0]) + note = col.models.newField("baz") + col.models.addField(m, note) + note = col.getNote(col.models.nids(m)[0]) note["baz"] = "2" note.flush() - assert d.getNote(d.models.nids(m)[0]).fields == ["1", "", "2"] + assert col.getNote(col.models.nids(m)[0]).fields == ["1", "", "2"] # move 2 -> 1 - d.models.moveField(m, m["flds"][2], 1) - assert d.getNote(d.models.nids(m)[0]).fields == ["1", "2", ""] + col.models.moveField(m, m["flds"][2], 1) + assert col.getNote(col.models.nids(m)[0]).fields == ["1", "2", ""] # move 0 -> 2 - d.models.moveField(m, m["flds"][0], 2) - assert d.getNote(d.models.nids(m)[0]).fields == ["2", "", "1"] + col.models.moveField(m, m["flds"][0], 2) + assert col.getNote(col.models.nids(m)[0]).fields == ["2", "", "1"] # move 0 -> 1 - d.models.moveField(m, m["flds"][0], 1) - assert d.getNote(d.models.nids(m)[0]).fields == ["", "2", "1"] + col.models.moveField(m, m["flds"][0], 1) + assert col.getNote(col.models.nids(m)[0]).fields == ["", "2", "1"] def test_templates(): - d = getEmptyCol() - m = d.models.current() - mm = d.models + col = getEmptyCol() + m = col.models.current() + mm = col.models t = mm.newTemplate("Reverse") t["qfmt"] = "{{Back}}" t["afmt"] = "{{Front}}" mm.addTemplate(m, t) mm.save(m) - note = d.newNote() + note = col.newNote() note["Front"] = "1" note["Back"] = "2" - d.addNote(note) - assert d.cardCount() == 2 + col.addNote(note) + assert col.cardCount() == 2 (c, c2) = note.cards() # first card should have first ord assert c.ord == 0 assert c2.ord == 1 # switch templates - d.models.moveTemplate(m, c.template(), 1) + col.models.moveTemplate(m, c.template(), 1) c.load() c2.load() assert c.ord == 1 assert c2.ord == 0 # removing a template should delete its cards - d.models.remTemplate(m, m["tmpls"][0]) - assert d.cardCount() == 1 + col.models.remTemplate(m, m["tmpls"][0]) + assert col.cardCount() == 1 # and should have updated the other cards' ordinals c = note.cards()[0] assert c.ord == 0 @@ -113,18 +113,20 @@ def test_templates(): # it shouldn't be possible to orphan notes by removing templates t = mm.newTemplate("template name") mm.addTemplate(m, t) - d.models.remTemplate(m, m["tmpls"][0]) + col.models.remTemplate(m, m["tmpls"][0]) assert ( - d.db.scalar("select count() from cards where nid not in (select id from notes)") + col.db.scalar( + "select count() from cards where nid not in (select id from notes)" + ) == 0 ) def test_cloze_ordinals(): - d = getEmptyCol() - d.models.setCurrent(d.models.byName("Cloze")) - m = d.models.current() - mm = d.models + col = getEmptyCol() + col.models.setCurrent(col.models.byName("Cloze")) + m = col.models.current() + mm = col.models # We replace the default Cloze template t = mm.newTemplate("ChainedCloze") @@ -132,12 +134,12 @@ def test_cloze_ordinals(): t["afmt"] = "{{text:cloze:Text}}" mm.addTemplate(m, t) mm.save(m) - d.models.remTemplate(m, m["tmpls"][0]) + col.models.remTemplate(m, m["tmpls"][0]) - note = d.newNote() + note = col.newNote() note["Text"] = "{{c1::firstQ::firstA}}{{c2::secondQ::secondA}}" - d.addNote(note) - assert d.cardCount() == 2 + col.addNote(note) + assert col.cardCount() == 2 (c, c2) = note.cards() # first card should have first ord assert c.ord == 0 @@ -145,40 +147,40 @@ def test_cloze_ordinals(): def test_text(): - d = getEmptyCol() - m = d.models.current() + col = getEmptyCol() + m = col.models.current() m["tmpls"][0]["qfmt"] = "{{text:Front}}" - d.models.save(m) - note = d.newNote() + col.models.save(m) + note = col.newNote() note["Front"] = "helloworld" - d.addNote(note) + col.addNote(note) assert "helloworld" in note.cards()[0].q() def test_cloze(): - d = getEmptyCol() - d.models.setCurrent(d.models.byName("Cloze")) - note = d.newNote() + col = getEmptyCol() + col.models.setCurrent(col.models.byName("Cloze")) + note = col.newNote() assert note.model()["name"] == "Cloze" # a cloze model with no clozes is not empty note["Text"] = "nothing" - assert d.addNote(note) + assert col.addNote(note) # try with one cloze - note = d.newNote() + note = col.newNote() note["Text"] = "hello {{c1::world}}" - assert d.addNote(note) == 1 + assert col.addNote(note) == 1 assert "hello [...]" in note.cards()[0].q() assert "hello world" in note.cards()[0].a() # and with a comment - note = d.newNote() + note = col.newNote() note["Text"] = "hello {{c1::world::typical}}" - assert d.addNote(note) == 1 + assert col.addNote(note) == 1 assert "[typical]" in note.cards()[0].q() assert "world" in note.cards()[0].a() # and with 2 clozes - note = d.newNote() + note = col.newNote() note["Text"] = "hello {{c1::world}} {{c2::bar}}" - assert d.addNote(note) == 2 + assert col.addNote(note) == 2 (c1, c2) = note.cards() assert "[...] bar" in c1.q() assert "world bar" in c1.a() @@ -186,17 +188,17 @@ def test_cloze(): assert "world bar" in c2.a() # if there are multiple answers for a single cloze, they are given in a # list - note = d.newNote() + note = col.newNote() note["Text"] = "a {{c1::b}} {{c1::c}}" - assert d.addNote(note) == 1 + assert col.addNote(note) == 1 assert "b c" in ( note.cards()[0].a() ) # if we add another cloze, a card should be generated - cnt = d.cardCount() + cnt = col.cardCount() note["Text"] = "{{c2::hello}} {{c1::foo}}" note.flush() - assert d.cardCount() == cnt + 1 + assert col.cardCount() == cnt + 1 # 0 or negative indices are not supported note["Text"] += "{{c0::zero}} {{c-1:foo}}" note.flush() @@ -204,13 +206,13 @@ def test_cloze(): def test_cloze_mathjax(): - d = getEmptyCol() - d.models.setCurrent(d.models.byName("Cloze")) - note = d.newNote() + col = getEmptyCol() + col.models.setCurrent(col.models.byName("Cloze")) + note = col.newNote() note[ "Text" ] = r"{{c1::ok}} \(2^2\) {{c2::not ok}} \(2^{{c3::2}}\) \(x^3\) {{c4::blah}} {{c5::text with \(x^2\) jax}}" - assert d.addNote(note) + assert col.addNote(note) assert len(note.cards()) == 5 assert "class=cloze" in note.cards()[0].q() assert "class=cloze" in note.cards()[1].q() @@ -218,9 +220,9 @@ def test_cloze_mathjax(): assert "class=cloze" in note.cards()[3].q() assert "class=cloze" in note.cards()[4].q() - note = d.newNote() + note = col.newNote() note["Text"] = r"\(a\) {{c1::b}} \[ {{c1::c}} \]" - assert d.addNote(note) + assert col.addNote(note) assert len(note.cards()) == 1 assert ( note.cards()[0] @@ -230,22 +232,22 @@ def test_cloze_mathjax(): def test_typecloze(): - d = getEmptyCol() - m = d.models.byName("Cloze") - d.models.setCurrent(m) + col = getEmptyCol() + m = col.models.byName("Cloze") + col.models.setCurrent(m) m["tmpls"][0]["qfmt"] = "{{cloze:Text}}{{type:cloze:Text}}" - d.models.save(m) - note = d.newNote() + col.models.save(m) + note = col.newNote() note["Text"] = "hello {{c1::world}}" - d.addNote(note) + col.addNote(note) assert "[[type:cloze:Text]]" in note.cards()[0].q() def test_chained_mods(): - d = getEmptyCol() - d.models.setCurrent(d.models.byName("Cloze")) - m = d.models.current() - mm = d.models + col = getEmptyCol() + col.models.setCurrent(col.models.byName("Cloze")) + m = col.models.current() + mm = col.models # We replace the default Cloze template t = mm.newTemplate("ChainedCloze") @@ -253,9 +255,9 @@ def test_chained_mods(): t["afmt"] = "{{cloze:text:Text}}" mm.addTemplate(m, t) mm.save(m) - d.models.remTemplate(m, m["tmpls"][0]) + col.models.remTemplate(m, m["tmpls"][0]) - note = d.newNote() + note = col.newNote() q1 = 'phrase' a1 = "sentence" q2 = 'en chaine' @@ -266,7 +268,7 @@ def test_chained_mods(): q2, a2, ) - assert d.addNote(note) == 1 + assert col.addNote(note) == 1 assert ( "This [sentence] demonstrates [chained] clozes." in note.cards()[0].q() @@ -366,8 +368,8 @@ def test_req(): return assert len(model["tmpls"]) == len(model["req"]) - d = getEmptyCol() - mm = d.models + col = getEmptyCol() + mm = col.models basic = mm.byName("Basic") assert "req" in basic reqSize(basic) diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index ed5821baf..8d8b7a32f 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -16,41 +16,41 @@ def getEmptyCol(): def test_clock(): - d = getEmptyCol() - if (d.sched.dayCutoff - intTime()) < 10 * 60: + col = getEmptyCol() + if (col.sched.dayCutoff - intTime()) < 10 * 60: raise Exception("Unit tests will fail around the day rollover.") -def checkRevIvl(d, c, targetIvl): - min, max = d.sched._fuzzIvlRange(targetIvl) +def checkRevIvl(col, c, targetIvl): + min, max = col.sched._fuzzIvlRange(targetIvl) return min <= c.ivl <= max def test_basics(): - d = getEmptyCol() - d.reset() - assert not d.sched.getCard() + col = getEmptyCol() + col.reset() + assert not col.sched.getCard() def test_new(): - d = getEmptyCol() - d.reset() - assert d.sched.newCount == 0 + col = getEmptyCol() + col.reset() + assert col.sched.newCount == 0 # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) - d.reset() - assert d.sched.newCount == 1 + col.addNote(note) + col.reset() + assert col.sched.newCount == 1 # fetch it - c = d.sched.getCard() + c = col.sched.getCard() assert c assert c.queue == QUEUE_TYPE_NEW assert c.type == CARD_TYPE_NEW # if we answer it, it should become a learn card t = intTime() - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_LRN assert c.due >= t @@ -58,94 +58,94 @@ def test_new(): # disabled for now, as the learn fudging makes this randomly fail # # the default order should ensure siblings are not seen together, and # # should show all cards - # m = d.models.current(); mm = d.models + # m = col.models.current(); mm = col.models # t = mm.newTemplate("Reverse") # t['qfmt'] = "{{Back}}" # t['afmt'] = "{{Front}}" # mm.addTemplate(m, t) # mm.save(m) - # note = d.newNote() + # note = col.newNote() # note['Front'] = u"2"; note['Back'] = u"2" - # d.addNote(note) - # note = d.newNote() + # col.addNote(note) + # note = col.newNote() # note['Front'] = u"3"; note['Back'] = u"3" - # d.addNote(note) - # d.reset() + # col.addNote(note) + # col.reset() # qs = ("2", "3", "2", "3") # for n in range(4): - # c = d.sched.getCard() + # c = col.sched.getCard() # assert qs[n] in c.q() - # d.sched.answerCard(c, 2) + # col.sched.answerCard(c, 2) def test_newLimits(): - d = getEmptyCol() + col = getEmptyCol() # add some notes - g2 = d.decks.id("Default::foo") + g2 = col.decks.id("Default::foo") for i in range(30): - note = d.newNote() + note = col.newNote() note["Front"] = str(i) if i > 4: note.model()["did"] = g2 - d.addNote(note) + col.addNote(note) # give the child deck a different configuration - c2 = d.decks.add_config_returning_id("new conf") - d.decks.setConf(d.decks.get(g2), c2) - d.reset() + c2 = col.decks.add_config_returning_id("new conf") + col.decks.setConf(col.decks.get(g2), c2) + col.reset() # both confs have defaulted to a limit of 20 - assert d.sched.newCount == 20 + assert col.sched.newCount == 20 # first card we get comes from parent - c = d.sched.getCard() + c = col.sched.getCard() assert c.did == 1 # limit the parent to 10 cards, meaning we get 10 in total - conf1 = d.decks.confForDid(1) + conf1 = col.decks.confForDid(1) conf1["new"]["perDay"] = 10 - d.decks.save(conf1) - d.reset() - assert d.sched.newCount == 10 + col.decks.save(conf1) + col.reset() + assert col.sched.newCount == 10 # if we limit child to 4, we should get 9 - conf2 = d.decks.confForDid(g2) + conf2 = col.decks.confForDid(g2) conf2["new"]["perDay"] = 4 - d.decks.save(conf2) - d.reset() - assert d.sched.newCount == 9 + col.decks.save(conf2) + col.reset() + assert col.sched.newCount == 9 def test_newBoxes(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() - c = d.sched.getCard() - conf = d.sched._cardConf(c) + col.addNote(note) + col.reset() + c = col.sched.getCard() + conf = col.sched._cardConf(c) conf["new"]["delays"] = [1, 2, 3, 4, 5] - d.decks.save(conf) - d.sched.answerCard(c, 2) + col.decks.save(conf) + col.sched.answerCard(c, 2) # should handle gracefully conf["new"]["delays"] = [1] - d.decks.save(conf) - d.sched.answerCard(c, 2) + col.decks.save(conf) + col.sched.answerCard(c, 2) def test_learn(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - note = d.addNote(note) + note = col.addNote(note) # set as a learn card and rebuild queues - d.db.execute("update cards set queue=0, type=0") - d.reset() + col.db.execute("update cards set queue=0, type=0") + col.reset() # sched.getCard should return it, since it's due in the past - c = d.sched.getCard() + c = col.sched.getCard() assert c - conf = d.sched._cardConf(c) + conf = col.sched._cardConf(c) conf["new"]["delays"] = [0.5, 3, 10] - d.decks.save(conf) + col.decks.save(conf) # fail it - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) # it should have three reps left to graduation assert c.left % 1000 == 3 assert c.left // 1000 == 3 @@ -153,18 +153,18 @@ def test_learn(): t = round(c.due - time.time()) assert t >= 25 and t <= 40 # pass it once - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) # it should by due in 3 minutes assert round(c.due - time.time()) in (179, 180) assert c.left % 1000 == 2 assert c.left // 1000 == 2 # check log is accurate - log = d.db.first("select * from revlog order by id desc") + log = col.db.first("select * from revlog order by id desc") assert log[3] == 2 assert log[4] == -180 assert log[5] == -30 # pass again - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) # it should by due in 10 minutes assert round(c.due - time.time()) in (599, 600) assert c.left % 1000 == 1 @@ -172,26 +172,26 @@ def test_learn(): # the next pass should graduate the card assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_LRN - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) assert c.queue == QUEUE_TYPE_REV assert c.type == CARD_TYPE_REV # should be due tomorrow, with an interval of 1 - assert c.due == d.sched.today + 1 + assert c.due == col.sched.today + 1 assert c.ivl == 1 # or normal removal c.type = 0 c.queue = 1 - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) assert c.type == CARD_TYPE_REV assert c.queue == QUEUE_TYPE_REV - assert checkRevIvl(d, c, 4) + assert checkRevIvl(col, c, 4) # revlog should have been updated each time - assert d.db.scalar("select count() from revlog where type = 0") == 5 + assert col.db.scalar("select count() from revlog where type = 0") == 5 # now failed card handling c.type = CARD_TYPE_REV c.queue = 1 c.odue = 123 - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) assert c.due == 123 assert c.type == CARD_TYPE_REV assert c.queue == QUEUE_TYPE_REV @@ -200,114 +200,114 @@ def test_learn(): c.queue = 1 c.odue = 321 c.flush() - d.sched.removeLrn() + col.sched.removeLrn() c.load() assert c.queue == QUEUE_TYPE_REV assert c.due == 321 def test_learn_collapsed(): - d = getEmptyCol() + col = getEmptyCol() # add 2 notes - note = d.newNote() + note = col.newNote() note["Front"] = "1" - note = d.addNote(note) - note = d.newNote() + note = col.addNote(note) + note = col.newNote() note["Front"] = "2" - note = d.addNote(note) + note = col.addNote(note) # set as a learn card and rebuild queues - d.db.execute("update cards set queue=0, type=0") - d.reset() + col.db.execute("update cards set queue=0, type=0") + col.reset() # should get '1' first - c = d.sched.getCard() + c = col.sched.getCard() assert c.q().endswith("1") # pass it so it's due in 10 minutes - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) # get the other card - c = d.sched.getCard() + c = col.sched.getCard() assert c.q().endswith("2") # fail it so it's due in 1 minute - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) # we shouldn't get the same card again - c = d.sched.getCard() + c = col.sched.getCard() assert not c.q().endswith("2") def test_learn_day(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - note = d.addNote(note) - d.sched.reset() - c = d.sched.getCard() - conf = d.sched._cardConf(c) + note = col.addNote(note) + col.sched.reset() + c = col.sched.getCard() + conf = col.sched._cardConf(c) conf["new"]["delays"] = [1, 10, 1440, 2880] - d.decks.save(conf) + col.decks.save(conf) # pass it - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) # two reps to graduate, 1 more today assert c.left % 1000 == 3 assert c.left // 1000 == 1 - assert d.sched.counts() == (0, 1, 0) - c = d.sched.getCard() - ni = d.sched.nextIvl + assert col.sched.counts() == (0, 1, 0) + c = col.sched.getCard() + ni = col.sched.nextIvl assert ni(c, 2) == 86400 # answering it will place it in queue 3 - d.sched.answerCard(c, 2) - assert c.due == d.sched.today + 1 + col.sched.answerCard(c, 2) + assert c.due == col.sched.today + 1 assert c.queue == CARD_TYPE_RELEARNING - assert not d.sched.getCard() + assert not col.sched.getCard() # for testing, move it back a day c.due -= 1 c.flush() - d.reset() - assert d.sched.counts() == (0, 1, 0) - c = d.sched.getCard() + col.reset() + assert col.sched.counts() == (0, 1, 0) + c = col.sched.getCard() # nextIvl should work assert ni(c, 2) == 86400 * 2 # if we fail it, it should be back in the correct queue - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN - d.undo() - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 2) + col.undo() + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 2) # simulate the passing of another two days c.due -= 2 c.flush() - d.reset() + col.reset() # the last pass should graduate it into a review card assert ni(c, 2) == 86400 - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV # if the lapse step is tomorrow, failing it should handle the counts # correctly c.due = 0 c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 1) - conf = d.sched._cardConf(c) + col.reset() + assert col.sched.counts() == (0, 0, 1) + conf = col.sched._cardConf(c) conf["lapse"]["delays"] = [1440] - d.decks.save(conf) - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.decks.save(conf) + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.queue == CARD_TYPE_RELEARNING - assert d.sched.counts() == (0, 0, 0) + assert col.sched.counts() == (0, 0, 0) def test_reviews(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) # set the card up as a review card, due 8 days ago c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV - c.due = d.sched.today - 8 + c.due = col.sched.today - 8 c.factor = STARTING_FACTOR c.reps = 3 c.lapses = 1 @@ -319,14 +319,14 @@ def test_reviews(): # failing it should put it in the learn queue with the default options ################################################## # different delay to new - d.reset() - conf = d.sched._cardConf(c) + col.reset() + conf = col.sched._cardConf(c) conf["lapse"]["delays"] = [2, 20] - d.decks.save(conf) - d.sched.answerCard(c, 1) + col.decks.save(conf) + col.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN # it should be due tomorrow, with an interval of 1 - assert c.odue == d.sched.today + 1 + assert c.odue == col.sched.today + 1 assert c.ivl == 1 # but because it's in the learn queue, its current due time should be in # the future @@ -338,18 +338,18 @@ def test_reviews(): assert c.lapses == 2 assert c.reps == 4 # check ests. - ni = d.sched.nextIvl + ni = col.sched.nextIvl assert ni(c, 1) == 120 assert ni(c, 2) == 20 * 60 # try again with an ease of 2 instead ################################################## c = copy.copy(cardcopy) c.flush() - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) assert c.queue == QUEUE_TYPE_REV # the new interval should be (100 + 8/4) * 1.2 = 122 - assert checkRevIvl(d, c, 122) - assert c.due == d.sched.today + c.ivl + assert checkRevIvl(col, c, 122) + assert c.due == col.sched.today + c.ivl # factor should have been decremented assert c.factor == 2350 # check counters @@ -359,40 +359,40 @@ def test_reviews(): ################################################## c = copy.copy(cardcopy) c.flush() - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # the new interval should be (100 + 8/2) * 2.5 = 260 - assert checkRevIvl(d, c, 260) - assert c.due == d.sched.today + c.ivl + assert checkRevIvl(col, c, 260) + assert c.due == col.sched.today + c.ivl # factor should have been left alone assert c.factor == STARTING_FACTOR # ease 4 ################################################## c = copy.copy(cardcopy) c.flush() - d.sched.answerCard(c, 4) + col.sched.answerCard(c, 4) # the new interval should be (100 + 8) * 2.5 * 1.3 = 351 - assert checkRevIvl(d, c, 351) - assert c.due == d.sched.today + c.ivl + assert checkRevIvl(col, c, 351) + assert c.due == col.sched.today + c.ivl # factor should have been increased assert c.factor == 2650 def test_button_spacing(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # 1 day ivl review card due now c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV - c.due = d.sched.today + c.due = col.sched.today c.reps = 1 c.ivl = 1 c.startTimer() c.flush() - d.reset() - ni = d.sched.nextIvlStr + col.reset() + ni = col.sched.nextIvlStr wo = without_unicode_isolation assert wo(ni(c, 2)) == "2d" assert wo(ni(c, 3)) == "3d" @@ -402,11 +402,11 @@ def test_button_spacing(): def test_overdue_lapse(): # disabled in commit 3069729776990980f34c25be66410e947e9d51a2 return - d = getEmptyCol() # pylint: disable=unreachable + col = getEmptyCol() # pylint: disable=unreachable # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # simulate a review that was lapsed and is now due for its normal review c = note.cards()[0] c.type = CARD_TYPE_REV @@ -417,74 +417,74 @@ def test_overdue_lapse(): c.left = 2002 c.ivl = 0 c.flush() - d.sched._clearOverdue = False + col.sched._clearOverdue = False # checkpoint - d.save() - d.sched.reset() - assert d.sched.counts() == (0, 2, 0) - c = d.sched.getCard() - d.sched.answerCard(c, 3) + col.save() + col.sched.reset() + assert col.sched.counts() == (0, 2, 0) + c = col.sched.getCard() + col.sched.answerCard(c, 3) # it should be due tomorrow - assert c.due == d.sched.today + 1 + assert c.due == col.sched.today + 1 # revert to before - d.rollback() - d.sched._clearOverdue = True + col.rollback() + col.sched._clearOverdue = True # with the default settings, the overdue card should be removed from the # learning queue - d.sched.reset() - assert d.sched.counts() == (0, 0, 1) + col.sched.reset() + assert col.sched.counts() == (0, 0, 1) def test_finished(): - d = getEmptyCol() + col = getEmptyCol() # nothing due - assert "Congratulations" in d.sched.finishedMsg() - assert "limit" not in d.sched.finishedMsg() - note = d.newNote() + assert "Congratulations" in col.sched.finishedMsg() + assert "limit" not in col.sched.finishedMsg() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) # have a new card - assert "new cards available" in d.sched.finishedMsg() + assert "new cards available" in col.sched.finishedMsg() # turn it into a review - d.reset() + col.reset() c = note.cards()[0] c.startTimer() - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # nothing should be due tomorrow, as it's due in a week - assert "Congratulations" in d.sched.finishedMsg() - assert "limit" not in d.sched.finishedMsg() + assert "Congratulations" in col.sched.finishedMsg() + assert "limit" not in col.sched.finishedMsg() def test_nextIvl(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) - d.reset() - conf = d.decks.confForDid(1) + col.addNote(note) + col.reset() + conf = col.decks.confForDid(1) conf["new"]["delays"] = [0.5, 3, 10] conf["lapse"]["delays"] = [1, 5, 9] - d.decks.save(conf) - c = d.sched.getCard() + col.decks.save(conf) + c = col.sched.getCard() # new cards ################################################## - ni = d.sched.nextIvl + ni = col.sched.nextIvl assert ni(c, 1) == 30 assert ni(c, 2) == 180 assert ni(c, 3) == 4 * 86400 - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) # cards in learning ################################################## assert ni(c, 1) == 30 assert ni(c, 2) == 180 assert ni(c, 3) == 4 * 86400 - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) assert ni(c, 1) == 30 assert ni(c, 2) == 600 assert ni(c, 3) == 4 * 86400 - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) # normal graduation is tomorrow assert ni(c, 2) == 1 * 86400 assert ni(c, 3) == 4 * 86400 @@ -505,7 +505,7 @@ def test_nextIvl(): assert ni(c, 1) == 60 # or 1 day if relearn is false conf["lapse"]["delays"] = [] - d.decks.save(conf) + col.decks.save(conf) assert ni(c, 1) == 1 * 86400 # (* 100 1.2 86400)10368000.0 assert ni(c, 2) == 10368000 @@ -513,54 +513,54 @@ def test_nextIvl(): assert ni(c, 3) == 21600000 # (* 100 2.5 1.3 86400)28080000.0 assert ni(c, 4) == 28080000 - assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.8mo" + assert without_unicode_isolation(col.sched.nextIvlStr(c, 4)) == "10.8mo" def test_misc(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] # burying - d.sched.buryNote(c.nid) - d.reset() - assert not d.sched.getCard() - d.sched.unburyCards() - d.reset() - assert d.sched.getCard() + col.sched.buryNote(c.nid) + col.reset() + assert not col.sched.getCard() + col.sched.unburyCards() + col.reset() + assert col.sched.getCard() def test_suspend(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] # suspending - d.reset() - assert d.sched.getCard() - d.sched.suspendCards([c.id]) - d.reset() - assert not d.sched.getCard() + col.reset() + assert col.sched.getCard() + col.sched.suspendCards([c.id]) + col.reset() + assert not col.sched.getCard() # unsuspending - d.sched.unsuspendCards([c.id]) - d.reset() - assert d.sched.getCard() + col.sched.unsuspendCards([c.id]) + col.reset() + assert col.sched.getCard() # should cope with rev cards being relearnt c.due = 0 c.ivl = 100 c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.flush() - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.due >= time.time() assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_REV - d.sched.suspendCards([c.id]) - d.sched.unsuspendCards([c.id]) + col.sched.suspendCards([c.id]) + col.sched.unsuspendCards([c.id]) c.load() assert c.queue == QUEUE_TYPE_REV assert c.type == CARD_TYPE_REV @@ -568,56 +568,56 @@ def test_suspend(): # should cope with cards in cram decks c.due = 1 c.flush() - cram = d.decks.newDyn("tmp") - d.sched.rebuildDyn() + cram = col.decks.newDyn("tmp") + col.sched.rebuildDyn() c.load() assert c.due != 1 assert c.did != 1 - d.sched.suspendCards([c.id]) + col.sched.suspendCards([c.id]) c.load() assert c.due == 1 assert c.did == 1 def test_cram(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.ivl = 100 c.queue = CARD_TYPE_REV c.type = QUEUE_TYPE_REV # due in 25 days, so it's been waiting 75 days - c.due = d.sched.today + 25 + c.due = col.sched.today + 25 c.mod = 1 c.factor = STARTING_FACTOR c.startTimer() c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 0) + col.reset() + assert col.sched.counts() == (0, 0, 0) cardcopy = copy.copy(c) # create a dynamic deck and refresh it - did = d.decks.newDyn("Cram") - d.sched.rebuildDyn(did) - d.reset() + did = col.decks.newDyn("Cram") + col.sched.rebuildDyn(did) + col.reset() # should appear as new in the deck list - assert sorted(d.sched.deck_due_tree().children)[0].new_count == 1 + assert sorted(col.sched.deck_due_tree().children)[0].new_count == 1 # and should appear in the counts - assert d.sched.counts() == (1, 0, 0) + assert col.sched.counts() == (1, 0, 0) # grab it and check estimates - c = d.sched.getCard() - assert d.sched.answerButtons(c) == 2 - assert d.sched.nextIvl(c, 1) == 600 - assert d.sched.nextIvl(c, 2) == 138 * 60 * 60 * 24 - cram = d.decks.get(did) + c = col.sched.getCard() + assert col.sched.answerButtons(c) == 2 + assert col.sched.nextIvl(c, 1) == 600 + assert col.sched.nextIvl(c, 2) == 138 * 60 * 60 * 24 + cram = col.decks.get(did) cram["delays"] = [1, 10] - d.decks.save(cram) - assert d.sched.answerButtons(c) == 3 - assert d.sched.nextIvl(c, 1) == 60 - assert d.sched.nextIvl(c, 2) == 600 - assert d.sched.nextIvl(c, 3) == 138 * 60 * 60 * 24 - d.sched.answerCard(c, 2) + col.decks.save(cram) + assert col.sched.answerButtons(c) == 3 + assert col.sched.nextIvl(c, 1) == 60 + assert col.sched.nextIvl(c, 2) == 600 + assert col.sched.nextIvl(c, 3) == 138 * 60 * 60 * 24 + col.sched.answerCard(c, 2) # elapsed time was 75 days # factor = 2.5+1.2/2 = 1.85 # int(75*1.85) = 138 @@ -625,88 +625,88 @@ def test_cram(): assert c.odue == 138 assert c.queue == QUEUE_TYPE_LRN # should be logged as a cram rep - assert d.db.scalar("select type from revlog order by id desc limit 1") == 3 + assert col.db.scalar("select type from revlog order by id desc limit 1") == 3 # check ivls again - assert d.sched.nextIvl(c, 1) == 60 - assert d.sched.nextIvl(c, 2) == 138 * 60 * 60 * 24 - assert d.sched.nextIvl(c, 3) == 138 * 60 * 60 * 24 + assert col.sched.nextIvl(c, 1) == 60 + assert col.sched.nextIvl(c, 2) == 138 * 60 * 60 * 24 + assert col.sched.nextIvl(c, 3) == 138 * 60 * 60 * 24 # when it graduates, due is updated - c = d.sched.getCard() - d.sched.answerCard(c, 2) + c = col.sched.getCard() + col.sched.answerCard(c, 2) assert c.ivl == 138 assert c.due == 138 assert c.queue == QUEUE_TYPE_REV # and it will have moved back to the previous deck assert c.did == 1 # cram the deck again - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() # check ivls again - passing should be idempotent - assert d.sched.nextIvl(c, 1) == 60 - assert d.sched.nextIvl(c, 2) == 600 - assert d.sched.nextIvl(c, 3) == 138 * 60 * 60 * 24 - d.sched.answerCard(c, 2) + assert col.sched.nextIvl(c, 1) == 60 + assert col.sched.nextIvl(c, 2) == 600 + assert col.sched.nextIvl(c, 3) == 138 * 60 * 60 * 24 + col.sched.answerCard(c, 2) assert c.ivl == 138 assert c.odue == 138 # fail - d.sched.answerCard(c, 1) - assert d.sched.nextIvl(c, 1) == 60 - assert d.sched.nextIvl(c, 2) == 600 - assert d.sched.nextIvl(c, 3) == 86400 + col.sched.answerCard(c, 1) + assert col.sched.nextIvl(c, 1) == 60 + assert col.sched.nextIvl(c, 2) == 600 + assert col.sched.nextIvl(c, 3) == 86400 # delete the deck, returning the card mid-study - d.decks.rem(d.decks.selected()) - assert len(d.sched.deck_due_tree().children) == 1 + col.decks.rem(col.decks.selected()) + assert len(col.sched.deck_due_tree().children) == 1 c.load() assert c.ivl == 1 - assert c.due == d.sched.today + 1 + assert c.due == col.sched.today + 1 # make it due - d.reset() - assert d.sched.counts() == (0, 0, 0) + col.reset() + assert col.sched.counts() == (0, 0, 0) c.due = -5 c.ivl = 100 c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 1) + col.reset() + assert col.sched.counts() == (0, 0, 1) # cram again - did = d.decks.newDyn("Cram") - d.sched.rebuildDyn(did) - d.reset() - assert d.sched.counts() == (0, 0, 1) + did = col.decks.newDyn("Cram") + col.sched.rebuildDyn(did) + col.reset() + assert col.sched.counts() == (0, 0, 1) c.load() - assert d.sched.answerButtons(c) == 4 + assert col.sched.answerButtons(c) == 4 # add a sibling so we can test minSpace, etc c.col = None c2 = copy.deepcopy(c) - c2.col = c.col = d + c2.col = c.col = col c2.id = 0 c2.ord = 1 c2.due = 325 c2.col = c.col c2.flush() # should be able to answer it - c = d.sched.getCard() - d.sched.answerCard(c, 4) + c = col.sched.getCard() + col.sched.answerCard(c, 4) # it should have been moved back to the original deck assert c.did == 1 def test_cram_rem(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) oldDue = note.cards()[0].due - did = d.decks.newDyn("Cram") - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 2) + did = col.decks.newDyn("Cram") + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 2) # answering the card will put it in the learning queue assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN assert c.due != oldDue # if we terminate cramming prematurely it should be set back to new - d.sched.emptyDyn(did) + col.sched.emptyDyn(did) c.load() assert c.type == CARD_TYPE_NEW and c.queue == QUEUE_TYPE_NEW assert c.due == oldDue @@ -714,75 +714,75 @@ def test_cram_rem(): def test_cram_resched(): # add card - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # cram deck - did = d.decks.newDyn("Cram") - cram = d.decks.get(did) + did = col.decks.newDyn("Cram") + cram = col.decks.get(did) cram["resched"] = False - d.decks.save(cram) - d.sched.rebuildDyn(did) - d.reset() + col.decks.save(cram) + col.sched.rebuildDyn(did) + col.reset() # graduate should return it to new - c = d.sched.getCard() - ni = d.sched.nextIvl + c = col.sched.getCard() + ni = col.sched.nextIvl assert ni(c, 1) == 60 assert ni(c, 2) == 600 assert ni(c, 3) == 0 - assert d.sched.nextIvlStr(c, 3) == "(end)" - d.sched.answerCard(c, 3) + assert col.sched.nextIvlStr(c, 3) == "(end)" + col.sched.answerCard(c, 3) assert c.type == CARD_TYPE_NEW and c.queue == QUEUE_TYPE_NEW # undue reviews should also be unaffected c.ivl = 100 c.queue = CARD_TYPE_REV c.type = QUEUE_TYPE_REV - c.due = d.sched.today + 25 + c.due = col.sched.today + 25 c.factor = STARTING_FACTOR c.flush() cardcopy = copy.copy(c) - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() assert ni(c, 1) == 600 assert ni(c, 2) == 0 assert ni(c, 3) == 0 - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) assert c.ivl == 100 - assert c.due == d.sched.today + 25 + assert c.due == col.sched.today + 25 # check failure too c = cardcopy c.flush() - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) - d.sched.emptyDyn(did) + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) + col.sched.emptyDyn(did) c.load() assert c.ivl == 100 - assert c.due == d.sched.today + 25 + assert c.due == col.sched.today + 25 # fail+grad early c = cardcopy c.flush() - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) - d.sched.answerCard(c, 3) - d.sched.emptyDyn(did) + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) + col.sched.answerCard(c, 3) + col.sched.emptyDyn(did) c.load() assert c.ivl == 100 - assert c.due == d.sched.today + 25 + assert c.due == col.sched.today + 25 # due cards - pass c = cardcopy c.due = -25 c.flush() - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 3) - d.sched.emptyDyn(did) + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 3) + col.sched.emptyDyn(did) c.load() assert c.ivl == 100 assert c.due == -25 @@ -790,11 +790,11 @@ def test_cram_resched(): c = cardcopy c.due = -25 c.flush() - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) - d.sched.emptyDyn(did) + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) + col.sched.emptyDyn(did) c.load() assert c.ivl == 100 assert c.due == -25 @@ -802,29 +802,29 @@ def test_cram_resched(): c = cardcopy c.due = -25 c.flush() - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) - d.sched.answerCard(c, 3) + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) + col.sched.answerCard(c, 3) c.load() assert c.ivl == 100 assert c.due == -25 # lapsed card pulled into cram - # d.sched._cardConf(c)['lapse']['mult']=0.5 - # d.sched.answerCard(c, 1) - # d.sched.rebuildDyn(did) - # d.reset() - # c = d.sched.getCard() - # d.sched.answerCard(c, 2) + # col.sched._cardConf(c)['lapse']['mult']=0.5 + # col.sched.answerCard(c, 1) + # col.sched.rebuildDyn(did) + # col.reset() + # c = col.sched.getCard() + # col.sched.answerCard(c, 2) # print c.__dict__ def test_ordcycle(): - d = getEmptyCol() + col = getEmptyCol() # add two more templates and set second active - m = d.models.current() - mm = d.models + m = col.models.current() + mm = col.models t = mm.newTemplate("Reverse") t["qfmt"] = "{{Back}}" t["afmt"] = "{{Front}}" @@ -835,117 +835,117 @@ def test_ordcycle(): mm.addTemplate(m, t) mm.save(m) # create a new note; it should have 3 cards - note = d.newNote() + note = col.newNote() note["Front"] = "1" note["Back"] = "1" - d.addNote(note) - assert d.cardCount() == 3 - d.reset() + col.addNote(note) + assert col.cardCount() == 3 + col.reset() # ordinals should arrive in order - assert d.sched.getCard().ord == 0 - assert d.sched.getCard().ord == 1 - assert d.sched.getCard().ord == 2 + assert col.sched.getCard().ord == 0 + assert col.sched.getCard().ord == 1 + assert col.sched.getCard().ord == 2 def test_counts_idx(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) - d.reset() - assert d.sched.counts() == (1, 0, 0) - c = d.sched.getCard() + col.addNote(note) + col.reset() + assert col.sched.counts() == (1, 0, 0) + c = col.sched.getCard() # counter's been decremented but idx indicates 1 - assert d.sched.counts() == (0, 0, 0) - assert d.sched.countIdx(c) == 0 + assert col.sched.counts() == (0, 0, 0) + assert col.sched.countIdx(c) == 0 # answer to move to learn queue - d.sched.answerCard(c, 1) - assert d.sched.counts() == (0, 2, 0) + col.sched.answerCard(c, 1) + assert col.sched.counts() == (0, 2, 0) # fetching again will decrement the count - c = d.sched.getCard() - assert d.sched.counts() == (0, 0, 0) - assert d.sched.countIdx(c) == 1 + c = col.sched.getCard() + assert col.sched.counts() == (0, 0, 0) + assert col.sched.countIdx(c) == 1 # answering should add it back again - d.sched.answerCard(c, 1) - assert d.sched.counts() == (0, 2, 0) + col.sched.answerCard(c, 1) + assert col.sched.counts() == (0, 2, 0) def test_repCounts(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() + col.addNote(note) + col.reset() # lrnReps should be accurate on pass/fail - assert d.sched.counts() == (1, 0, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 2, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 2, 0) - d.sched.answerCard(d.sched.getCard(), 2) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 2, 0) - d.sched.answerCard(d.sched.getCard(), 2) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 2) - assert d.sched.counts() == (0, 0, 0) - note = d.newNote() + assert col.sched.counts() == (1, 0, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 2, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 2, 0) + col.sched.answerCard(col.sched.getCard(), 2) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 2, 0) + col.sched.answerCard(col.sched.getCard(), 2) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 2) + assert col.sched.counts() == (0, 0, 0) + note = col.newNote() note["Front"] = "two" - d.addNote(note) - d.reset() + col.addNote(note) + col.reset() # initial pass should be correct too - d.sched.answerCard(d.sched.getCard(), 2) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 2, 0) - d.sched.answerCard(d.sched.getCard(), 3) - assert d.sched.counts() == (0, 0, 0) + col.sched.answerCard(col.sched.getCard(), 2) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 2, 0) + col.sched.answerCard(col.sched.getCard(), 3) + assert col.sched.counts() == (0, 0, 0) # immediate graduate should work - note = d.newNote() + note = col.newNote() note["Front"] = "three" - d.addNote(note) - d.reset() - d.sched.answerCard(d.sched.getCard(), 3) - assert d.sched.counts() == (0, 0, 0) + col.addNote(note) + col.reset() + col.sched.answerCard(col.sched.getCard(), 3) + assert col.sched.counts() == (0, 0, 0) # and failing a review should too - note = d.newNote() + note = col.newNote() note["Front"] = "three" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV - c.due = d.sched.today + c.due = col.sched.today c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 1) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 1, 0) + col.reset() + assert col.sched.counts() == (0, 0, 1) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 1, 0) def test_timing(): - d = getEmptyCol() + col = getEmptyCol() # add a few review cards, due today for i in range(5): - note = d.newNote() + note = col.newNote() note["Front"] = "num" + str(i) - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # fail the first one - d.reset() - c = d.sched.getCard() + col.reset() + c = col.sched.getCard() # set a a fail delay of 4 seconds - conf = d.sched._cardConf(c) + conf = col.sched._cardConf(c) conf["lapse"]["delays"][0] = 1 / 15.0 - d.decks.save(conf) - d.sched.answerCard(c, 1) + col.decks.save(conf) + col.sched.answerCard(c, 1) # the next card should be another review - c = d.sched.getCard() + c = col.sched.getCard() assert c.queue == QUEUE_TYPE_REV # but if we wait for a few seconds, the failed card should come back orig_time = time.time @@ -954,55 +954,55 @@ def test_timing(): return orig_time() + 5 time.time = adjusted_time - c = d.sched.getCard() + c = col.sched.getCard() assert c.queue == QUEUE_TYPE_LRN time.time = orig_time def test_collapse(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() + col.addNote(note) + col.reset() # test collapsing - c = d.sched.getCard() - d.sched.answerCard(c, 1) - c = d.sched.getCard() - d.sched.answerCard(c, 3) - assert not d.sched.getCard() + c = col.sched.getCard() + col.sched.answerCard(c, 1) + c = col.sched.getCard() + col.sched.answerCard(c, 3) + assert not col.sched.getCard() def test_deckDue(): - d = getEmptyCol() + col = getEmptyCol() # add a note with default deck - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # and one that's a child - note = d.newNote() + note = col.newNote() note["Front"] = "two" - default1 = note.model()["did"] = d.decks.id("Default::1") - d.addNote(note) + default1 = note.model()["did"] = col.decks.id("Default::1") + col.addNote(note) # make it a review card c = note.cards()[0] c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # add one more with a new deck - note = d.newNote() + note = col.newNote() note["Front"] = "two" - foobar = note.model()["did"] = d.decks.id("foo::bar") - d.addNote(note) + foobar = note.model()["did"] = col.decks.id("foo::bar") + col.addNote(note) # and one that's a sibling - note = d.newNote() + note = col.newNote() note["Front"] = "three" - foobaz = note.model()["did"] = d.decks.id("foo::baz") - d.addNote(note) - d.reset() - assert len(d.decks.all_names_and_ids()) == 5 - tree = d.sched.deck_due_tree().children + foobaz = note.model()["did"] = col.decks.id("foo::baz") + col.addNote(note) + col.reset() + assert len(col.decks.all_names_and_ids()) == 5 + tree = col.sched.deck_due_tree().children assert tree[0].name == "Default" # sum of child and parent assert tree[0].deck_id == 1 @@ -1017,66 +1017,66 @@ def test_deckDue(): # code should not fail if a card has an invalid deck c.did = 12345 c.flush() - d.sched.deck_due_tree() + col.sched.deck_due_tree() def test_deckFlow(): - d = getEmptyCol() + col = getEmptyCol() # add a note with default deck - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # and one that's a child - note = d.newNote() + note = col.newNote() note["Front"] = "two" - default1 = note.model()["did"] = d.decks.id("Default::2") - d.addNote(note) + default1 = note.model()["did"] = col.decks.id("Default::2") + col.addNote(note) # and another that's higher up - note = d.newNote() + note = col.newNote() note["Front"] = "three" - default1 = note.model()["did"] = d.decks.id("Default::1") - d.addNote(note) + default1 = note.model()["did"] = col.decks.id("Default::1") + col.addNote(note) # should get top level one first, then ::1, then ::2 - d.reset() - assert d.sched.counts() == (3, 0, 0) + col.reset() + assert col.sched.counts() == (3, 0, 0) for i in "one", "three", "two": - c = d.sched.getCard() + c = col.sched.getCard() assert c.note()["Front"] == i - d.sched.answerCard(c, 2) + col.sched.answerCard(c, 2) def test_reorder(): - d = getEmptyCol() + col = getEmptyCol() # add a note with default deck - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - note2 = d.newNote() + col.addNote(note) + note2 = col.newNote() note2["Front"] = "two" - d.addNote(note2) + col.addNote(note2) assert note2.cards()[0].due == 2 found = False # 50/50 chance of being reordered for i in range(20): - d.sched.randomizeCards(1) + col.sched.randomizeCards(1) if note.cards()[0].due != note.id: found = True break assert found - d.sched.orderCards(1) + col.sched.orderCards(1) assert note.cards()[0].due == 1 # shifting - f3 = d.newNote() + f3 = col.newNote() f3["Front"] = "three" - d.addNote(f3) - f4 = d.newNote() + col.addNote(f3) + f4 = col.newNote() f4["Front"] = "four" - d.addNote(f4) + col.addNote(f4) assert note.cards()[0].due == 1 assert note2.cards()[0].due == 2 assert f3.cards()[0].due == 3 assert f4.cards()[0].due == 4 - d.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True) + col.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True) assert note.cards()[0].due == 3 assert note2.cards()[0].due == 4 assert f3.cards()[0].due == 1 @@ -1084,46 +1084,46 @@ def test_reorder(): def test_forget(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.queue = QUEUE_TYPE_REV c.type = CARD_TYPE_REV c.ivl = 100 c.due = 0 c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 1) - d.sched.forgetCards([c.id]) - d.reset() - assert d.sched.counts() == (1, 0, 0) + col.reset() + assert col.sched.counts() == (0, 0, 1) + col.sched.forgetCards([c.id]) + col.reset() + assert col.sched.counts() == (1, 0, 0) def test_resched(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] - d.sched.reschedCards([c.id], 0, 0) + col.sched.reschedCards([c.id], 0, 0) c.load() - assert c.due == d.sched.today + assert c.due == col.sched.today assert c.ivl == 1 assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV - d.sched.reschedCards([c.id], 1, 1) + col.sched.reschedCards([c.id], 1, 1) c.load() - assert c.due == d.sched.today + 1 + assert c.due == col.sched.today + 1 assert c.ivl == +1 def test_norelearn(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV @@ -1134,33 +1134,33 @@ def test_norelearn(): c.ivl = 100 c.startTimer() c.flush() - d.reset() - d.sched.answerCard(c, 1) - d.sched._cardConf(c)["lapse"]["delays"] = [] - d.sched.answerCard(c, 1) + col.reset() + col.sched.answerCard(c, 1) + col.sched._cardConf(c)["lapse"]["delays"] = [] + col.sched.answerCard(c, 1) def test_failmult(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.ivl = 100 - c.due = d.sched.today - c.ivl + c.due = col.sched.today - c.ivl c.factor = STARTING_FACTOR c.reps = 3 c.lapses = 1 c.startTimer() c.flush() - conf = d.sched._cardConf(c) + conf = col.sched._cardConf(c) conf["lapse"]["mult"] = 0.5 - d.decks.save(conf) - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.decks.save(conf) + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.ivl == 50 - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.ivl == 25 diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index 5124166d9..30c654d17 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -17,41 +17,41 @@ def getEmptyCol(): def test_clock(): - d = getEmptyCol() - if (d.sched.dayCutoff - intTime()) < 10 * 60: + col = getEmptyCol() + if (col.sched.dayCutoff - intTime()) < 10 * 60: raise Exception("Unit tests will fail around the day rollover.") -def checkRevIvl(d, c, targetIvl): - min, max = d.sched._fuzzIvlRange(targetIvl) +def checkRevIvl(col, c, targetIvl): + min, max = col.sched._fuzzIvlRange(targetIvl) return min <= c.ivl <= max def test_basics(): - d = getEmptyCol() - d.reset() - assert not d.sched.getCard() + col = getEmptyCol() + col.reset() + assert not col.sched.getCard() def test_new(): - d = getEmptyCol() - d.reset() - assert d.sched.newCount == 0 + col = getEmptyCol() + col.reset() + assert col.sched.newCount == 0 # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) - d.reset() - assert d.sched.newCount == 1 + col.addNote(note) + col.reset() + assert col.sched.newCount == 1 # fetch it - c = d.sched.getCard() + c = col.sched.getCard() assert c assert c.queue == QUEUE_TYPE_NEW assert c.type == CARD_TYPE_NEW # if we answer it, it should become a learn card t = intTime() - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_LRN assert c.due >= t @@ -59,94 +59,94 @@ def test_new(): # disabled for now, as the learn fudging makes this randomly fail # # the default order should ensure siblings are not seen together, and # # should show all cards - # m = d.models.current(); mm = d.models + # m = col.models.current(); mm = col.models # t = mm.newTemplate("Reverse") # t['qfmt'] = "{{Back}}" # t['afmt'] = "{{Front}}" # mm.addTemplate(m, t) # mm.save(m) - # note = d.newNote() + # note = col.newNote() # note['Front'] = u"2"; note['Back'] = u"2" - # d.addNote(note) - # note = d.newNote() + # col.addNote(note) + # note = col.newNote() # note['Front'] = u"3"; note['Back'] = u"3" - # d.addNote(note) - # d.reset() + # col.addNote(note) + # col.reset() # qs = ("2", "3", "2", "3") # for n in range(4): - # c = d.sched.getCard() + # c = col.sched.getCard() # assert qs[n] in c.q() - # d.sched.answerCard(c, 2) + # col.sched.answerCard(c, 2) def test_newLimits(): - d = getEmptyCol() + col = getEmptyCol() # add some notes - g2 = d.decks.id("Default::foo") + g2 = col.decks.id("Default::foo") for i in range(30): - note = d.newNote() + note = col.newNote() note["Front"] = str(i) if i > 4: note.model()["did"] = g2 - d.addNote(note) + col.addNote(note) # give the child deck a different configuration - c2 = d.decks.add_config_returning_id("new conf") - d.decks.setConf(d.decks.get(g2), c2) - d.reset() + c2 = col.decks.add_config_returning_id("new conf") + col.decks.setConf(col.decks.get(g2), c2) + col.reset() # both confs have defaulted to a limit of 20 - assert d.sched.newCount == 20 + assert col.sched.newCount == 20 # first card we get comes from parent - c = d.sched.getCard() + c = col.sched.getCard() assert c.did == 1 # limit the parent to 10 cards, meaning we get 10 in total - conf1 = d.decks.confForDid(1) + conf1 = col.decks.confForDid(1) conf1["new"]["perDay"] = 10 - d.decks.save(conf1) - d.reset() - assert d.sched.newCount == 10 + col.decks.save(conf1) + col.reset() + assert col.sched.newCount == 10 # if we limit child to 4, we should get 9 - conf2 = d.decks.confForDid(g2) + conf2 = col.decks.confForDid(g2) conf2["new"]["perDay"] = 4 - d.decks.save(conf2) - d.reset() - assert d.sched.newCount == 9 + col.decks.save(conf2) + col.reset() + assert col.sched.newCount == 9 def test_newBoxes(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() - c = d.sched.getCard() - conf = d.sched._cardConf(c) + col.addNote(note) + col.reset() + c = col.sched.getCard() + conf = col.sched._cardConf(c) conf["new"]["delays"] = [1, 2, 3, 4, 5] - d.decks.save(conf) - d.sched.answerCard(c, 2) + col.decks.save(conf) + col.sched.answerCard(c, 2) # should handle gracefully conf["new"]["delays"] = [1] - d.decks.save(conf) - d.sched.answerCard(c, 2) + col.decks.save(conf) + col.sched.answerCard(c, 2) def test_learn(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - note = d.addNote(note) + note = col.addNote(note) # set as a learn card and rebuild queues - d.db.execute("update cards set queue=0, type=0") - d.reset() + col.db.execute("update cards set queue=0, type=0") + col.reset() # sched.getCard should return it, since it's due in the past - c = d.sched.getCard() + c = col.sched.getCard() assert c - conf = d.sched._cardConf(c) + conf = col.sched._cardConf(c) conf["new"]["delays"] = [0.5, 3, 10] - d.decks.save(conf) + col.decks.save(conf) # fail it - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) # it should have three reps left to graduation assert c.left % 1000 == 3 assert c.left // 1000 == 3 @@ -154,19 +154,19 @@ def test_learn(): t = round(c.due - time.time()) assert t >= 25 and t <= 40 # pass it once - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # it should by due in 3 minutes dueIn = c.due - time.time() assert 178 <= dueIn <= 180 * 1.25 assert c.left % 1000 == 2 assert c.left // 1000 == 2 # check log is accurate - log = d.db.first("select * from revlog order by id desc") + log = col.db.first("select * from revlog order by id desc") assert log[3] == 3 assert log[4] == -180 assert log[5] == -30 # pass again - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # it should by due in 10 minutes dueIn = c.due - time.time() assert 599 <= dueIn <= 600 * 1.25 @@ -175,175 +175,175 @@ def test_learn(): # the next pass should graduate the card assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_LRN - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) assert c.queue == QUEUE_TYPE_REV assert c.type == CARD_TYPE_REV # should be due tomorrow, with an interval of 1 - assert c.due == d.sched.today + 1 + assert c.due == col.sched.today + 1 assert c.ivl == 1 # or normal removal c.type = 0 c.queue = 1 - d.sched.answerCard(c, 4) + col.sched.answerCard(c, 4) assert c.type == CARD_TYPE_REV assert c.queue == QUEUE_TYPE_REV - assert checkRevIvl(d, c, 4) + assert checkRevIvl(col, c, 4) # revlog should have been updated each time - assert d.db.scalar("select count() from revlog where type = 0") == 5 + assert col.db.scalar("select count() from revlog where type = 0") == 5 def test_relearn(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.ivl = 100 - c.due = d.sched.today + c.due = col.sched.today c.queue = CARD_TYPE_REV c.type = QUEUE_TYPE_REV c.flush() # fail the card - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_RELEARNING assert c.ivl == 1 # immediately graduate it - d.sched.answerCard(c, 4) + col.sched.answerCard(c, 4) assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV assert c.ivl == 2 - assert c.due == d.sched.today + c.ivl + assert c.due == col.sched.today + c.ivl def test_relearn_no_steps(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.ivl = 100 - c.due = d.sched.today + c.due = col.sched.today c.queue = CARD_TYPE_REV c.type = QUEUE_TYPE_REV c.flush() - conf = d.decks.confForDid(1) + conf = col.decks.confForDid(1) conf["lapse"]["delays"] = [] - d.decks.save(conf) + col.decks.save(conf) # fail the card - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV def test_learn_collapsed(): - d = getEmptyCol() + col = getEmptyCol() # add 2 notes - note = d.newNote() + note = col.newNote() note["Front"] = "1" - note = d.addNote(note) - note = d.newNote() + note = col.addNote(note) + note = col.newNote() note["Front"] = "2" - note = d.addNote(note) + note = col.addNote(note) # set as a learn card and rebuild queues - d.db.execute("update cards set queue=0, type=0") - d.reset() + col.db.execute("update cards set queue=0, type=0") + col.reset() # should get '1' first - c = d.sched.getCard() + c = col.sched.getCard() assert c.q().endswith("1") # pass it so it's due in 10 minutes - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # get the other card - c = d.sched.getCard() + c = col.sched.getCard() assert c.q().endswith("2") # fail it so it's due in 1 minute - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) # we shouldn't get the same card again - c = d.sched.getCard() + c = col.sched.getCard() assert not c.q().endswith("2") def test_learn_day(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - note = d.addNote(note) - d.sched.reset() - c = d.sched.getCard() - conf = d.sched._cardConf(c) + note = col.addNote(note) + col.sched.reset() + c = col.sched.getCard() + conf = col.sched._cardConf(c) conf["new"]["delays"] = [1, 10, 1440, 2880] - d.decks.save(conf) + col.decks.save(conf) # pass it - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # two reps to graduate, 1 more today assert c.left % 1000 == 3 assert c.left // 1000 == 1 - assert d.sched.counts() == (0, 1, 0) - c = d.sched.getCard() - ni = d.sched.nextIvl + assert col.sched.counts() == (0, 1, 0) + c = col.sched.getCard() + ni = col.sched.nextIvl assert ni(c, 3) == 86400 # answering it will place it in queue 3 - d.sched.answerCard(c, 3) - assert c.due == d.sched.today + 1 + col.sched.answerCard(c, 3) + assert c.due == col.sched.today + 1 assert c.queue == QUEUE_TYPE_DAY_LEARN_RELEARN - assert not d.sched.getCard() + assert not col.sched.getCard() # for testing, move it back a day c.due -= 1 c.flush() - d.reset() - assert d.sched.counts() == (0, 1, 0) - c = d.sched.getCard() + col.reset() + assert col.sched.counts() == (0, 1, 0) + c = col.sched.getCard() # nextIvl should work assert ni(c, 3) == 86400 * 2 # if we fail it, it should be back in the correct queue - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN - d.undo() - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 3) + col.undo() + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 3) # simulate the passing of another two days c.due -= 2 c.flush() - d.reset() + col.reset() # the last pass should graduate it into a review card assert ni(c, 3) == 86400 - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV # if the lapse step is tomorrow, failing it should handle the counts # correctly c.due = 0 c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 1) - conf = d.sched._cardConf(c) + col.reset() + assert col.sched.counts() == (0, 0, 1) + conf = col.sched._cardConf(c) conf["lapse"]["delays"] = [1440] - d.decks.save(conf) - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.decks.save(conf) + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_DAY_LEARN_RELEARN - assert d.sched.counts() == (0, 0, 0) + assert col.sched.counts() == (0, 0, 0) def test_reviews(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) # set the card up as a review card, due 8 days ago c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV - c.due = d.sched.today - 8 + c.due = col.sched.today - 8 c.factor = STARTING_FACTOR c.reps = 3 c.lapses = 1 @@ -356,12 +356,12 @@ def test_reviews(): ################################################## c = copy.copy(cardcopy) c.flush() - d.reset() - d.sched.answerCard(c, 2) + col.reset() + col.sched.answerCard(c, 2) assert c.queue == QUEUE_TYPE_REV # the new interval should be (100) * 1.2 = 120 - assert checkRevIvl(d, c, 120) - assert c.due == d.sched.today + c.ivl + assert checkRevIvl(col, c, 120) + assert c.due == col.sched.today + c.ivl # factor should have been decremented assert c.factor == 2350 # check counters @@ -371,27 +371,27 @@ def test_reviews(): ################################################## c = copy.copy(cardcopy) c.flush() - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # the new interval should be (100 + 8/2) * 2.5 = 260 - assert checkRevIvl(d, c, 260) - assert c.due == d.sched.today + c.ivl + assert checkRevIvl(col, c, 260) + assert c.due == col.sched.today + c.ivl # factor should have been left alone assert c.factor == STARTING_FACTOR # ease 4 ################################################## c = copy.copy(cardcopy) c.flush() - d.sched.answerCard(c, 4) + col.sched.answerCard(c, 4) # the new interval should be (100 + 8) * 2.5 * 1.3 = 351 - assert checkRevIvl(d, c, 351) - assert c.due == d.sched.today + c.ivl + assert checkRevIvl(col, c, 351) + assert c.due == col.sched.today + c.ivl # factor should have been increased assert c.factor == 2650 # leech handling ################################################## - conf = d.decks.getConf(1) + conf = col.decks.getConf(1) conf["lapse"]["leechAction"] = LEECH_SUSPEND - d.decks.save(conf) + col.decks.save(conf) c = copy.copy(cardcopy) c.lapses = 7 c.flush() @@ -402,7 +402,7 @@ def test_reviews(): hooked.append(1) hooks.card_did_leech.append(onLeech) - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert hooked assert c.queue == QUEUE_TYPE_SUSPENDED c.load() @@ -410,31 +410,31 @@ def test_reviews(): def test_review_limits(): - d = getEmptyCol() + col = getEmptyCol() - parent = d.decks.get(d.decks.id("parent")) - child = d.decks.get(d.decks.id("parent::child")) + parent = col.decks.get(col.decks.id("parent")) + child = col.decks.get(col.decks.id("parent::child")) - pconf = d.decks.get_config(d.decks.add_config_returning_id("parentConf")) - cconf = d.decks.get_config(d.decks.add_config_returning_id("childConf")) + pconf = col.decks.get_config(col.decks.add_config_returning_id("parentConf")) + cconf = col.decks.get_config(col.decks.add_config_returning_id("childConf")) pconf["rev"]["perDay"] = 5 - d.decks.update_config(pconf) - d.decks.setConf(parent, pconf["id"]) + col.decks.update_config(pconf) + col.decks.setConf(parent, pconf["id"]) cconf["rev"]["perDay"] = 10 - d.decks.update_config(cconf) - d.decks.setConf(child, cconf["id"]) + col.decks.update_config(cconf) + col.decks.setConf(child, cconf["id"]) - m = d.models.current() + m = col.models.current() m["did"] = child["id"] - d.models.save(m, updateReqs=False) + col.models.save(m, updateReqs=False) # add some cards for i in range(20): - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) # make them reviews c = note.cards()[0] @@ -443,62 +443,62 @@ def test_review_limits(): c.due = 0 c.flush() - tree = d.sched.deck_due_tree().children + tree = col.sched.deck_due_tree().children # (('parent', 1514457677462, 5, 0, 0, (('child', 1514457677463, 5, 0, 0, ()),))) assert tree[0].review_count == 5 # parent assert tree[0].children[0].review_count == 5 # child # .counts() should match - d.decks.select(child["id"]) - d.sched.reset() - assert d.sched.counts() == (0, 0, 5) + col.decks.select(child["id"]) + col.sched.reset() + assert col.sched.counts() == (0, 0, 5) # answering a card in the child should decrement parent count - c = d.sched.getCard() - d.sched.answerCard(c, 3) - assert d.sched.counts() == (0, 0, 4) + c = col.sched.getCard() + col.sched.answerCard(c, 3) + assert col.sched.counts() == (0, 0, 4) - tree = d.sched.deck_due_tree().children + tree = col.sched.deck_due_tree().children assert tree[0].review_count == 4 # parent assert tree[0].children[0].review_count == 4 # child def test_button_spacing(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # 1 day ivl review card due now c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV - c.due = d.sched.today + c.due = col.sched.today c.reps = 1 c.ivl = 1 c.startTimer() c.flush() - d.reset() - ni = d.sched.nextIvlStr + col.reset() + ni = col.sched.nextIvlStr wo = without_unicode_isolation assert wo(ni(c, 2)) == "2d" assert wo(ni(c, 3)) == "3d" assert wo(ni(c, 4)) == "4d" # if hard factor is <= 1, then hard may not increase - conf = d.decks.confForDid(1) + conf = col.decks.confForDid(1) conf["rev"]["hardFactor"] = 1 - d.decks.save(conf) + col.decks.save(conf) assert wo(ni(c, 2)) == "1d" def test_overdue_lapse(): # disabled in commit 3069729776990980f34c25be66410e947e9d51a2 return - d = getEmptyCol() # pylint: disable=unreachable + col = getEmptyCol() # pylint: disable=unreachable # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # simulate a review that was lapsed and is now due for its normal review c = note.cards()[0] c.type = CARD_TYPE_REV @@ -509,77 +509,77 @@ def test_overdue_lapse(): c.left = 2002 c.ivl = 0 c.flush() - d.sched._clearOverdue = False + col.sched._clearOverdue = False # checkpoint - d.save() - d.sched.reset() - assert d.sched.counts() == (0, 2, 0) - c = d.sched.getCard() - d.sched.answerCard(c, 3) + col.save() + col.sched.reset() + assert col.sched.counts() == (0, 2, 0) + c = col.sched.getCard() + col.sched.answerCard(c, 3) # it should be due tomorrow - assert c.due == d.sched.today + 1 + assert c.due == col.sched.today + 1 # revert to before - d.rollback() - d.sched._clearOverdue = True + col.rollback() + col.sched._clearOverdue = True # with the default settings, the overdue card should be removed from the # learning queue - d.sched.reset() - assert d.sched.counts() == (0, 0, 1) + col.sched.reset() + assert col.sched.counts() == (0, 0, 1) def test_finished(): - d = getEmptyCol() + col = getEmptyCol() # nothing due - assert "Congratulations" in d.sched.finishedMsg() - assert "limit" not in d.sched.finishedMsg() - note = d.newNote() + assert "Congratulations" in col.sched.finishedMsg() + assert "limit" not in col.sched.finishedMsg() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) # have a new card - assert "new cards available" in d.sched.finishedMsg() + assert "new cards available" in col.sched.finishedMsg() # turn it into a review - d.reset() + col.reset() c = note.cards()[0] c.startTimer() - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # nothing should be due tomorrow, as it's due in a week - assert "Congratulations" in d.sched.finishedMsg() - assert "limit" not in d.sched.finishedMsg() + assert "Congratulations" in col.sched.finishedMsg() + assert "limit" not in col.sched.finishedMsg() def test_nextIvl(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) - d.reset() - conf = d.decks.confForDid(1) + col.addNote(note) + col.reset() + conf = col.decks.confForDid(1) conf["new"]["delays"] = [0.5, 3, 10] conf["lapse"]["delays"] = [1, 5, 9] - d.decks.save(conf) - c = d.sched.getCard() + col.decks.save(conf) + c = col.sched.getCard() # new cards ################################################## - ni = d.sched.nextIvl + ni = col.sched.nextIvl assert ni(c, 1) == 30 assert ni(c, 2) == (30 + 180) // 2 assert ni(c, 3) == 180 assert ni(c, 4) == 4 * 86400 - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) # cards in learning ################################################## assert ni(c, 1) == 30 assert ni(c, 2) == (30 + 180) // 2 assert ni(c, 3) == 180 assert ni(c, 4) == 4 * 86400 - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) assert ni(c, 1) == 30 assert ni(c, 2) == (180 + 600) // 2 assert ni(c, 3) == 600 assert ni(c, 4) == 4 * 86400 - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # normal graduation is tomorrow assert ni(c, 3) == 1 * 86400 assert ni(c, 4) == 4 * 86400 @@ -600,7 +600,7 @@ def test_nextIvl(): assert ni(c, 1) == 60 # or 1 day if relearn is false conf["lapse"]["delays"] = [] - d.decks.save(conf) + col.decks.save(conf) assert ni(c, 1) == 1 * 86400 # (* 100 1.2 86400)10368000.0 assert ni(c, 2) == 10368000 @@ -608,81 +608,83 @@ def test_nextIvl(): assert ni(c, 3) == 21600000 # (* 100 2.5 1.3 86400)28080000.0 assert ni(c, 4) == 28080000 - assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.8mo" + assert without_unicode_isolation(col.sched.nextIvlStr(c, 4)) == "10.8mo" def test_bury(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] - note = d.newNote() + note = col.newNote() note["Front"] = "two" - d.addNote(note) + col.addNote(note) c2 = note.cards()[0] # burying - d.sched.buryCards([c.id], manual=True) # pylint: disable=unexpected-keyword-arg + col.sched.buryCards([c.id], manual=True) # pylint: disable=unexpected-keyword-arg c.load() assert c.queue == QUEUE_TYPE_MANUALLY_BURIED - d.sched.buryCards([c2.id], manual=False) # pylint: disable=unexpected-keyword-arg + col.sched.buryCards([c2.id], manual=False) # pylint: disable=unexpected-keyword-arg c2.load() assert c2.queue == QUEUE_TYPE_SIBLING_BURIED - d.reset() - assert not d.sched.getCard() + col.reset() + assert not col.sched.getCard() - d.sched.unburyCardsForDeck(type="manual") # pylint: disable=unexpected-keyword-arg + col.sched.unburyCardsForDeck( # pylint: disable=unexpected-keyword-arg + type="manual" + ) c.load() assert c.queue == QUEUE_TYPE_NEW c2.load() assert c2.queue == QUEUE_TYPE_SIBLING_BURIED - d.sched.unburyCardsForDeck( # pylint: disable=unexpected-keyword-arg + col.sched.unburyCardsForDeck( # pylint: disable=unexpected-keyword-arg type="siblings" ) c2.load() assert c2.queue == QUEUE_TYPE_NEW - d.sched.buryCards([c.id, c2.id]) - d.sched.unburyCardsForDeck(type="all") # pylint: disable=unexpected-keyword-arg + col.sched.buryCards([c.id, c2.id]) + col.sched.unburyCardsForDeck(type="all") # pylint: disable=unexpected-keyword-arg - d.reset() + col.reset() - assert d.sched.counts() == (2, 0, 0) + assert col.sched.counts() == (2, 0, 0) def test_suspend(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] # suspending - d.reset() - assert d.sched.getCard() - d.sched.suspendCards([c.id]) - d.reset() - assert not d.sched.getCard() + col.reset() + assert col.sched.getCard() + col.sched.suspendCards([c.id]) + col.reset() + assert not col.sched.getCard() # unsuspending - d.sched.unsuspendCards([c.id]) - d.reset() - assert d.sched.getCard() + col.sched.unsuspendCards([c.id]) + col.reset() + assert col.sched.getCard() # should cope with rev cards being relearnt c.due = 0 c.ivl = 100 c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.flush() - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.due >= time.time() due = c.due assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_RELEARNING - d.sched.suspendCards([c.id]) - d.sched.unsuspendCards([c.id]) + col.sched.suspendCards([c.id]) + col.sched.unsuspendCards([c.id]) c.load() assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_RELEARNING @@ -690,12 +692,12 @@ def test_suspend(): # should cope with cards in cram decks c.due = 1 c.flush() - cram = d.decks.newDyn("tmp") - d.sched.rebuildDyn() + cram = col.decks.newDyn("tmp") + col.sched.rebuildDyn() c.load() assert c.due != 1 assert c.did != 1 - d.sched.suspendCards([c.id]) + col.sched.suspendCards([c.id]) c.load() assert c.due != 1 assert c.did != 1 @@ -703,86 +705,86 @@ def test_suspend(): def test_filt_reviewing_early_normal(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.ivl = 100 c.queue = CARD_TYPE_REV c.type = QUEUE_TYPE_REV # due in 25 days, so it's been waiting 75 days - c.due = d.sched.today + 25 + c.due = col.sched.today + 25 c.mod = 1 c.factor = STARTING_FACTOR c.startTimer() c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 0) + col.reset() + assert col.sched.counts() == (0, 0, 0) # create a dynamic deck and refresh it - did = d.decks.newDyn("Cram") - d.sched.rebuildDyn(did) - d.reset() + did = col.decks.newDyn("Cram") + col.sched.rebuildDyn(did) + col.reset() # should appear as normal in the deck list - assert sorted(d.sched.deck_due_tree().children)[0].review_count == 1 + assert sorted(col.sched.deck_due_tree().children)[0].review_count == 1 # and should appear in the counts - assert d.sched.counts() == (0, 0, 1) + assert col.sched.counts() == (0, 0, 1) # grab it and check estimates - c = d.sched.getCard() - assert d.sched.answerButtons(c) == 4 - assert d.sched.nextIvl(c, 1) == 600 - assert d.sched.nextIvl(c, 2) == int(75 * 1.2) * 86400 - assert d.sched.nextIvl(c, 3) == int(75 * 2.5) * 86400 - assert d.sched.nextIvl(c, 4) == int(75 * 2.5 * 1.15) * 86400 + c = col.sched.getCard() + assert col.sched.answerButtons(c) == 4 + assert col.sched.nextIvl(c, 1) == 600 + assert col.sched.nextIvl(c, 2) == int(75 * 1.2) * 86400 + assert col.sched.nextIvl(c, 3) == int(75 * 2.5) * 86400 + assert col.sched.nextIvl(c, 4) == int(75 * 2.5 * 1.15) * 86400 # answer 'good' - d.sched.answerCard(c, 3) - checkRevIvl(d, c, 90) - assert c.due == d.sched.today + c.ivl + col.sched.answerCard(c, 3) + checkRevIvl(col, c, 90) + assert c.due == col.sched.today + c.ivl assert not c.odue # should not be in learning assert c.queue == QUEUE_TYPE_REV # should be logged as a cram rep - assert d.db.scalar("select type from revlog order by id desc limit 1") == 3 + assert col.db.scalar("select type from revlog order by id desc limit 1") == 3 # due in 75 days, so it's been waiting 25 days c.ivl = 100 - c.due = d.sched.today + 75 + c.due = col.sched.today + 75 c.flush() - d.sched.rebuildDyn(did) - d.reset() - c = d.sched.getCard() + col.sched.rebuildDyn(did) + col.reset() + c = col.sched.getCard() - assert d.sched.nextIvl(c, 2) == 60 * 86400 - assert d.sched.nextIvl(c, 3) == 100 * 86400 - assert d.sched.nextIvl(c, 4) == 114 * 86400 + assert col.sched.nextIvl(c, 2) == 60 * 86400 + assert col.sched.nextIvl(c, 3) == 100 * 86400 + assert col.sched.nextIvl(c, 4) == 114 * 86400 def test_filt_keep_lrn_state(): - d = getEmptyCol() + col = getEmptyCol() - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # fail the card outside filtered deck - c = d.sched.getCard() - conf = d.sched._cardConf(c) + c = col.sched.getCard() + conf = col.sched._cardConf(c) conf["new"]["delays"] = [1, 10, 61] - d.decks.save(conf) + col.decks.save(conf) - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN assert c.left == 3003 - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN # create a dynamic deck and refresh it - did = d.decks.newDyn("Cram") - d.sched.rebuildDyn(did) - d.reset() + did = col.decks.newDyn("Cram") + col.sched.rebuildDyn(did) + col.reset() # card should still be in learning state c.load() @@ -790,12 +792,12 @@ def test_filt_keep_lrn_state(): assert c.left == 2002 # should be able to advance learning steps - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) # should be due at least an hour in the future assert c.due - intTime() > 60 * 60 # emptying the deck preserves learning state - d.sched.emptyDyn(did) + col.sched.emptyDyn(did) c.load() assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN assert c.left == 1001 @@ -804,48 +806,48 @@ def test_filt_keep_lrn_state(): def test_preview(): # add cards - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] orig = copy.copy(c) - note2 = d.newNote() + note2 = col.newNote() note2["Front"] = "two" - d.addNote(note2) + col.addNote(note2) # cram deck - did = d.decks.newDyn("Cram") - cram = d.decks.get(did) + did = col.decks.newDyn("Cram") + cram = col.decks.get(did) cram["resched"] = False - d.decks.save(cram) - d.sched.rebuildDyn(did) - d.reset() + col.decks.save(cram) + col.sched.rebuildDyn(did) + col.reset() # grab the first card - c = d.sched.getCard() - assert d.sched.answerButtons(c) == 2 - assert d.sched.nextIvl(c, 1) == 600 - assert d.sched.nextIvl(c, 2) == 0 + c = col.sched.getCard() + assert col.sched.answerButtons(c) == 2 + assert col.sched.nextIvl(c, 1) == 600 + assert col.sched.nextIvl(c, 2) == 0 # failing it will push its due time back due = c.due - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.due != due # the other card should come next - c2 = d.sched.getCard() + c2 = col.sched.getCard() assert c2.id != c.id # passing it will remove it - d.sched.answerCard(c2, 2) + col.sched.answerCard(c2, 2) assert c2.queue == QUEUE_TYPE_NEW assert c2.reps == 0 assert c2.type == CARD_TYPE_NEW # the other card should appear again - c = d.sched.getCard() + c = col.sched.getCard() assert c.id == orig.id # emptying the filtered deck should restore card - d.sched.emptyDyn(did) + col.sched.emptyDyn(did) c.load() assert c.queue == QUEUE_TYPE_NEW assert c.reps == 0 @@ -853,10 +855,10 @@ def test_preview(): def test_ordcycle(): - d = getEmptyCol() + col = getEmptyCol() # add two more templates and set second active - m = d.models.current() - mm = d.models + m = col.models.current() + mm = col.models t = mm.newTemplate("Reverse") t["qfmt"] = "{{Back}}" t["afmt"] = "{{Front}}" @@ -867,166 +869,166 @@ def test_ordcycle(): mm.addTemplate(m, t) mm.save(m) # create a new note; it should have 3 cards - note = d.newNote() + note = col.newNote() note["Front"] = "1" note["Back"] = "1" - d.addNote(note) - assert d.cardCount() == 3 - d.reset() + col.addNote(note) + assert col.cardCount() == 3 + col.reset() # ordinals should arrive in order - assert d.sched.getCard().ord == 0 - assert d.sched.getCard().ord == 1 - assert d.sched.getCard().ord == 2 + assert col.sched.getCard().ord == 0 + assert col.sched.getCard().ord == 1 + assert col.sched.getCard().ord == 2 def test_counts_idx(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) - d.reset() - assert d.sched.counts() == (1, 0, 0) - c = d.sched.getCard() + col.addNote(note) + col.reset() + assert col.sched.counts() == (1, 0, 0) + c = col.sched.getCard() # counter's been decremented but idx indicates 1 - assert d.sched.counts() == (0, 0, 0) - assert d.sched.countIdx(c) == 0 + assert col.sched.counts() == (0, 0, 0) + assert col.sched.countIdx(c) == 0 # answer to move to learn queue - d.sched.answerCard(c, 1) - assert d.sched.counts() == (0, 1, 0) + col.sched.answerCard(c, 1) + assert col.sched.counts() == (0, 1, 0) # fetching again will decrement the count - c = d.sched.getCard() - assert d.sched.counts() == (0, 0, 0) - assert d.sched.countIdx(c) == 1 + c = col.sched.getCard() + assert col.sched.counts() == (0, 0, 0) + assert col.sched.countIdx(c) == 1 # answering should add it back again - d.sched.answerCard(c, 1) - assert d.sched.counts() == (0, 1, 0) + col.sched.answerCard(c, 1) + assert col.sched.counts() == (0, 1, 0) def test_repCounts(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() + col.addNote(note) + col.reset() # lrnReps should be accurate on pass/fail - assert d.sched.counts() == (1, 0, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 3) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 3) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 3) - assert d.sched.counts() == (0, 0, 0) - note = d.newNote() + assert col.sched.counts() == (1, 0, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 3) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 3) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 3) + assert col.sched.counts() == (0, 0, 0) + note = col.newNote() note["Front"] = "two" - d.addNote(note) - d.reset() + col.addNote(note) + col.reset() # initial pass should be correct too - d.sched.answerCard(d.sched.getCard(), 3) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 1, 0) - d.sched.answerCard(d.sched.getCard(), 4) - assert d.sched.counts() == (0, 0, 0) + col.sched.answerCard(col.sched.getCard(), 3) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 1, 0) + col.sched.answerCard(col.sched.getCard(), 4) + assert col.sched.counts() == (0, 0, 0) # immediate graduate should work - note = d.newNote() + note = col.newNote() note["Front"] = "three" - d.addNote(note) - d.reset() - d.sched.answerCard(d.sched.getCard(), 4) - assert d.sched.counts() == (0, 0, 0) + col.addNote(note) + col.reset() + col.sched.answerCard(col.sched.getCard(), 4) + assert col.sched.counts() == (0, 0, 0) # and failing a review should too - note = d.newNote() + note = col.newNote() note["Front"] = "three" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV - c.due = d.sched.today + c.due = col.sched.today c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 1) - d.sched.answerCard(d.sched.getCard(), 1) - assert d.sched.counts() == (0, 1, 0) + col.reset() + assert col.sched.counts() == (0, 0, 1) + col.sched.answerCard(col.sched.getCard(), 1) + assert col.sched.counts() == (0, 1, 0) def test_timing(): - d = getEmptyCol() + col = getEmptyCol() # add a few review cards, due today for i in range(5): - note = d.newNote() + note = col.newNote() note["Front"] = "num" + str(i) - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # fail the first one - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 1) # the next card should be another review - c2 = d.sched.getCard() + c2 = col.sched.getCard() assert c2.queue == QUEUE_TYPE_REV # if the failed card becomes due, it should show first c.due = intTime() - 1 c.flush() - d.reset() - c = d.sched.getCard() + col.reset() + c = col.sched.getCard() assert c.queue == QUEUE_TYPE_LRN def test_collapse(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() + col.addNote(note) + col.reset() # test collapsing - c = d.sched.getCard() - d.sched.answerCard(c, 1) - c = d.sched.getCard() - d.sched.answerCard(c, 4) - assert not d.sched.getCard() + c = col.sched.getCard() + col.sched.answerCard(c, 1) + c = col.sched.getCard() + col.sched.answerCard(c, 4) + assert not col.sched.getCard() def test_deckDue(): - d = getEmptyCol() + col = getEmptyCol() # add a note with default deck - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # and one that's a child - note = d.newNote() + note = col.newNote() note["Front"] = "two" - default1 = note.model()["did"] = d.decks.id("Default::1") - d.addNote(note) + default1 = note.model()["did"] = col.decks.id("Default::1") + col.addNote(note) # make it a review card c = note.cards()[0] c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # add one more with a new deck - note = d.newNote() + note = col.newNote() note["Front"] = "two" - foobar = note.model()["did"] = d.decks.id("foo::bar") - d.addNote(note) + foobar = note.model()["did"] = col.decks.id("foo::bar") + col.addNote(note) # and one that's a sibling - note = d.newNote() + note = col.newNote() note["Front"] = "three" - foobaz = note.model()["did"] = d.decks.id("foo::baz") - d.addNote(note) - d.reset() - assert len(d.decks.all_names_and_ids()) == 5 - tree = d.sched.deck_due_tree().children + foobaz = note.model()["did"] = col.decks.id("foo::baz") + col.addNote(note) + col.reset() + assert len(col.decks.all_names_and_ids()) == 5 + tree = col.sched.deck_due_tree().children assert tree[0].name == "Default" # sum of child and parent assert tree[0].deck_id == 1 @@ -1041,76 +1043,76 @@ def test_deckDue(): # code should not fail if a card has an invalid deck c.did = 12345 c.flush() - d.sched.deck_due_tree() + col.sched.deck_due_tree() def test_deckTree(): - d = getEmptyCol() - d.decks.id("new::b::c") - d.decks.id("new2") + col = getEmptyCol() + col.decks.id("new::b::c") + col.decks.id("new2") # new should not appear twice in tree - names = [x.name for x in d.sched.deck_due_tree().children] + names = [x.name for x in col.sched.deck_due_tree().children] names.remove("new") assert "new" not in names def test_deckFlow(): - d = getEmptyCol() + col = getEmptyCol() # add a note with default deck - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) # and one that's a child - note = d.newNote() + note = col.newNote() note["Front"] = "two" - default1 = note.model()["did"] = d.decks.id("Default::2") - d.addNote(note) + default1 = note.model()["did"] = col.decks.id("Default::2") + col.addNote(note) # and another that's higher up - note = d.newNote() + note = col.newNote() note["Front"] = "three" - default1 = note.model()["did"] = d.decks.id("Default::1") - d.addNote(note) + default1 = note.model()["did"] = col.decks.id("Default::1") + col.addNote(note) # should get top level one first, then ::1, then ::2 - d.reset() - assert d.sched.counts() == (3, 0, 0) + col.reset() + assert col.sched.counts() == (3, 0, 0) for i in "one", "three", "two": - c = d.sched.getCard() + c = col.sched.getCard() assert c.note()["Front"] == i - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) def test_reorder(): - d = getEmptyCol() + col = getEmptyCol() # add a note with default deck - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) - note2 = d.newNote() + col.addNote(note) + note2 = col.newNote() note2["Front"] = "two" - d.addNote(note2) + col.addNote(note2) assert note2.cards()[0].due == 2 found = False # 50/50 chance of being reordered for i in range(20): - d.sched.randomizeCards(1) + col.sched.randomizeCards(1) if note.cards()[0].due != note.id: found = True break assert found - d.sched.orderCards(1) + col.sched.orderCards(1) assert note.cards()[0].due == 1 # shifting - f3 = d.newNote() + f3 = col.newNote() f3["Front"] = "three" - d.addNote(f3) - f4 = d.newNote() + col.addNote(f3) + f4 = col.newNote() f4["Front"] = "four" - d.addNote(f4) + col.addNote(f4) assert note.cards()[0].due == 1 assert note2.cards()[0].due == 2 assert f3.cards()[0].due == 3 assert f4.cards()[0].due == 4 - d.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True) + col.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True) assert note.cards()[0].due == 3 assert note2.cards()[0].due == 4 assert f3.cards()[0].due == 1 @@ -1118,46 +1120,46 @@ def test_reorder(): def test_forget(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.queue = QUEUE_TYPE_REV c.type = CARD_TYPE_REV c.ivl = 100 c.due = 0 c.flush() - d.reset() - assert d.sched.counts() == (0, 0, 1) - d.sched.forgetCards([c.id]) - d.reset() - assert d.sched.counts() == (1, 0, 0) + col.reset() + assert col.sched.counts() == (0, 0, 1) + col.sched.forgetCards([c.id]) + col.reset() + assert col.sched.counts() == (1, 0, 0) def test_resched(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] - d.sched.reschedCards([c.id], 0, 0) + col.sched.reschedCards([c.id], 0, 0) c.load() - assert c.due == d.sched.today + assert c.due == col.sched.today assert c.ivl == 1 assert c.queue == QUEUE_TYPE_REV and c.type == CARD_TYPE_REV - d.sched.reschedCards([c.id], 1, 1) + col.sched.reschedCards([c.id], 1, 1) c.load() - assert c.due == d.sched.today + 1 + assert c.due == col.sched.today + 1 assert c.ivl == +1 def test_norelearn(): - d = getEmptyCol() + col = getEmptyCol() # add a note - note = d.newNote() + note = col.newNote() note["Front"] = "one" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV @@ -1168,35 +1170,35 @@ def test_norelearn(): c.ivl = 100 c.startTimer() c.flush() - d.reset() - d.sched.answerCard(c, 1) - d.sched._cardConf(c)["lapse"]["delays"] = [] - d.sched.answerCard(c, 1) + col.reset() + col.sched.answerCard(c, 1) + col.sched._cardConf(c)["lapse"]["delays"] = [] + col.sched.answerCard(c, 1) def test_failmult(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.ivl = 100 - c.due = d.sched.today - c.ivl + c.due = col.sched.today - c.ivl c.factor = STARTING_FACTOR c.reps = 3 c.lapses = 1 c.startTimer() c.flush() - conf = d.sched._cardConf(c) + conf = col.sched._cardConf(c) conf["lapse"]["mult"] = 0.5 - d.decks.save(conf) - c = d.sched.getCard() - d.sched.answerCard(c, 1) + col.decks.save(conf) + c = col.sched.getCard() + col.sched.answerCard(c, 1) assert c.ivl == 50 - d.sched.answerCard(c, 1) + col.sched.answerCard(c, 1) assert c.ivl == 25 @@ -1261,13 +1263,13 @@ def test_moveVersions(): # cards with a due date earlier than the collection should retain # their due date when removed def test_negativeDueFilter(): - d = getEmptyCol() + col = getEmptyCol() # card due prior to collection date - note = d.newNote() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) c = note.cards()[0] c.due = -5 c.queue = QUEUE_TYPE_REV @@ -1275,10 +1277,10 @@ def test_negativeDueFilter(): c.flush() # into and out of filtered deck - did = d.decks.newDyn("Cram") - d.sched.rebuildDyn(did) - d.sched.emptyDyn(did) - d.reset() + did = col.decks.newDyn("Cram") + col.sched.rebuildDyn(did) + col.sched.emptyDyn(did) + col.reset() c.load() assert c.due == -5 @@ -1287,18 +1289,18 @@ def test_negativeDueFilter(): # hard on the first step should be the average of again and good, # and it should be logged properly def test_initial_repeat(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "one" note["Back"] = "two" - d.addNote(note) + col.addNote(note) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 2) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 2) # should be due in ~ 5.5 mins expected = time.time() + 5.5 * 60 assert expected - 10 < c.due < expected * 1.25 - ivl = d.db.scalar("select ivl from revlog") + ivl = col.db.scalar("select ivl from revlog") assert ivl == -5.5 * 60 diff --git a/pylib/tests/test_stats.py b/pylib/tests/test_stats.py index 56d1b27c6..101bd50ed 100644 --- a/pylib/tests/test_stats.py +++ b/pylib/tests/test_stats.py @@ -8,29 +8,29 @@ from tests.shared import getEmptyCol def test_stats(): - d = getEmptyCol() - note = d.newNote() + col = getEmptyCol() + note = col.newNote() note["Front"] = "foo" - d.addNote(note) + col.addNote(note) c = note.cards()[0] # card stats - assert d.cardStats(c) - d.reset() - c = d.sched.getCard() - d.sched.answerCard(c, 3) - d.sched.answerCard(c, 2) - assert d.cardStats(c) + assert col.cardStats(c) + col.reset() + c = col.sched.getCard() + col.sched.answerCard(c, 3) + col.sched.answerCard(c, 2) + assert col.cardStats(c) def test_graphs_empty(): - d = getEmptyCol() - assert d.stats().report() + col = getEmptyCol() + assert col.stats().report() def test_graphs(): dir = tempfile.gettempdir() - d = getEmptyCol() - g = d.stats() + col = getEmptyCol() + g = col.stats() rep = g.report() with open(os.path.join(dir, "test.html"), "w", encoding="UTF-8") as note: note.write(rep) diff --git a/pylib/tests/test_template.py b/pylib/tests/test_template.py index 6a7487ab6..bd3234d6f 100644 --- a/pylib/tests/test_template.py +++ b/pylib/tests/test_template.py @@ -2,14 +2,14 @@ from tests.shared import getEmptyCol def test_deferred_frontside(): - d = getEmptyCol() - m = d.models.current() + col = getEmptyCol() + m = col.models.current() m["tmpls"][0]["qfmt"] = "{{custom:Front}}" - d.models.save(m) + col.models.save(m) - note = d.newNote() + note = col.newNote() note["Front"] = "xxtest" note["Back"] = "" - d.addNote(note) + col.addNote(note) assert "xxtest" in note.cards()[0].a() diff --git a/pylib/tests/test_undo.py b/pylib/tests/test_undo.py index a21bdbf14..70b08ce0a 100644 --- a/pylib/tests/test_undo.py +++ b/pylib/tests/test_undo.py @@ -13,84 +13,84 @@ def getEmptyCol(): def test_op(): - d = getEmptyCol() + col = getEmptyCol() # should have no undo by default - assert not d.undoName() + assert not col.undoName() # let's adjust a study option - d.save("studyopts") - d.conf["abc"] = 5 + col.save("studyopts") + col.conf["abc"] = 5 # it should be listed as undoable - assert d.undoName() == "studyopts" + assert col.undoName() == "studyopts" # with about 5 minutes until it's clobbered - assert time.time() - d._lastSave < 1 + assert time.time() - col._lastSave < 1 # undoing should restore the old value - d.undo() - assert not d.undoName() - assert "abc" not in d.conf + col.undo() + assert not col.undoName() + assert "abc" not in col.conf # an (auto)save will clear the undo - d.save("foo") - assert d.undoName() == "foo" - d.save() - assert not d.undoName() + col.save("foo") + assert col.undoName() == "foo" + col.save() + assert not col.undoName() # and a review will, too - d.save("add") - note = d.newNote() + col.save("add") + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() - assert d.undoName() == "add" - c = d.sched.getCard() - d.sched.answerCard(c, 2) - assert d.undoName() == "Review" + col.addNote(note) + col.reset() + assert col.undoName() == "add" + c = col.sched.getCard() + col.sched.answerCard(c, 2) + assert col.undoName() == "Review" def test_review(): - d = getEmptyCol() - d.conf["counts"] = COUNT_REMAINING - note = d.newNote() + col = getEmptyCol() + col.conf["counts"] = COUNT_REMAINING + note = col.newNote() note["Front"] = "one" - d.addNote(note) - d.reset() - assert not d.undoName() + col.addNote(note) + col.reset() + assert not col.undoName() # answer - assert d.sched.counts() == (1, 0, 0) - c = d.sched.getCard() + assert col.sched.counts() == (1, 0, 0) + c = col.sched.getCard() assert c.queue == QUEUE_TYPE_NEW - d.sched.answerCard(c, 3) + col.sched.answerCard(c, 3) assert c.left == 1001 - assert d.sched.counts() == (0, 1, 0) + assert col.sched.counts() == (0, 1, 0) assert c.queue == QUEUE_TYPE_LRN # undo - assert d.undoName() - d.undo() - d.reset() - assert d.sched.counts() == (1, 0, 0) + assert col.undoName() + col.undo() + col.reset() + assert col.sched.counts() == (1, 0, 0) c.load() assert c.queue == QUEUE_TYPE_NEW assert c.left != 1001 - assert not d.undoName() + assert not col.undoName() # we should be able to undo multiple answers too - note = d.newNote() + note = col.newNote() note["Front"] = "two" - d.addNote(note) - d.reset() - assert d.sched.counts() == (2, 0, 0) - c = d.sched.getCard() - d.sched.answerCard(c, 3) - c = d.sched.getCard() - d.sched.answerCard(c, 3) - assert d.sched.counts() == (0, 2, 0) - d.undo() - d.reset() - assert d.sched.counts() == (1, 1, 0) - d.undo() - d.reset() - assert d.sched.counts() == (2, 0, 0) + col.addNote(note) + col.reset() + assert col.sched.counts() == (2, 0, 0) + c = col.sched.getCard() + col.sched.answerCard(c, 3) + c = col.sched.getCard() + col.sched.answerCard(c, 3) + assert col.sched.counts() == (0, 2, 0) + col.undo() + col.reset() + assert col.sched.counts() == (1, 1, 0) + col.undo() + col.reset() + assert col.sched.counts() == (2, 0, 0) # performing a normal op will clear the review queue - c = d.sched.getCard() - d.sched.answerCard(c, 3) - assert d.undoName() == "Review" - d.save("foo") - assert d.undoName() == "foo" - d.undo() - assert not d.undoName() + c = col.sched.getCard() + col.sched.answerCard(c, 3) + assert col.undoName() == "Review" + col.save("foo") + assert col.undoName() == "foo" + col.undo() + assert not col.undoName()