diff options
Diffstat (limited to '')
-rw-r--r-- | tests/test_extensions/test_ext_math.py (renamed from tests/test_ext_math.py) | 104 |
1 files changed, 74 insertions, 30 deletions
diff --git a/tests/test_ext_math.py b/tests/test_extensions/test_ext_math.py index d5331f8..b673f83 100644 --- a/tests/test_ext_math.py +++ b/tests/test_extensions/test_ext_math.py @@ -25,9 +25,9 @@ def has_binary(binary): @pytest.mark.skipif(not has_binary('dvipng'), reason='Requires dvipng" binary') @pytest.mark.sphinx('html', testroot='ext-math-simple', - confoverrides = {'extensions': ['sphinx.ext.imgmath']}) + confoverrides={'extensions': ['sphinx.ext.imgmath']}) def test_imgmath_png(app, status, warning): - app.builder.build_all() + app.build(force_all=True) if "LaTeX command 'latex' cannot be run" in warning.getvalue(): msg = 'LaTeX command "latex" is not available' raise pytest.skip.Exception(msg) @@ -39,7 +39,7 @@ def test_imgmath_png(app, status, warning): shutil.rmtree(app.outdir) html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"' r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>') - assert re.search(html, content, re.S) + assert re.search(html, content, re.DOTALL) @pytest.mark.skipif(not has_binary('dvisvgm'), @@ -48,7 +48,7 @@ def test_imgmath_png(app, status, warning): confoverrides={'extensions': ['sphinx.ext.imgmath'], 'imgmath_image_format': 'svg'}) def test_imgmath_svg(app, status, warning): - app.builder.build_all() + app.build(force_all=True) if "LaTeX command 'latex' cannot be run" in warning.getvalue(): msg = 'LaTeX command "latex" is not available' raise pytest.skip.Exception(msg) @@ -60,7 +60,7 @@ def test_imgmath_svg(app, status, warning): shutil.rmtree(app.outdir) html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"' r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>') - assert re.search(html, content, re.S) + assert re.search(html, content, re.DOTALL) @pytest.mark.skipif(not has_binary('dvisvgm'), @@ -70,7 +70,7 @@ def test_imgmath_svg(app, status, warning): 'imgmath_image_format': 'svg', 'imgmath_embed': True}) def test_imgmath_svg_embed(app, status, warning): - app.builder.build_all() + app.build(force_all=True) if "LaTeX command 'latex' cannot be run" in warning.getvalue(): msg = 'LaTeX command "latex" is not available' raise pytest.skip.Exception(msg) @@ -88,7 +88,7 @@ def test_imgmath_svg_embed(app, status, warning): confoverrides={'extensions': ['sphinx.ext.mathjax'], 'mathjax_options': {'integrity': 'sha384-0123456789'}}) def test_mathjax_options(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') shutil.rmtree(app.outdir) @@ -100,14 +100,14 @@ def test_mathjax_options(app, status, warning): @pytest.mark.sphinx('html', testroot='ext-math', confoverrides={'extensions': ['sphinx.ext.mathjax']}) def test_mathjax_align(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') shutil.rmtree(app.outdir) html = (r'<div class="math notranslate nohighlight">\s*' r'\\\[ \\begin\{align\}\\begin\{aligned\}S \&= \\pi r\^2\\\\' r'V \&= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]</div>') - assert re.search(html, content, re.S) + assert re.search(html, content, re.DOTALL) @pytest.mark.sphinx('html', testroot='ext-math', @@ -119,7 +119,7 @@ def test_math_number_all_mathjax(app, status, warning): content = (app.outdir / 'index.html').read_text(encoding='utf8') html = (r'<div class="math notranslate nohighlight" id="equation-index-0">\s*' r'<span class="eqno">\(1\)<a .*>\xb6</a></span>\\\[a\^2\+b\^2=c\^2\\\]</div>') - assert re.search(html, content, re.S) + assert re.search(html, content, re.DOTALL) @pytest.mark.sphinx('latex', testroot='ext-math', @@ -131,31 +131,31 @@ def test_math_number_all_latex(app, status, warning): macro = (r'\\begin{equation\*}\s*' r'\\begin{split}a\^2\+b\^2=c\^2\\end{split}\s*' r'\\end{equation\*}') - assert re.search(macro, content, re.S) + assert re.search(macro, content, re.DOTALL) macro = r'Inline \\\(E=mc\^2\\\)' - assert re.search(macro, content, re.S) + assert re.search(macro, content, re.DOTALL) macro = (r'\\begin{equation\*}\s*' r'\\begin{split}e\^{i\\pi}\+1=0\\end{split}\s+' r'\\end{equation\*}') - assert re.search(macro, content, re.S) + assert re.search(macro, content, re.DOTALL) macro = (r'\\begin{align\*}\\!\\begin{aligned}\s*' r'S &= \\pi r\^2\\\\\s*' r'V &= \\frac\{4}\{3} \\pi r\^3\\\\\s*' r'\\end{aligned}\\end{align\*}') - assert re.search(macro, content, re.S) + assert re.search(macro, content, re.DOTALL) macro = r'Referencing equation \\eqref{equation:math:foo}.' - assert re.search(macro, content, re.S) + assert re.search(macro, content, re.DOTALL) @pytest.mark.sphinx('html', testroot='ext-math', confoverrides={'extensions': ['sphinx.ext.mathjax'], 'math_eqref_format': 'Eq.{number}'}) def test_math_eqref_format_html(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'math.html').read_text(encoding='utf8') html = ('<p>Referencing equation <a class="reference internal" ' @@ -168,12 +168,12 @@ def test_math_eqref_format_html(app, status, warning): confoverrides={'extensions': ['sphinx.ext.mathjax'], 'math_eqref_format': 'Eq.{number}'}) def test_math_eqref_format_latex(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'python.tex').read_text(encoding='utf8') macro = (r'Referencing equation Eq.\\ref{equation:math:foo} and ' r'Eq.\\ref{equation:math:foo}.') - assert re.search(macro, content, re.S) + assert re.search(macro, content, re.DOTALL) @pytest.mark.sphinx('html', testroot='ext-math', @@ -181,7 +181,7 @@ def test_math_eqref_format_latex(app, status, warning): 'numfig': True, 'math_numfig': True}) def test_mathjax_numfig_html(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'math.html').read_text(encoding='utf8') html = ('<div class="math notranslate nohighlight" id="equation-math-0">\n' @@ -199,7 +199,7 @@ def test_mathjax_numfig_html(app, status, warning): 'numfig_secnum_depth': 0, 'math_numfig': True}) def test_imgmath_numfig_html(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'page.html').read_text(encoding='utf8') html = '<span class="eqno">(3)<a class="headerlink" href="#equation-bar"' @@ -213,7 +213,7 @@ def test_imgmath_numfig_html(app, status, warning): @pytest.mark.sphinx('dummy', testroot='ext-math-compat') def test_math_compat(app, status, warning): with warnings.catch_warnings(record=True): - app.builder.build_all() + app.build(force_all=True) doctree = app.env.get_and_resolve_doctree('index', app.builder) assert_node(doctree, @@ -239,7 +239,7 @@ def test_math_compat(app, status, warning): confoverrides={'extensions': ['sphinx.ext.mathjax'], 'mathjax3_config': {'extensions': ['tex2jax.js']}}) def test_mathjax3_config(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert MATHJAX_URL in content @@ -251,7 +251,7 @@ def test_mathjax3_config(app, status, warning): confoverrides={'extensions': ['sphinx.ext.mathjax'], 'mathjax2_config': {'extensions': ['tex2jax.js']}}) def test_mathjax2_config(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert ('<script async="async" src="%s">' % MATHJAX_URL in content) @@ -265,7 +265,7 @@ def test_mathjax2_config(app, status, warning): 'mathjax_options': {'async': 'async'}, 'mathjax3_config': {'extensions': ['tex2jax.js']}}) def test_mathjax_options_async_for_mathjax3(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert MATHJAX_URL in content @@ -277,7 +277,7 @@ def test_mathjax_options_async_for_mathjax3(app, status, warning): 'mathjax_options': {'defer': 'defer'}, 'mathjax2_config': {'extensions': ['tex2jax.js']}}) def test_mathjax_options_defer_for_mathjax2(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert ('<script defer="defer" src="%s">' % MATHJAX_URL in content) @@ -291,7 +291,7 @@ def test_mathjax_options_defer_for_mathjax2(app, status, warning): }, ) def test_mathjax_path(app): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert '<script async="async" src="_static/MathJax.js"></script>' in content @@ -305,7 +305,7 @@ def test_mathjax_path(app): }, ) def test_mathjax_path_config(app): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert '<script async="async" src="_static/MathJax.js?config=scipy-mathjax"></script>' in content @@ -314,7 +314,7 @@ def test_mathjax_path_config(app): @pytest.mark.sphinx('html', testroot='ext-math', confoverrides={'extensions': ['sphinx.ext.mathjax']}) def test_mathjax_is_installed_only_if_document_having_math(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert MATHJAX_URL in content @@ -326,7 +326,7 @@ def test_mathjax_is_installed_only_if_document_having_math(app, status, warning) @pytest.mark.sphinx('html', testroot='basic', confoverrides={'extensions': ['sphinx.ext.mathjax']}) def test_mathjax_is_not_installed_if_no_equations(app, status, warning): - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert 'MathJax.js' not in content @@ -336,10 +336,54 @@ def test_mathjax_is_not_installed_if_no_equations(app, status, warning): confoverrides={'extensions': ['sphinx.ext.mathjax']}) def test_mathjax_is_installed_if_no_equations_when_forced(app, status, warning): app.set_html_assets_policy('always') - app.builder.build_all() + app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert MATHJAX_URL in content content = (app.outdir / 'nomath.html').read_text(encoding='utf8') assert MATHJAX_URL in content + + +@pytest.mark.sphinx('html', testroot='ext-math-include', + confoverrides={'extensions': ['sphinx.ext.mathjax']}) +def test_mathjax_is_installed_if_included_file_has_equations(app): + app.build(force_all=True) + + # no real equations at the rst level, but includes "included" + content = (app.outdir / 'index.html').read_text(encoding='utf8') + assert MATHJAX_URL in content + + # no real equations at the rst level, but includes "math.rst" + content = (app.outdir / 'included.html').read_text(encoding='utf8') + assert MATHJAX_URL in content + + content = (app.outdir / 'math.html').read_text(encoding='utf8') + assert MATHJAX_URL in content + + +@pytest.mark.sphinx('singlehtml', testroot='ext-math', + confoverrides={'extensions': ['sphinx.ext.mathjax']}) +def test_mathjax_is_installed_only_if_document_having_math_singlehtml(app): + app.build(force_all=True) + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + assert MATHJAX_URL in content + + +@pytest.mark.sphinx('singlehtml', testroot='basic', + confoverrides={'extensions': ['sphinx.ext.mathjax']}) +def test_mathjax_is_not_installed_if_no_equations_singlehtml(app): + app.build(force_all=True) + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + assert 'MathJax.js' not in content + + +@pytest.mark.sphinx('singlehtml', testroot='ext-math-include', + confoverrides={'extensions': ['sphinx.ext.mathjax']}) +def test_mathjax_is_installed_if_included_file_has_equations_singlehtml(app): + app.build(force_all=True) + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + assert MATHJAX_URL in content |