当前位置: 首页>>代码示例>>Python>>正文


Python shared.getEmptyDeck函数代码示例

本文整理汇总了Python中tests.shared.getEmptyDeck函数的典型用法代码示例。如果您正苦于以下问题:Python getEmptyDeck函数的具体用法?Python getEmptyDeck怎么用?Python getEmptyDeck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getEmptyDeck函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_basic

def setup_basic():
    global deck1, deck2, client, server
    deck1 = getEmptyDeck()
    # 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 = getEmptyDeck(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)
开发者ID:kieranclancy,项目名称:libanki,代码行数:29,代码来源:test_sync.py

示例2: test_counts

def test_counts():
    d = getEmptyDeck()
    # add a second group
    assert d.groupId("new group") == 2
    # for each card type
    for type in range(3):
        # and each of the groups
        for gid in (1,2):
            # create a new fact
            f = d.newFact()
            f['Front'] = u"one"
            d.addFact(f)
            c = f.cards()[0]
            # set type/gid
            c.type = type
            c.queue = type
            c.gid = gid
            c.due = 0
            c.flush()
    d.reset()
    # with the default settings, there's no count limit
    assert d.sched.counts() == (2,2,2)
    # check limit to one group
    d.qconf['groups'] = [1]
    d.reset()
    assert d.sched.counts() == (1,1,1)
    # we don't need to build the queue to get the counts
    assert d.sched.allCounts() == (2,2,2)
    assert d.sched.selCounts() == (1,1,1)
    assert d.sched.allCounts() == (2,2,2)
开发者ID:ChYi,项目名称:libanki,代码行数:30,代码来源:test_sched.py

示例3: test_remove

def test_remove():
    deck = getEmptyDeck()
    # can't remove the default deck
    assertException(AssertionError, lambda: deck.decks.rem(1))
    # create a new deck, and add a note/card to it
    g1 = deck.decks.id("g1")
    f = deck.newNote()
    f['Front'] = u"1"
    f.model()['did'] = g1
    deck.addNote(f)
    c = f.cards()[0]
    assert c.did == g1
    # by default deleting the deck leaves the cards with an invalid did
    assert deck.cardCount() == 1
    deck.decks.rem(g1)
    assert deck.cardCount() == 1
    c.load()
    assert c.did == g1
    # but if we try to get it, we get the default
    assert deck.decks.name(c.did) == "[no deck]"
    # let's create another deck and explicitly set the card to it
    g2 = deck.decks.id("g2")
    c.did = g2; c.flush()
    # this time we'll delete the card/note too
    deck.decks.rem(g2, cardsToo=True)
    assert deck.cardCount() == 0
    assert deck.noteCount() == 0
开发者ID:greedychipmunk,项目名称:libanki,代码行数:27,代码来源:test_decks.py

示例4: test_delete

def test_delete():
    deck = getEmptyDeck()
    f = deck.newFact()
    f['Front'] = u'1'
    f['Back'] = u'2'
    deck.addFact(f)
    cid = f.cards()[0].id
    deck.reset()
    deck.sched.answerCard(deck.sched.getCard(), 2)
    assert deck.db.scalar("select count() from revlog") == 1
    deck.delCards([cid])
    assert deck.cardCount() == 0
    assert deck.factCount() == 0
    assert deck.db.scalar("select count() from facts") == 0
    assert deck.db.scalar("select count() from cards") == 0
    assert deck.db.scalar("select count() from fsums") == 0
    assert deck.db.scalar("select count() from revlog") == 0
    assert deck.db.scalar("select count() from graves") == 0
    # add the fact back
    deck.addFact(f)
    assert deck.cardCount() == 1
    cid = f.cards()[0].id
    # delete again, this time with syncing enabled
    deck.syncName = "abc"
    deck.lastSync = time.time()
    deck.delCards([cid])
    assert deck.cardCount() == 0
    assert deck.factCount() == 0
    assert deck.db.scalar("select count() from graves") != 0
开发者ID:bhutley,项目名称:libanki,代码行数:29,代码来源:test_cards.py

示例5: test_fieldChecksum

def test_fieldChecksum():
    deck = getEmptyDeck()
    f = deck.newFact()
    f['Front'] = u"new"; f['Back'] = u"new2"
    deck.addFact(f)
    assert deck.db.scalar(
        "select csum from fsums") == int("22af645d", 16)
    # empty field should have no checksum
    f['Front'] = u""
    f.flush()
    assert deck.db.scalar(
        "select count() from fsums") == 0
    # changing the val should change the checksum
    f['Front'] = u"newx"
    f.flush()
    assert deck.db.scalar(
        "select csum from fsums") == int("4b0e5a4c", 16)
    # turning off unique and modifying the fact should delete the sum
    m = f.model()
    m.fields[0]['uniq'] = False
    m.flush()
    f.flush()
    assert deck.db.scalar(
        "select count() from fsums") == 0
    # and turning on both should ensure two checksums generated
    m.fields[0]['uniq'] = True
    m.fields[1]['uniq'] = True
    m.flush()
    f.flush()
    assert deck.db.scalar(
        "select count() from fsums") == 2
开发者ID:bhutley,项目名称:libanki,代码行数:31,代码来源:test_deck.py

示例6: test_genrem

def test_genrem():
    d = getEmptyDeck()
    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
开发者ID:ACEfanatic02,项目名称:libanki,代码行数:26,代码来源:test_cards.py

示例7: test_gendeck

def test_gendeck():
    d = getEmptyDeck()
    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
开发者ID:ACEfanatic02,项目名称:libanki,代码行数:29,代码来源:test_cards.py

示例8: test_ordcycle

def test_ordcycle():
    d = getEmptyDeck()
    # add two more templates and set second active
    m = d.models.current()
    mm = d.models
    t = mm.newTemplate("Reverse")
    t["qfmt"] = "{{Back}}"
    t["afmt"] = "{{Front}}"
    mm.addTemplate(m, t)
    t = mm.newTemplate("f2")
    t["qfmt"] = "{{Front}}"
    t["afmt"] = "{{Back}}"
    mm.addTemplate(m, t)
    mm.save(m)
    # create a new note; it should have 3 cards
    f = d.newNote()
    f["Front"] = "1"
    f["Back"] = "1"
    d.addNote(f)
    assert d.cardCount() == 3
    d.reset()
    # ordinals should arrive in order
    assert d.sched.getCard().ord == 0
    assert d.sched.getCard().ord == 1
    assert d.sched.getCard().ord == 2
开发者ID:harcharansidhu,项目名称:anki,代码行数:25,代码来源:test_sched.py

示例9: test_op

def test_op():
    d = getEmptyDeck()
    # should have no undo by default
    assert not d.undoName()
    # let's adjust a study option
    d.save("studyopts")
    d.conf['abc'] = 5
    # it should be listed as undoable
    assert d.undoName() == "studyopts"
    # with about 5 minutes until it's clobbered
    assert time.time() - d._lastSave < 1
    # undoing should restore the old value
    d.undo()
    assert not d.undoName()
    assert 'abc' not in d.conf
    # an (auto)save will clear the undo
    d.save("foo")
    assert d.undoName() == "foo"
    d.save()
    assert not d.undoName()
    # and a review will, too
    d.save("add")
    f = d.newNote()
    f['Front'] = u"one"
    d.addNote(f)
    d.reset()
    assert d.undoName() == "add"
    c = d.sched.getCard()
    d.sched.answerCard(c, 2)
    assert d.undoName() == "Review"
开发者ID:aaronharsh,项目名称:libanki,代码行数:30,代码来源:test_undo.py

示例10: test_templates

def test_templates():
    d = getEmptyDeck()
    m = d.currentModel()
    m.templates[1]['actv'] = True
    m.flush()
    f = d.newFact()
    f['Front'] = u'1'
    f['Back'] = u'2'
    d.addFact(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
    m.moveTemplate(c.template(), 1)
    c.load(); c2.load()
    assert c.ord == 1
    assert c2.ord == 0
    # removing a template should delete its cards
    m.delTemplate(m.templates[0])
    assert d.cardCount() == 1
    # and should have updated the other cards' ordinals
    c = f.cards()[0]
    assert c.ord == 0
    stripHTML(c.q()) == "2"
开发者ID:ChYi,项目名称:libanki,代码行数:26,代码来源:test_models.py

示例11: test_genrem

def test_genrem():
    d = getEmptyDeck()
    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)
    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
    # deleteion calls a hook to let the user abort the delete. let's abort it:
    def abort(val, *args):
        return False
    addHook("remEmptyCards", abort)
    f['Back'] = ""
    f.flush()
    assert len(f.cards()) == 2
开发者ID:aaronharsh,项目名称:libanki,代码行数:32,代码来源:test_cards.py

示例12: test_findReplace

def test_findReplace():
    deck = getEmptyDeck()
    f = deck.newFact()
    f['Front'] = u'foo'
    f['Back'] = u'bar'
    deck.addFact(f)
    f2 = deck.newFact()
    f2['Front'] = u'baz'
    f2['Back'] = u'foo'
    deck.addFact(f2)
    fids = [f.id, f2.id]
    # should do nothing
    assert deck.findReplace(fids, "abc", "123") == 0
    # global replace
    assert deck.findReplace(fids, "foo", "qux") == 2
    f.load(); assert f['Front'] == "qux"
    f2.load(); assert f2['Back'] == "qux"
    # single field replace
    assert deck.findReplace(fids, "qux", "foo", field="Front") == 1
    f.load(); assert f['Front'] == "foo"
    f2.load(); assert f2['Back'] == "qux"
    # regex replace
    assert deck.findReplace(fids, "B.r", "reg") == 0
    f.load(); assert f['Back'] != "reg"
    assert deck.findReplace(fids, "B.r", "reg", regex=True) == 1
    f.load(); assert f['Back'] == "reg"
开发者ID:ChYi,项目名称:libanki,代码行数:26,代码来源:test_find.py

示例13: test_findDupes

def test_findDupes():
    deck = getEmptyDeck()
    f = deck.newNote()
    f['Front'] = u'foo'
    f['Back'] = u'bar'
    deck.addNote(f)
    f2 = deck.newNote()
    f2['Front'] = u'baz'
    f2['Back'] = u'bar'
    deck.addNote(f2)
    f3 = deck.newNote()
    f3['Front'] = u'quux'
    f3['Back'] = u'bar'
    deck.addNote(f3)
    f4 = deck.newNote()
    f4['Front'] = u'quuux'
    f4['Back'] = u'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") == []
开发者ID:ACEfanatic02,项目名称:anki,代码行数:30,代码来源:test_find.py

示例14: test_basic

def test_basic():
    deck = getEmptyDeck()
    # we start with a standard deck
    assert len(deck.decks.decks) == 1
    # it should have an id of 1
    assert deck.decks.name(1)
    # create a new deck
    parentId = deck.decks.id("new deck")
    assert parentId
    assert len(deck.decks.decks) == 2
    # should get the same id
    assert deck.decks.id("new deck") == parentId
    # we start with the default deck selected
    assert deck.decks.selected() == 1
    assert deck.decks.active() == [1]
    # we can select a different deck
    deck.decks.select(parentId)
    assert deck.decks.selected() == parentId
    assert deck.decks.active() == [parentId]
    # let's create a child
    childId = deck.decks.id("new deck::child")
    # it should have been added to the active list
    assert deck.decks.selected() == parentId
    assert deck.decks.active() == [parentId, childId]
    # we can select the child individually too
    deck.decks.select(childId)
    assert deck.decks.selected() == childId
    assert deck.decks.active() == [childId]
开发者ID:shantipants,项目名称:libanki,代码行数:28,代码来源:test_decks.py

示例15: test_overdue_lapse

def test_overdue_lapse():
    d = getEmptyDeck()
    # 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 = 2
    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)
开发者ID:jakeprobst,项目名称:libanki,代码行数:32,代码来源:test_sched.py


注:本文中的tests.shared.getEmptyDeck函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。