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)
assert conf["id"] != 1
# connect to new deck
d2 = aopen(newname)
assert d2.cardCount() == 2
col2 = aopen(newname)
assert col2.cardCount() == 2
# 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
conf2 = d2.decks.confForDid(did)
conf2 = col2.decks.confForDid(did)
assert conf2["new"]["perDay"] == 20
dobj = d2.decks.get(did)
dobj = col2.decks.get(did)
# conf should be 1
assert dobj["conf"] == 1
# try again, limited to a deck
@ -78,8 +78,8 @@ def test_export_anki():
os.unlink(newname)
e.did = 1
e.exportInto(newname)
d2 = aopen(newname)
assert d2.cardCount() == 1
col2 = aopen(newname)
assert col2.cardCount() == 1
def test_export_ankipkg():
@ -125,12 +125,12 @@ def test_export_anki_due():
os.unlink(newname)
e.exportInto(newname)
# importing into a new deck, the due date should be equivalent
deck2 = getEmptyCol()
imp = Anki2Importer(deck2, newname)
col2 = getEmptyCol()
imp = Anki2Importer(col2, newname)
imp.run()
c = deck2.getCard(c.id)
deck2.sched.reset()
assert c.due - deck2.sched.today == 1
c = col2.getCard(c.id)
col2.sched.reset()
assert c.due - col2.sched.today == 1
# def test_export_textcard():

View file

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

View file

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

View file

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

View file

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