コード例 #1
0
def test_mnemosyne10():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/test.mem"))
    i = mnemosyne10.Mnemosyne10Importer(deck, file)
    i.doImport()
    assert i.total == 5
    deck.close()
コード例 #2
0
ファイル: test_importing.py プロジェクト: ChYi/libanki
def test_mnemosyne10():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/test.mem"))
    i = mnemosyne10.Mnemosyne10Importer(deck, file)
    i.doImport()
    assert i.total == 5
    deck.close()
コード例 #3
0
def test_dingsbums():
    deck = Deck()
    deck.addModel(BasicModel())
    startNumberOfFacts = deck.factCount()
    file = unicode(os.path.join(testDir, "importing/dingsbums.xml"))
    i = dingsbums.DingsBumsImporter(deck, file)
    i.doImport()
    assert 7 == i.total
    deck.close()
コード例 #4
0
ファイル: test_importing.py プロジェクト: ChYi/libanki
def test_dingsbums():
    deck = Deck()
    deck.addModel(BasicModel())
    startNumberOfFacts = deck.factCount()
    file = unicode(os.path.join(testDir, "importing/dingsbums.xml"))
    i = dingsbums.DingsBumsImporter(deck, file)
    i.doImport()
    assert 7 == i.total
    deck.close()
コード例 #5
0
def test_csv():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/text-2fields.txt"))
    i = csvfile.TextImporter(deck, file)
    i.doImport()
    # four problems - missing front, dupe front, wrong num of fields
    assert len(i.log) == 4
    assert i.total == 5
    deck.close()
コード例 #6
0
def test_csv_tags():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/text-tags.txt"))
    i = csvfile.TextImporter(deck, file)
    i.doImport()
    facts = deck.db.query(Fact).all()
    assert len(facts) == 2
    assert facts[0].tags == "baz qux" or facts[1].tags == "baz qux"
    deck.close()
コード例 #7
0
def test_supermemo_xml_01_unicode():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/supermemo1.xml"))
    i = supermemo_xml.SupermemoXmlImporter(deck, file)
    #i.META.logToStdOutput = True
    i.doImport()
    # only returning top-level elements?
    assert i.total == 1
    deck.close()
コード例 #8
0
ファイル: test_importing.py プロジェクト: ChYi/libanki
def test_supermemo_xml_01_unicode():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/supermemo1.xml"))
    i = supermemo_xml.SupermemoXmlImporter(deck, file)
    #i.META.logToStdOutput = True
    i.doImport()
    # only returning top-level elements?
    assert i.total == 1
    deck.close()
コード例 #9
0
ファイル: test_importing.py プロジェクト: ChYi/libanki
def test_csv_tags():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/text-tags.txt"))
    i = csvfile.TextImporter(deck, file)
    i.doImport()
    facts = deck.db.query(Fact).all()
    assert len(facts) == 2
    assert facts[0].tags == "baz qux" or facts[1].tags == "baz qux"
    deck.close()
コード例 #10
0
ファイル: test_importing.py プロジェクト: ChYi/libanki
def test_csv():
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/text-2fields.txt"))
    i = csvfile.TextImporter(deck, file)
    i.doImport()
    # four problems - missing front, dupe front, wrong num of fields
    assert len(i.log) == 4
    assert i.total == 5
    deck.close()
コード例 #11
0
 def _checkDecks(self):
     self._decks = []
     decks = self.mw.config.recentDecks()
     if not decks:
         return
     tx = time.time()
     self.mw.progress.start(max=len(decks))
     for c, d in enumerate(decks):
         self.mw.progress.update(
             _("Checking deck %(x)d of %(y)d...") % {
                 'x': c + 1,
                 'y': len(decks)
             })
         base = os.path.basename(d)
         if not os.path.exists(d):
             self._decks.append({
                 'name': base,
                 'state': 'missing',
                 'path': d
             })
             continue
         try:
             mod = os.stat(d)[stat.ST_MTIME]
             t = time.time()
             deck = Deck(d, queue=False, lock=False)
             counts = deck.sched.selCounts()
             dtime = deck.sched.timeToday()
             dreps = deck.sched.repsToday()
             self._decks.append({
                 'path': d,
                 'state': 'ok',
                 'name': deck.name(),
                 'due': counts[1] + counts[2],
                 'new': counts[0],
                 'mod': deck.mod,
                 # these multiply deck check time by a factor of 6
                 'time': dtime,
                 'reps': dreps
             })
             deck.close(save=False)
             # reset modification time for the sake of backup systems
             try:
                 os.utime(d, (mod, mod))
             except:
                 # some misbehaving filesystems may fail here
                 pass
         except Exception, e:
             if "locked" in unicode(e):
                 state = "in use"
             else:
                 state = "corrupt"
             self._decks.append({'name': base, 'state': state, 'path': d})
コード例 #12
0
ファイル: test_deck.py プロジェクト: bhutley/libanki
def test_create():
    global newPath, newMod
    path = "/tmp/test_attachNew.anki"
    try:
        os.unlink(path)
    except OSError:
        pass
    deck = Deck(path)
    # for open()
    newPath = deck.path
    deck.save()
    newMod = deck.mod
    deck.close()
    del deck
コード例 #13
0
ファイル: test_deck.py プロジェクト: ChYi/libanki
def test_create():
    global newPath, newMod
    path = "/tmp/test_attachNew.anki"
    try:
        os.unlink(path)
    except OSError:
        pass
    deck = Deck(path)
    # for open()
    newPath = deck.path
    deck.save()
    newMod = deck.mod
    deck.close()
    del deck
コード例 #14
0
ファイル: deckbrowser.py プロジェクト: ChYi/ankiqt
 def _checkDecks(self):
     self._decks = []
     decks = self.mw.config.recentDecks()
     if not decks:
         return
     tx = time.time()
     self.mw.progress.start(max=len(decks))
     for c, d in enumerate(decks):
         self.mw.progress.update(_("Checking deck %(x)d of %(y)d...") % {
             'x': c+1, 'y': len(decks)})
         base = os.path.basename(d)
         if not os.path.exists(d):
             self._decks.append({'name': base, 'state': 'missing', 'path':d})
             continue
         try:
             mod = os.stat(d)[stat.ST_MTIME]
             t = time.time()
             deck = Deck(d, queue=False, lock=False)
             counts = deck.sched.selCounts()
             dtime = deck.sched.timeToday()
             dreps = deck.sched.repsToday()
             self._decks.append({
                 'path': d,
                 'state': 'ok',
                 'name': deck.name(),
                 'due': counts[1]+counts[2],
                 'new': counts[0],
                 'mod': deck.mod,
                 # these multiply deck check time by a factor of 6
                 'time': dtime,
                 'reps': dreps
                 })
             deck.close(save=False)
             # reset modification time for the sake of backup systems
             try:
                 os.utime(d, (mod, mod))
             except:
                 # some misbehaving filesystems may fail here
                 pass
         except Exception, e:
             if "locked" in unicode(e):
                 state = "in use"
             else:
                 state = "corrupt"
             self._decks.append({'name': base, 'state':state, 'path':d})
コード例 #15
0
def test_anki10():
    # though these are not modified, sqlite updates the mtime, so copy to tmp
    # first
    file_ = unicode(os.path.join(testDir, "importing/test10.anki"))
    file = "/tmp/test10.anki"
    shutil.copy(file_, file)
    file2_ = unicode(os.path.join(testDir, "importing/test10-2.anki"))
    file2 = "/tmp/test10-2.anki"
    shutil.copy(file2_, file2)
    deck = Deck()
    i = anki10.Anki10Importer(deck, file)
    i.doImport()
    assert i.total == 2
    deck.db.rollback()
    deck.close()
    # import a deck into itself - 10-2 is the same as test10, but with one
    # card answered and another deleted. nothing should be synced to client
    deck = Deck(file, backup=False)
    i = anki10.Anki10Importer(deck, file2)
    i.doImport()
    assert i.total == 0
    deck.db.rollback()
コード例 #16
0
ファイル: test_importing.py プロジェクト: ChYi/libanki
def test_anki10():
    # though these are not modified, sqlite updates the mtime, so copy to tmp
    # first
    file_ = unicode(os.path.join(testDir, "importing/test10.anki"))
    file = "/tmp/test10.anki"
    shutil.copy(file_, file)
    file2_ = unicode(os.path.join(testDir, "importing/test10-2.anki"))
    file2 = "/tmp/test10-2.anki"
    shutil.copy(file2_, file2)
    deck = Deck()
    i = anki10.Anki10Importer(deck, file)
    i.doImport()
    assert i.total == 2
    deck.db.rollback()
    deck.close()
    # import a deck into itself - 10-2 is the same as test10, but with one
    # card answered and another deleted. nothing should be synced to client
    deck = Deck(file, backup=False)
    i = anki10.Anki10Importer(deck, file2)
    i.doImport()
    assert i.total == 0
    deck.db.rollback()
コード例 #17
0
ファイル: test_importing.py プロジェクト: ChYi/libanki
def test_updating():
    # get the standard csv deck first
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/text-2fields.txt"))
    i = csvfile.TextImporter(deck, file)
    i.doImport()
    # now update
    file = unicode(os.path.join(testDir, "importing/text-update.txt"))
    i = csvfile.TextImporter(deck, file)
    # first field
    i.updateKey = (0, deck.currentModel.fieldModels[0].id)
    i.multipleCardsAllowed = False
    i.doImport()
    ans = deck.db.scalar(
        u"select answer from cards where question like '%食べる%'")
    assert "to ate" in ans
    # try again with tags
    i.updateKey = (0, deck.currentModel.fieldModels[0].id)
    i.mapping[1] = 0
    i.doImport()
    deck.close()
コード例 #18
0
def test_updating():
    # get the standard csv deck first
    deck = Deck()
    deck.addModel(BasicModel())
    file = unicode(os.path.join(testDir, "importing/text-2fields.txt"))
    i = csvfile.TextImporter(deck, file)
    i.doImport()
    # now update
    file = unicode(os.path.join(testDir, "importing/text-update.txt"))
    i = csvfile.TextImporter(deck, file)
    # first field
    i.updateKey = (0, deck.currentModel.fieldModels[0].id)
    i.multipleCardsAllowed = False
    i.doImport()
    ans = deck.db.scalar(
        u"select answer from cards where question like '%食べる%'")
    assert "to ate" in ans
    # try again with tags
    i.updateKey = (0, deck.currentModel.fieldModels[0].id)
    i.mapping[1] = 0
    i.doImport()
    deck.close()
コード例 #19
0
ファイル: test_deck.py プロジェクト: ChYi/libanki
def test_open():
    deck = Deck(newPath)
    assert deck.mod == newMod
    deck.close()
コード例 #20
0
ファイル: test_deck.py プロジェクト: bhutley/libanki
def test_open():
    deck = Deck(newPath)
    assert deck.mod == newMod
    deck.close()