Merge pull request #693 from Arthur-Milchior/master

More variable renaming in tests
This commit is contained in:
Damien Elmes 2020-07-18 12:09:06 +10:00 committed by GitHub
commit f04ea6904d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 74 deletions

View file

@ -61,14 +61,14 @@ def test_export_anki():
conf = col.decks.confForDid(did) conf = col.decks.confForDid(did)
assert conf["id"] != 1 assert conf["id"] != 1
# connect to new deck # connect to new deck
d2 = aopen(newname) col2 = aopen(newname)
assert d2.cardCount() == 2 assert col2.cardCount() == 2
# as scheduling was reset, should also revert decks to default conf # as scheduling was reset, should also revert decks to default conf
did = d2.decks.id("test", create=False) did = col2.decks.id("test", create=False)
assert did assert did
conf2 = d2.decks.confForDid(did) conf2 = col2.decks.confForDid(did)
assert conf2["new"]["perDay"] == 20 assert conf2["new"]["perDay"] == 20
dobj = d2.decks.get(did) dobj = col2.decks.get(did)
# conf should be 1 # conf should be 1
assert dobj["conf"] == 1 assert dobj["conf"] == 1
# try again, limited to a deck # try again, limited to a deck
@ -78,8 +78,8 @@ def test_export_anki():
os.unlink(newname) os.unlink(newname)
e.did = 1 e.did = 1
e.exportInto(newname) e.exportInto(newname)
d2 = aopen(newname) col2 = aopen(newname)
assert d2.cardCount() == 1 assert col2.cardCount() == 1
def test_export_ankipkg(): def test_export_ankipkg():
@ -125,12 +125,12 @@ def test_export_anki_due():
os.unlink(newname) os.unlink(newname)
e.exportInto(newname) e.exportInto(newname)
# importing into a new deck, the due date should be equivalent # importing into a new deck, the due date should be equivalent
deck2 = getEmptyCol() col2 = getEmptyCol()
imp = Anki2Importer(deck2, newname) imp = Anki2Importer(col2, newname)
imp.run() imp.run()
c = deck2.getCard(c.id) c = col2.getCard(c.id)
deck2.sched.reset() col2.sched.reset()
assert c.due - deck2.sched.today == 1 assert c.due - col2.sched.today == 1
# def test_export_textcard(): # def test_export_textcard():

View file

@ -18,14 +18,14 @@ def test_findCards():
note["Back"] = "cat" note["Back"] = "cat"
note.tags.append("monkey animal_1 * %") note.tags.append("monkey animal_1 * %")
col.addNote(note) col.addNote(note)
f1id = note.id n1id = note.id
firstCardId = note.cards()[0].id firstCardId = note.cards()[0].id
note = col.newNote() note = col.newNote()
note["Front"] = "goats are fun" note["Front"] = "goats are fun"
note["Back"] = "sheep" note["Back"] = "sheep"
note.tags.append("sheep goat horse animal11") note.tags.append("sheep goat horse animal11")
col.addNote(note) col.addNote(note)
f2id = note.id n2id = note.id
note = col.newNote() note = col.newNote()
note["Front"] = "cat" note["Front"] = "cat"
note["Back"] = "sheep" note["Back"] = "sheep"
@ -91,7 +91,7 @@ def test_findCards():
# nids # nids
assert col.findCards("nid:54321") == [] assert col.findCards("nid:54321") == []
assert len(col.findCards(f"nid:{note.id}")) == 2 assert len(col.findCards(f"nid:{note.id}")) == 2
assert len(col.findCards(f"nid:{f1id},{f2id}")) == 2 assert len(col.findCards(f"nid:{n1id},{n2id}")) == 2
# templates # templates
assert len(col.findCards("card:foo")) == 0 assert len(col.findCards("card:foo")) == 0
assert len(col.findCards('"card:card 1"')) == 4 assert len(col.findCards('"card:card 1"')) == 4
@ -273,14 +273,14 @@ def test_findDupes():
note2["Front"] = "baz" note2["Front"] = "baz"
note2["Back"] = "bar" note2["Back"] = "bar"
col.addNote(note2) col.addNote(note2)
f3 = col.newNote() note3 = col.newNote()
f3["Front"] = "quux" note3["Front"] = "quux"
f3["Back"] = "bar" note3["Back"] = "bar"
col.addNote(f3) col.addNote(note3)
f4 = col.newNote() note4 = col.newNote()
f4["Front"] = "quuux" note4["Front"] = "quuux"
f4["Back"] = "nope" note4["Back"] = "nope"
col.addNote(f4) col.addNote(note4)
r = col.findDupes("Back") r = col.findDupes("Back")
assert r[0][0] == "bar" assert r[0][0] == "bar"
assert len(r[0][1]) == 3 assert len(r[0][1]) == 3

View file

@ -30,24 +30,24 @@ def clear_tempfile(tf):
def test_anki2_mediadupes(): def test_anki2_mediadupes():
tmp = getEmptyCol() col = getEmptyCol()
# add a note that references a sound # add a note that references a sound
n = tmp.newNote() n = col.newNote()
n["Front"] = "[sound:foo.mp3]" n["Front"] = "[sound:foo.mp3]"
mid = n.model()["id"] mid = n.model()["id"]
tmp.addNote(n) col.addNote(n)
# add that sound to media folder # add that sound to media folder
with open(os.path.join(tmp.media.dir(), "foo.mp3"), "w") as note: with open(os.path.join(col.media.dir(), "foo.mp3"), "w") as note:
note.write("foo") note.write("foo")
tmp.close() col.close()
# it should be imported correctly into an empty deck # it should be imported correctly into an empty deck
empty = getEmptyCol() empty = getEmptyCol()
imp = Anki2Importer(empty, tmp.path) imp = Anki2Importer(empty, col.path)
imp.run() imp.run()
assert os.listdir(empty.media.dir()) == ["foo.mp3"] assert os.listdir(empty.media.dir()) == ["foo.mp3"]
# and importing again will not duplicate, as the file content matches # and importing again will not duplicate, as the file content matches
empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards")) empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards"))
imp = Anki2Importer(empty, tmp.path) imp = Anki2Importer(empty, col.path)
imp.run() imp.run()
assert os.listdir(empty.media.dir()) == ["foo.mp3"] assert os.listdir(empty.media.dir()) == ["foo.mp3"]
n = empty.getNote(empty.db.scalar("select id from notes")) n = empty.getNote(empty.db.scalar("select id from notes"))
@ -57,7 +57,7 @@ def test_anki2_mediadupes():
empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards")) empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards"))
with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as note: with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as note:
note.write("bar") note.write("bar")
imp = Anki2Importer(empty, tmp.path) imp = Anki2Importer(empty, col.path)
imp.run() imp.run()
assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid] assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid]
n = empty.getNote(empty.db.scalar("select id from notes")) n = empty.getNote(empty.db.scalar("select id from notes"))
@ -67,7 +67,7 @@ def test_anki2_mediadupes():
empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards")) empty.remove_cards_and_orphaned_notes(empty.db.list("select id from cards"))
with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as note: with open(os.path.join(empty.media.dir(), "foo.mp3"), "w") as note:
note.write("bar") note.write("bar")
imp = Anki2Importer(empty, tmp.path) imp = Anki2Importer(empty, col.path)
imp.run() imp.run()
assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid] assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid]
assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid] assert sorted(os.listdir(empty.media.dir())) == ["foo.mp3", "foo_%s.mp3" % mid]
@ -76,24 +76,24 @@ def test_anki2_mediadupes():
def test_apkg(): def test_apkg():
tmp = getEmptyCol() col = getEmptyCol()
apkg = str(os.path.join(testDir, "support/media.apkg")) apkg = str(os.path.join(testDir, "support/media.apkg"))
imp = AnkiPackageImporter(tmp, apkg) imp = AnkiPackageImporter(col, apkg)
assert os.listdir(tmp.media.dir()) == [] assert os.listdir(col.media.dir()) == []
imp.run() imp.run()
assert os.listdir(tmp.media.dir()) == ["foo.wav"] assert os.listdir(col.media.dir()) == ["foo.wav"]
# importing again should be idempotent in terms of media # importing again should be idempotent in terms of media
tmp.remove_cards_and_orphaned_notes(tmp.db.list("select id from cards")) col.remove_cards_and_orphaned_notes(col.db.list("select id from cards"))
imp = AnkiPackageImporter(tmp, apkg) imp = AnkiPackageImporter(col, apkg)
imp.run() imp.run()
assert os.listdir(tmp.media.dir()) == ["foo.wav"] assert os.listdir(col.media.dir()) == ["foo.wav"]
# but if the local file has different data, it will rename # but if the local file has different data, it will rename
tmp.remove_cards_and_orphaned_notes(tmp.db.list("select id from cards")) col.remove_cards_and_orphaned_notes(col.db.list("select id from cards"))
with open(os.path.join(tmp.media.dir(), "foo.wav"), "w") as note: with open(os.path.join(col.media.dir(), "foo.wav"), "w") as note:
note.write("xyz") note.write("xyz")
imp = AnkiPackageImporter(tmp, apkg) imp = AnkiPackageImporter(col, apkg)
imp.run() imp.run()
assert len(os.listdir(tmp.media.dir())) == 2 assert len(os.listdir(col.media.dir())) == 2
def test_anki2_diffmodel_templates(): def test_anki2_diffmodel_templates():
@ -101,13 +101,13 @@ def test_anki2_diffmodel_templates():
# changed, not the number of cards/fields # changed, not the number of cards/fields
dst = getEmptyCol() dst = getEmptyCol()
# import the first version of the model # import the first version of the model
tmp = getUpgradeDeckPath("diffmodeltemplates-1.apkg") col = getUpgradeDeckPath("diffmodeltemplates-1.apkg")
imp = AnkiPackageImporter(dst, tmp) imp = AnkiPackageImporter(dst, col)
imp.dupeOnSchemaChange = True imp.dupeOnSchemaChange = True
imp.run() imp.run()
# then the version with updated template # then the version with updated template
tmp = getUpgradeDeckPath("diffmodeltemplates-2.apkg") col = getUpgradeDeckPath("diffmodeltemplates-2.apkg")
imp = AnkiPackageImporter(dst, tmp) imp = AnkiPackageImporter(dst, col)
imp.dupeOnSchemaChange = True imp.dupeOnSchemaChange = True
imp.run() imp.run()
# collection should contain the note we imported # collection should contain the note we imported
@ -121,14 +121,14 @@ def test_anki2_diffmodel_templates():
def test_anki2_updates(): def test_anki2_updates():
# create a new empty deck # create a new empty deck
dst = getEmptyCol() dst = getEmptyCol()
tmp = getUpgradeDeckPath("update1.apkg") col = getUpgradeDeckPath("update1.apkg")
imp = AnkiPackageImporter(dst, tmp) imp = AnkiPackageImporter(dst, col)
imp.run() imp.run()
assert imp.dupes == 0 assert imp.dupes == 0
assert imp.added == 1 assert imp.added == 1
assert imp.updated == 0 assert imp.updated == 0
# importing again should be idempotent # importing again should be idempotent
imp = AnkiPackageImporter(dst, tmp) imp = AnkiPackageImporter(dst, col)
imp.run() imp.run()
assert imp.dupes == 1 assert imp.dupes == 1
assert imp.added == 0 assert imp.added == 0
@ -136,8 +136,8 @@ def test_anki2_updates():
# importing a newer note should update # importing a newer note should update
assert dst.noteCount() == 1 assert dst.noteCount() == 1
assert dst.db.scalar("select flds from notes").startswith("hello") assert dst.db.scalar("select flds from notes").startswith("hello")
tmp = getUpgradeDeckPath("update2.apkg") col = getUpgradeDeckPath("update2.apkg")
imp = AnkiPackageImporter(dst, tmp) imp = AnkiPackageImporter(dst, col)
imp.run() imp.run()
assert imp.dupes == 0 assert imp.dupes == 0
assert imp.added == 0 assert imp.added == 0

View file

@ -1066,21 +1066,21 @@ def test_reorder():
col.sched.orderCards(1) col.sched.orderCards(1)
assert note.cards()[0].due == 1 assert note.cards()[0].due == 1
# shifting # shifting
f3 = col.newNote() note3 = col.newNote()
f3["Front"] = "three" note3["Front"] = "three"
col.addNote(f3) col.addNote(note3)
f4 = col.newNote() note4 = col.newNote()
f4["Front"] = "four" note4["Front"] = "four"
col.addNote(f4) col.addNote(note4)
assert note.cards()[0].due == 1 assert note.cards()[0].due == 1
assert note2.cards()[0].due == 2 assert note2.cards()[0].due == 2
assert f3.cards()[0].due == 3 assert note3.cards()[0].due == 3
assert f4.cards()[0].due == 4 assert note4.cards()[0].due == 4
col.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True) col.sched.sortCards([note3.cards()[0].id, note4.cards()[0].id], start=1, shift=True)
assert note.cards()[0].due == 3 assert note.cards()[0].due == 3
assert note2.cards()[0].due == 4 assert note2.cards()[0].due == 4
assert f3.cards()[0].due == 1 assert note3.cards()[0].due == 1
assert f4.cards()[0].due == 2 assert note4.cards()[0].due == 2
def test_forget(): def test_forget():

View file

@ -1102,21 +1102,21 @@ def test_reorder():
col.sched.orderCards(1) col.sched.orderCards(1)
assert note.cards()[0].due == 1 assert note.cards()[0].due == 1
# shifting # shifting
f3 = col.newNote() note3 = col.newNote()
f3["Front"] = "three" note3["Front"] = "three"
col.addNote(f3) col.addNote(note3)
f4 = col.newNote() note4 = col.newNote()
f4["Front"] = "four" note4["Front"] = "four"
col.addNote(f4) col.addNote(note4)
assert note.cards()[0].due == 1 assert note.cards()[0].due == 1
assert note2.cards()[0].due == 2 assert note2.cards()[0].due == 2
assert f3.cards()[0].due == 3 assert note3.cards()[0].due == 3
assert f4.cards()[0].due == 4 assert note4.cards()[0].due == 4
col.sched.sortCards([f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True) col.sched.sortCards([note3.cards()[0].id, note4.cards()[0].id], start=1, shift=True)
assert note.cards()[0].due == 3 assert note.cards()[0].due == 3
assert note2.cards()[0].due == 4 assert note2.cards()[0].due == 4
assert f3.cards()[0].due == 1 assert note3.cards()[0].due == 1
assert f4.cards()[0].due == 2 assert note4.cards()[0].due == 2
def test_forget(): def test_forget():