2012-12-21 08:51:59 +01:00
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
import os
|
2014-06-03 10:38:47 +02:00
|
|
|
from tests.shared import getEmptyCol
|
2012-12-22 01:17:10 +01:00
|
|
|
from anki.utils import stripHTML
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def test_latex():
|
2014-06-03 10:38:47 +02:00
|
|
|
d = getEmptyCol()
|
2012-12-21 08:51:59 +01:00
|
|
|
# change latex cmd to simulate broken build
|
|
|
|
import anki.latex
|
2014-06-03 10:25:43 +02:00
|
|
|
anki.latex.latexCmds[0][0] = "nolatex"
|
2012-12-21 08:51:59 +01:00
|
|
|
# add a note with latex
|
|
|
|
f = d.newNote()
|
|
|
|
f['Front'] = u"[latex]hello[/latex]"
|
|
|
|
d.addNote(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()
|
2014-06-03 10:25:43 +02:00
|
|
|
assert "executing nolatex" in msg
|
2012-12-21 08:51:59 +01:00
|
|
|
assert "installed" in msg
|
|
|
|
# check if we have latex installed, and abort test if we don't
|
2013-03-15 22:40:03 +01:00
|
|
|
for cmd in ("latex", "dvipng"):
|
|
|
|
if (not os.path.exists("/usr/bin/"+cmd) and
|
|
|
|
not os.path.exists("/usr/texbin/"+cmd)):
|
|
|
|
print "aborting test; %s is not installed" % cmd
|
|
|
|
return
|
2012-12-21 08:51:59 +01:00
|
|
|
# fix path
|
2014-06-03 10:25:43 +02:00
|
|
|
anki.latex.latexCmds[0][0] = "latex"
|
2012-12-21 08:51:59 +01:00
|
|
|
# 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 notes should cause generation on question display
|
|
|
|
f = d.newNote()
|
|
|
|
f['Front'] = u"[latex]world[/latex]"
|
|
|
|
d.addNote(f)
|
|
|
|
f.cards()[0].q()
|
|
|
|
assert len(os.listdir(d.media.dir())) == 2
|
|
|
|
# another note with the same media should reuse
|
|
|
|
f = d.newNote()
|
|
|
|
f['Front'] = u" [latex]world[/latex]"
|
|
|
|
d.addNote(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.newNote()
|
|
|
|
f['Front'] = u"[latex]foo[/latex]"
|
|
|
|
d.addNote(f)
|
|
|
|
assert len(os.listdir(d.media.dir())) == 2
|
|
|
|
assert stripHTML(f.cards()[0].q()) == "[latex]foo[/latex]"
|
|
|
|
assert ".png" in oldcard.q()
|