1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
"""
test_jsmath
~~~~~~~~~~~
Test for jsmath extension.
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import pytest
import sphinx
@pytest.mark.sphinx('html', testroot='basic')
def test_basic(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'math.html').read_text()
print(content)
assert 'jsmath.js' in content
assert '<div class="math notranslate nohighlight">\nE = mc^2</div>' in content
assert ('<span class="eqno">(1)<a class="headerlink" href="#equation-pythagorean" '
'title="Permalink to this equation">¶</a></span>'
'<div class="math notranslate nohighlight" id="equation-pythagorean">\n'
'a^2 + b^2 = c^2</div>' in content)
assert ('<span class="eqno">(2)<a class="headerlink" href="#equation-math-0" '
'title="Permalink to this equation">¶</a></span>'
'<div class="math notranslate nohighlight" id="equation-math-0">\n'
'\\begin{split}y > x \\in 2\\end{split}</div>' in content)
assert '<a class="reference internal" href="#equation-pythagorean">(1)</a>' in content
assert '<a class="reference internal" href="#equation-pythagorean">(1)</a>' in content
@pytest.mark.sphinx('html', testroot='basic',
confoverrides={'numfig': True, 'math_numfig': True})
def test_numfig_enabled(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'math.html').read_text()
assert 'jsmath.js' in content
assert '<div class="math notranslate nohighlight">\nE = mc^2</div>' in content
assert ('<span class="eqno">(1.1)<a class="headerlink" href="#equation-pythagorean" '
'title="Permalink to this equation">¶</a></span>'
'<div class="math notranslate nohighlight" id="equation-pythagorean">\n'
'a^2 + b^2 = c^2</div>' in content)
assert ('<span class="eqno">(1.2)<a class="headerlink" href="#equation-math-0" '
'title="Permalink to this equation">¶</a></span>'
'<div class="math notranslate nohighlight" id="equation-math-0">\n'
'\\begin{split}y > x \\in 2\\end{split}</div>' in content)
assert '<a class="reference internal" href="#equation-pythagorean">(1.1)</a>' in content
assert '<a class="reference internal" href="#equation-pythagorean">(1.1)</a>' in content
@pytest.mark.skipif(
sphinx.version_info < (8, 2),
reason='Sphinx < 8.2 does not have `has_maths_elements` in context',
)
@pytest.mark.sphinx('html', testroot='nomath')
def test_disabled_when_equations_not_found(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').read_text()
assert 'jsmath.js' not in content
|