本文整理汇总了Python中tests.shared.getEmptyCol函数的典型用法代码示例。如果您正苦于以下问题:Python getEmptyCol函数的具体用法?Python getEmptyCol怎么用?Python getEmptyCol使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getEmptyCol函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_basic
def setup_basic():
global deck1, deck2, client, server
deck1 = getEmptyCol()
# add a note to deck 1
f = deck1.newNote()
f["Front"] = u"foo"
f["Back"] = u"bar"
f.tags = [u"foo"]
deck1.addNote(f)
# answer it
deck1.reset()
deck1.sched.answerCard(deck1.sched.getCard(), 4)
# repeat for deck2
deck2 = getEmptyDeckWith(server=True)
f = deck2.newNote()
f["Front"] = u"bar"
f["Back"] = u"bar"
f.tags = [u"bar"]
deck2.addNote(f)
deck2.reset()
deck2.sched.answerCard(deck2.sched.getCard(), 4)
# start with same schema and sync time
deck1.scm = deck2.scm = 0
# and same mod time, so sync does nothing
t = intTime(1000)
deck1.save(mod=t)
deck2.save(mod=t)
server = LocalServer(deck2)
client = Syncer(deck1, server)
示例2: test_anki2
def test_anki2():
global srcNotes, srcCards
# get the deck to import
tmp = getUpgradeDeckPath()
u = Upgrader()
u.check(tmp)
src = u.upgrade()
srcpath = src.path
srcNotes = src.noteCount()
srcCards = src.cardCount()
srcRev = src.db.scalar("select count() from revlog")
# add a media file for testing
open(os.path.join(src.media.dir(), "_foo.jpg"), "w").write("foo")
src.close()
# create a new empty deck
dst = getEmptyCol()
# import src into dst
imp = Anki2Importer(dst, srcpath)
imp.run()
def check():
assert dst.noteCount() == srcNotes
assert dst.cardCount() == srcCards
assert srcRev == dst.db.scalar("select count() from revlog")
mids = [int(x) for x in dst.models.models.keys()]
assert not dst.db.scalar("select count() from notes where mid not in " + ids2str(mids))
assert not dst.db.scalar("select count() from cards where nid not in (select id from notes)")
assert not dst.db.scalar("select count() from revlog where cid not in (select id from cards)")
assert dst.fixIntegrity()[0].startswith("Database rebuilt")
check()
# importing should be idempotent
imp.run()
check()
assert len(os.listdir(dst.media.dir())) == 1
示例3: _test_includes_bad_command
def _test_includes_bad_command(bad):
d = getEmptyCol()
f = d.newNote()
f['Front'] = '[latex]%s[/latex]' % bad
d.addNote(f)
q = f.cards()[0].q()
return ("'%s' is not allowed on cards" % bad in q, "Card content: %s" % q)
示例4: test_anki1_diffmodels
def test_anki1_diffmodels():
# create a new empty deck
dst = getEmptyCol()
# import the 1 card version of the model
tmp = getUpgradeDeckPath("diffmodels1.anki")
imp = Anki1Importer(dst, tmp)
imp.run()
before = dst.noteCount()
# repeating the process should do nothing
imp = Anki1Importer(dst, tmp)
imp.run()
assert before == dst.noteCount()
# then the 2 card version
tmp = getUpgradeDeckPath("diffmodels2.anki")
imp = Anki1Importer(dst, tmp)
imp.run()
after = dst.noteCount()
# as the model schemas differ, should have been imported as new model
assert after == before + 1
# repeating the process should do nothing
beforeModels = len(dst.models.all())
imp = Anki1Importer(dst, tmp)
imp.run()
after = dst.noteCount()
assert after == before + 1
assert beforeModels == len(dst.models.all())
示例5: test_overdue_lapse
def test_overdue_lapse():
# disabled in commit 3069729776990980f34c25be66410e947e9d51a2
return
d = getEmptyCol()
# add a note
f = d.newNote()
f['Front'] = u"one"
d.addNote(f)
# simulate a review that was lapsed and is now due for its normal review
c = f.cards()[0]
c.type = 2
c.queue = 1
c.due = -1
c.odue = -1
c.factor = 2500
c.left = 2002
c.ivl = 0
c.flush()
d.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)
# it should be due tomorrow
assert c.due == d.sched.today + 1
# revert to before
d.rollback()
d.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)
示例6: test_genrem
def test_genrem():
d = getEmptyCol()
f = d.newNote()
f["Front"] = u"1"
f["Back"] = u""
d.addNote(f)
assert len(f.cards()) == 1
m = d.models.current()
mm = d.models
# adding a new template should automatically create cards
t = mm.newTemplate("rev")
t["qfmt"] = "{{Front}}"
t["afmt"] = ""
mm.addTemplate(m, t)
mm.save(m, templates=True)
assert len(f.cards()) == 2
# if the template is changed to remove cards, they'll be removed
t["qfmt"] = "{{Back}}"
mm.save(m, templates=True)
d.remCards(d.emptyCids())
assert len(f.cards()) == 1
# if we add to the note, a card should be automatically generated
f.load()
f["Back"] = "1"
f.flush()
assert len(f.cards()) == 2
示例7: test_timing
def test_timing():
d = getEmptyCol()
# add a few review cards, due today
for i in range(5):
f = d.newNote()
f['Front'] = "num"+str(i)
d.addNote(f)
c = f.cards()[0]
c.type = 2
c.queue = 2
c.due = 0
c.flush()
# fail the first one
d.reset()
c = d.sched.getCard()
# set a a fail delay of 1 second so we don't have to wait
d.sched._cardConf(c)['lapse']['delays'][0] = 1/60.0
d.sched.answerCard(c, 1)
# the next card should be another review
c = d.sched.getCard()
assert c.queue == 2
# but if we wait for a second, the failed card should come back
time.sleep(1)
c = d.sched.getCard()
assert c.queue == 1
示例8: test_findDupes
def test_findDupes():
deck = getEmptyCol()
f = deck.newNote()
f["Front"] = "foo"
f["Back"] = "bar"
deck.addNote(f)
f2 = deck.newNote()
f2["Front"] = "baz"
f2["Back"] = "bar"
deck.addNote(f2)
f3 = deck.newNote()
f3["Front"] = "quux"
f3["Back"] = "bar"
deck.addNote(f3)
f4 = deck.newNote()
f4["Front"] = "quuux"
f4["Back"] = "nope"
deck.addNote(f4)
r = deck.findDupes("Back")
assert r[0][0] == "bar"
assert len(r[0][1]) == 3
# valid search
r = deck.findDupes("Back", "bar")
assert r[0][0] == "bar"
assert len(r[0][1]) == 3
# excludes everything
r = deck.findDupes("Back", "invalid")
assert not r
# front isn't dupe
assert deck.findDupes("Front") == []
示例9: test_newLimits
def test_newLimits():
d = getEmptyCol()
# add some notes
g2 = d.decks.id("Default::foo")
for i in range(30):
f = d.newNote()
f['Front'] = str(i)
if i > 4:
f.model()['did'] = g2
d.addNote(f)
# give the child deck a different configuration
c2 = d.decks.confId("new conf")
d.decks.setConf(d.decks.get(g2), c2)
d.reset()
# both confs have defaulted to a limit of 20
assert d.sched.newCount == 20
# first card we get comes from parent
c = d.sched.getCard()
assert c.did == 1
# limit the parent to 10 cards, meaning we get 10 in total
conf1 = d.decks.confForDid(1)
conf1['new']['perDay'] = 10
d.reset()
assert d.sched.newCount == 10
# if we limit child to 4, we should get 9
conf2 = d.decks.confForDid(g2)
conf2['new']['perDay'] = 4
d.reset()
assert d.sched.newCount == 9
示例10: test_csv
def test_csv():
deck = getEmptyCol()
file = str(os.path.join(testDir, "support/text-2fields.txt"))
i = TextImporter(deck, file)
i.initMapping()
i.run()
# four problems - too many & too few fields, a missing front, and a
# duplicate entry
assert len(i.log) == 5
assert i.total == 5
# if we run the import again, it should update instead
i.run()
assert len(i.log) == 10
assert i.total == 5
# but importing should not clobber tags if they're unmapped
n = deck.getNote(deck.db.scalar("select id from notes"))
n.addTag("test")
n.flush()
i.run()
n.load()
assert n.tags == ['test']
# if add-only mode, count will be 0
i.importMode = 1
i.run()
assert i.total == 0
# and if dupes mode, will reimport everything
assert deck.cardCount() == 5
i.importMode = 2
i.run()
# includes repeated field
assert i.total == 6
assert deck.cardCount() == 11
deck.close()
示例11: test_gendeck
def test_gendeck():
d = getEmptyCol()
cloze = d.models.byName("Cloze")
d.models.setCurrent(cloze)
f = d.newNote()
f["Text"] = u"{{c1::one}}"
d.addNote(f)
assert d.cardCount() == 1
assert f.cards()[0].did == 1
# set the model to a new default deck
newId = d.decks.id("new")
cloze["did"] = newId
d.models.save(cloze)
# a newly generated card should share the first card's deck
f["Text"] += u"{{c2::two}}"
f.flush()
assert f.cards()[1].did == 1
# and same with multiple cards
f["Text"] += u"{{c3::three}}"
f.flush()
assert f.cards()[2].did == 1
# if one of the cards is in a different deck, it should revert to the
# model default
c = f.cards()[1]
c.did = newId
c.flush()
f["Text"] += u"{{c4::four}}"
f.flush()
assert f.cards()[3].did == newId
示例12: test_learn_collapsed
def test_learn_collapsed():
d = getEmptyCol()
# add 2 notes
f = d.newNote()
f['Front'] = u"1"
f = d.addNote(f)
f = d.newNote()
f['Front'] = u"2"
f = d.addNote(f)
# set as a learn card and rebuild queues
d.db.execute("update cards set queue=0, type=0")
d.reset()
# should get '1' first
c = d.sched.getCard()
assert c.q().endswith("1")
# pass it so it's due in 10 minutes
d.sched.answerCard(c, 2)
# get the other card
c = d.sched.getCard()
assert c.q().endswith("2")
# fail it so it's due in 1 minute
d.sched.answerCard(c, 1)
# we shouldn't get the same card again
c = d.sched.getCard()
assert not c.q().endswith("2")
示例13: test_templates
def test_templates():
d = getEmptyCol()
m = d.models.current(); mm = d.models
t = mm.newTemplate("Reverse")
t['qfmt'] = "{{Back}}"
t['afmt'] = "{{Front}}"
mm.addTemplate(m, t)
mm.save(m)
f = d.newNote()
f['Front'] = '1'
f['Back'] = '2'
d.addNote(f)
assert d.cardCount() == 2
(c, c2) = f.cards()
# first card should have first ord
assert c.ord == 0
assert c2.ord == 1
# switch templates
d.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
assert d.models.remTemplate(m, m['tmpls'][0])
assert d.cardCount() == 1
# and should have updated the other cards' ordinals
c = f.cards()[0]
assert c.ord == 0
assert stripHTML(c.q()) == "1"
# it shouldn't be possible to orphan notes by removing templates
t = mm.newTemplate(m)
mm.addTemplate(m, t)
assert not d.models.remTemplate(m, m['tmpls'][0])
示例14: test_findReplace
def test_findReplace():
deck = getEmptyCol()
f = deck.newNote()
f['Front'] = 'foo'
f['Back'] = 'bar'
deck.addNote(f)
f2 = deck.newNote()
f2['Front'] = 'baz'
f2['Back'] = 'foo'
deck.addNote(f2)
nids = [f.id, f2.id]
# should do nothing
assert deck.findReplace(nids, "abc", "123") == 0
# global replace
assert deck.findReplace(nids, "foo", "qux") == 2
f.load(); assert f['Front'] == "qux"
f2.load(); assert f2['Back'] == "qux"
# single field replace
assert deck.findReplace(nids, "qux", "foo", field="Front") == 1
f.load(); assert f['Front'] == "foo"
f2.load(); assert f2['Back'] == "qux"
# regex replace
assert deck.findReplace(nids, "B.r", "reg") == 0
f.load(); assert f['Back'] != "reg"
assert deck.findReplace(nids, "B.r", "reg", regex=True) == 1
f.load(); assert f['Back'] == "reg"
示例15: test_anki2_diffmodels
def test_anki2_diffmodels():
# create a new empty deck
dst = getEmptyCol()
# import the 1 card version of the model
tmp = getUpgradeDeckPath("diffmodels2-1.apkg")
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
before = dst.noteCount()
# repeating the process should do nothing
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
assert before == dst.noteCount()
# then the 2 card version
tmp = getUpgradeDeckPath("diffmodels2-2.apkg")
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
after = dst.noteCount()
# as the model schemas differ, should have been imported as new model
assert after == before + 1
# and the new model should have both cards
assert dst.cardCount() == 3
# repeating the process should do nothing
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
after = dst.noteCount()
assert after == before + 1
assert dst.cardCount() == 3