mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00

Like the previous change, models have been moved from a separate DB table to an entry in the deck. We need them for many operations including reviewing, and it's easier to keep them in memory than half on disk with a cache that gets cleared every time we .reset(). This means they are easily serialized as well - previously they were part Python and part JSON, which made access confusing. Because the data is all pulled from JSON now, the instance methods have been moved to the model registry. Eg: model.addField(...) -> deck.models.addField(model, ...). - IDs are now timestamped as with groups et al. - The data field for plugins was also removed. Config info can be added to deck.conf; larger data should be stored externally. - Upgrading needs to be updated for the new model structure. - HexifyID() now accepts strings as well, as our IDs get converted to strings in the serialization process.
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
# coding: utf-8
|
|
|
|
import os
|
|
from tests.shared import assertException, getEmptyDeck
|
|
from anki.utils import stripHTML, intTime
|
|
from anki.hooks import addHook
|
|
|
|
def test_latex():
|
|
d = getEmptyDeck()
|
|
# no media directory to start
|
|
assert not d.media.dir()
|
|
# change latex cmd to simulate broken build
|
|
import anki.latex
|
|
anki.latex.latexCmd[0] = "nolatex"
|
|
# add a fact with latex
|
|
f = d.newFact()
|
|
f['Front'] = u"[latex]hello[/latex]"
|
|
d.addFact(f)
|
|
# adding will have created the media
|
|
assert d.media.dir()
|
|
# but since latex couldn't run, it will be empty
|
|
assert len(os.listdir(d.media.dir())) == 0
|
|
# check the error message
|
|
msg = f.cards()[0].q()
|
|
assert "executing latex" in msg
|
|
assert "installed" in msg
|
|
# check if we have latex installed, and abort test if we don't
|
|
if not os.path.exists("/usr/bin/latex"):
|
|
print "aborting test; latex is not installed"
|
|
return
|
|
# fix path
|
|
anki.latex.latexCmd[0] = "latex"
|
|
# check media db should cause latex to be generated
|
|
d.media.check()
|
|
assert len(os.listdir(d.media.dir())) == 1
|
|
assert ".png" in f.cards()[0].q()
|
|
# adding new facts should cause immediate generation
|
|
f = d.newFact()
|
|
f['Front'] = u"[latex]world[/latex]"
|
|
d.addFact(f)
|
|
assert len(os.listdir(d.media.dir())) == 2
|
|
# another fact with the same media should reuse
|
|
f = d.newFact()
|
|
f['Front'] = u" [latex]world[/latex]"
|
|
d.addFact(f)
|
|
assert len(os.listdir(d.media.dir())) == 2
|
|
oldcard = f.cards()[0]
|
|
assert ".png" in oldcard.q()
|
|
# if we turn off building, then previous cards should work, but cards with
|
|
# missing media will show the latex
|
|
anki.latex.build = False
|
|
f = d.newFact()
|
|
f['Front'] = u"[latex]foo[/latex]"
|
|
d.addFact(f)
|
|
assert len(os.listdir(d.media.dir())) == 2
|
|
assert stripHTML(f.cards()[0].q()) == "[latex]foo[/latex]"
|
|
assert ".png" in oldcard.q()
|