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

The old template handling was too complicated, and generated frequent questions on the forums. By dropping non-active templates we can do away with the generate cards function, and advanced users can simulate the old behaviour by using conditional field templates.
55 lines
1.9 KiB
Python
55 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()
|
|
# 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)
|
|
# but since latex couldn't run, there's nothing there
|
|
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") and
|
|
not os.path.exists("/usr/texbin/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 generation on question display
|
|
f = d.newFact()
|
|
f['Front'] = u"[latex]world[/latex]"
|
|
d.addFact(f)
|
|
f.cards()[0].q()
|
|
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()
|