Beispiel #1
0
def test_anki1_diffmodels():
    # create a new empty deck
    dst = getEmptyDeck()
    # 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())
Beispiel #2
0
def test_suspended():
    # create a new empty deck
    dst = getEmptyDeck()
    # import the 1 card version of the model
    tmp = getUpgradeDeckPath("suspended12.anki")
    imp = Anki1Importer(dst, tmp)
    imp.run()
    assert dst.db.scalar("select due from cards") < 0
Beispiel #3
0
 def _upgrade(self, path):
     if not os.path.exists(path):
         return [_("File was missing.")]
     imp = Anki1Importer(self.col, path)
     # try to copy over dropbox media first
     try:
         self.maybeCopyFromCustomFolder(path)
     except Exception, e:
         imp.log.append(unicode(e))
Beispiel #4
0
def test_anki1():
    # get the deck path to import
    tmp = getUpgradeDeckPath()
    # make sure media is imported properly through the upgrade
    mdir = tmp.replace(".anki2", ".media")
    if not os.path.exists(mdir):
        os.mkdir(mdir)
    open(os.path.join(mdir, "_foo.jpg"), "w").write("foo")
    # create a new empty deck
    dst = getEmptyDeck()
    # import src into dst
    imp = Anki1Importer(dst, tmp)
    imp.run()
    def check():
        assert dst.noteCount() == srcNotes
        assert dst.cardCount() == srcCards
        assert len(os.listdir(dst.media.dir())) == 1
    check()
    # importing should be idempotent
    imp = Anki1Importer(dst, tmp)
    imp.run()
    check()
Beispiel #5
0
 def _upgrade(self, path):
     if not os.path.exists(path):
         return [_("File was missing.")]
     imp = Anki1Importer(self.col, path)
     # try to copy over dropbox media first
     try:
         self.maybeCopyFromCustomFolder(path)
     except Exception as e:
         imp.log.append(repr(str(e)))
     # then run the import
     try:
         imp.run()
     except Exception as e:
         if repr(str(e)) == "invalidFile":
             # already logged
             pass
         else:
             imp.log.append(repr(str(e)))
     self.col.save()
     return imp.log