mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use long `re
` flags
This commit is contained in:
parent
183dd51f4d
commit
38ac67bd6c
@ -147,7 +147,7 @@ def test_html_entity(app):
|
||||
app.build(force_all=True)
|
||||
valid_entities = {'amp', 'lt', 'gt', 'quot', 'apos'}
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
for entity in re.findall(r'&([a-z]+);', content, re.M):
|
||||
for entity in re.findall(r'&([a-z]+);', content, re.MULTILINE):
|
||||
assert entity not in valid_entities
|
||||
|
||||
|
||||
|
@ -12,34 +12,34 @@ def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = ('<li><p><a class="reference internal" href="#introduce-of-sphinx">'
|
||||
'<span class=".*?">Introduce of Sphinx</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = ('<li><p><a class="reference internal" href="#installation">'
|
||||
'<span class="std std-ref">Installation</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = ('<li><p><a class="reference internal" href="#for-windows-users">'
|
||||
'<span class="std std-ref">For Windows users</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = ('<li><p><a class="reference internal" href="#for-unix-users">'
|
||||
'<span class="std std-ref">For UNIX users</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = ('<li><p><a class="reference internal" href="#linux">'
|
||||
'<span class="std std-ref">Linux</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = ('<li><p><a class="reference internal" href="#freebsd">'
|
||||
'<span class="std std-ref">FreeBSD</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
# for smart_quotes (refs: #4027)
|
||||
html = ('<li><p><a class="reference internal" '
|
||||
'href="#this-one-s-got-an-apostrophe">'
|
||||
'<span class="std std-ref">This one’s got an apostrophe'
|
||||
'</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
|
||||
# Reuse test definition from above, just change the test root directory
|
||||
@ -58,20 +58,20 @@ def test_autosectionlabel_maxdepth(app, status, warning):
|
||||
# depth: 1
|
||||
html = ('<li><p><a class="reference internal" href="#test-ext-autosectionlabel">'
|
||||
'<span class=".*?">test-ext-autosectionlabel</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
# depth: 2
|
||||
html = ('<li><p><a class="reference internal" href="#installation">'
|
||||
'<span class="std std-ref">Installation</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
# depth: 3
|
||||
html = ('<li><p><a class="reference internal" href="#for-windows-users">'
|
||||
'<span class="std std-ref">For Windows users</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
# depth: 4
|
||||
html = '<li><p><span class="xref std std-ref">Linux</span></p></li>'
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
assert "WARNING: undefined label: 'linux'" in warning.getvalue()
|
||||
|
@ -18,26 +18,26 @@ def test_graphviz_png_html(app, status, warning):
|
||||
r'<div class="graphviz"><img .*?/></div>\s*<figcaption>\s*'
|
||||
r'<p><span class="caption-text">caption of graph</span>.*</p>\s*'
|
||||
r'</figcaption>\s*</figure>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = 'Hello <div class="graphviz"><img .*?/></div>\n graphviz world'
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = ('<img src=".*?" alt="digraph foo {\nbaz -> qux\n}" '
|
||||
'class="graphviz neato-graph" />')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = (r'<figure class="align-right" .*?>\s*'
|
||||
r'<div class="graphviz"><img .*?/></div>\s*<figcaption>\s*'
|
||||
r'<p><span class="caption-text">on <em>right</em></span>.*</p>\s*'
|
||||
r'</figcaption>\s*</figure>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = (r'<div align=\"center\" class=\"align-center\">'
|
||||
r'<div class="graphviz"><img src=\".*\.png\" alt=\"digraph foo {\n'
|
||||
r'centered\n'
|
||||
r'}\" class="graphviz" /></div>\n</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-graphviz',
|
||||
@ -57,12 +57,12 @@ def test_graphviz_svg_html(app, status, warning):
|
||||
r'<p><span class=\"caption-text\">caption of graph</span>.*</p>\n'
|
||||
r'</figcaption>\n'
|
||||
r'</figure>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = (r'Hello <div class="graphviz"><object.*>\n'
|
||||
r'\s*<p class=\"warning\">graph</p></object></div>\n'
|
||||
r' graphviz world')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = (r'<figure class=\"align-right\" .*\>\n'
|
||||
r'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
||||
@ -73,7 +73,7 @@ def test_graphviz_svg_html(app, status, warning):
|
||||
r'<p><span class=\"caption-text\">on <em>right</em></span>.*</p>\n'
|
||||
r'</figcaption>\n'
|
||||
r'</figure>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
html = (r'<div align=\"center\" class=\"align-center\">'
|
||||
r'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
||||
@ -81,10 +81,10 @@ def test_graphviz_svg_html(app, status, warning):
|
||||
r'centered\n'
|
||||
r'}</p></object></div>\n'
|
||||
r'</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
assert re.search(html, content, re.DOTALL)
|
||||
|
||||
image_re = r'.*data="([^"]+)".*?digraph test'
|
||||
image_path_match = re.search(image_re, content, re.S)
|
||||
image_path_match = re.search(image_re, content, re.DOTALL)
|
||||
assert image_path_match
|
||||
|
||||
image_path = image_path_match.group(1)
|
||||
@ -109,21 +109,21 @@ def test_graphviz_latex(app, status, warning):
|
||||
macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n'
|
||||
'\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n'
|
||||
'\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}')
|
||||
assert re.search(macro, content, re.S)
|
||||
assert re.search(macro, content, re.DOTALL)
|
||||
|
||||
macro = 'Hello \\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf} graphviz world'
|
||||
assert re.search(macro, content, re.S)
|
||||
assert re.search(macro, content, re.DOTALL)
|
||||
|
||||
macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n'
|
||||
'\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n'
|
||||
'\\\\caption{on \\\\sphinxstyleemphasis{right}}'
|
||||
'\\\\label{.*}\\\\end{wrapfigure}')
|
||||
assert re.search(macro, content, re.S)
|
||||
assert re.search(macro, content, re.DOTALL)
|
||||
|
||||
macro = (r'\{\\hfill'
|
||||
r'\\sphinxincludegraphics\[\]{graphviz-.*}'
|
||||
r'\\hspace\*{\\fill}}')
|
||||
assert re.search(macro, content, re.S)
|
||||
assert re.search(macro, content, re.DOTALL)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-graphviz', confoverrides={'language': 'xx'})
|
||||
@ -133,7 +133,7 @@ def test_graphviz_i18n(app, status, warning):
|
||||
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = '<img src=".*?" alt="digraph {\n BAR -> BAZ\n}" class="graphviz" />'
|
||||
assert re.search(html, content, re.M)
|
||||
assert re.search(html, content, re.MULTILINE)
|
||||
|
||||
|
||||
def test_graphviz_parse_mapfile():
|
||||
|
@ -171,7 +171,7 @@ def test_inheritance_diagram_png_html(tmp_path, app):
|
||||
'class="inheritance graphviz" /></div>\n<figcaption>\n<p>'
|
||||
'<span class="caption-text">Test Foo!</span><a class="headerlink" href="#id1" '
|
||||
'title="Link to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
|
||||
assert re.search(pattern, content, re.M)
|
||||
assert re.search(pattern, content, re.MULTILINE)
|
||||
|
||||
subdir_content = (app.outdir / 'subdir/page1.html').read_text(encoding='utf8')
|
||||
subdir_maps = re.findall('<map .+\n.+\n</map>', subdir_content)
|
||||
@ -221,7 +221,7 @@ def test_inheritance_diagram_svg_html(tmp_path, app):
|
||||
'Test Foo!</span><a class="headerlink" href="#id1" '
|
||||
'title="Link to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
|
||||
|
||||
assert re.search(pattern, content, re.M)
|
||||
assert re.search(pattern, content, re.MULTILINE)
|
||||
|
||||
subdir_content = (app.outdir / 'subdir/page1.html').read_text(encoding='utf8')
|
||||
subdir_svgs = re.findall('<object data="../(_images/inheritance-\\w+.svg?)"', subdir_content)
|
||||
@ -256,7 +256,7 @@ def test_inheritance_diagram_latex(app, status, warning):
|
||||
pattern = ('\\\\begin{figure}\\[htbp]\n\\\\centering\n\\\\capstart\n\n'
|
||||
'\\\\sphinxincludegraphics\\[\\]{inheritance-\\w+.pdf}\n'
|
||||
'\\\\caption{Test Foo!}\\\\label{\\\\detokenize{index:id1}}\\\\end{figure}')
|
||||
assert re.search(pattern, content, re.M)
|
||||
assert re.search(pattern, content, re.MULTILINE)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-inheritance_diagram',
|
||||
@ -282,7 +282,7 @@ def test_inheritance_diagram_latex_alias(app, status, warning):
|
||||
'class="inheritance graphviz" /></div>\n<figcaption>\n<p>'
|
||||
'<span class="caption-text">Test Foo!</span><a class="headerlink" href="#id1" '
|
||||
'title="Link to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
|
||||
assert re.search(pattern, content, re.M)
|
||||
assert re.search(pattern, content, re.MULTILINE)
|
||||
|
||||
|
||||
def test_import_classes(rootdir):
|
||||
|
@ -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'),
|
||||
@ -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'),
|
||||
@ -107,7 +107,7 @@ def test_mathjax_align(app, status, warning):
|
||||
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,24 +131,24 @@ 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',
|
||||
@ -173,7 +173,7 @@ def test_math_eqref_format_latex(app, status, warning):
|
||||
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',
|
||||
|
@ -146,7 +146,7 @@ class Changes:
|
||||
f.write(body)
|
||||
|
||||
def filter_empty_sections(self, body):
|
||||
return re.sub('^\n.+\n-{3,}\n+(?=\n.+\n[-=]{3,}\n)', '', body, flags=re.M)
|
||||
return re.sub('^\n.+\n-{3,}\n+(?=\n.+\n[-=]{3,}\n)', '', body, flags=re.MULTILINE)
|
||||
|
||||
|
||||
def parse_options(argv):
|
||||
|
Loading…
Reference in New Issue
Block a user