Merge pull request #7081 from tk0miya/path_read_text

testing: Add Path.read_text() and Path.read_bytes()
This commit is contained in:
Takeshi KOMIYA 2020-02-01 12:21:39 +09:00 committed by GitHub
commit 1fee66a2f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 328 additions and 297 deletions

View File

@ -27,6 +27,8 @@ Deprecated
---------- ----------
* ``sphinx.domains.std.StandardDomain.add_object()`` * ``sphinx.domains.std.StandardDomain.add_object()``
* ``sphinx.testing.path.Path.text()``
* ``sphinx.testing.path.Path.bytes()``
Features added Features added
-------------- --------------

View File

@ -31,6 +31,16 @@ The following is a list of deprecated interfaces.
- 5.0 - 5.0
- ``sphinx.domains.std.StandardDomain.note_object()`` - ``sphinx.domains.std.StandardDomain.note_object()``
* - ``sphinx.testing.path.Path.text()``
- 3.0
- 5.0
- ``sphinx.testing.path.Path.read_text()``
* - ``sphinx.testing.path.Path.bytes()``
- 3.0
- 5.0
- ``sphinx.testing.path.Path.read_bytes()``
* - ``decode`` argument of ``sphinx.pycode.ModuleAnalyzer()`` * - ``decode`` argument of ``sphinx.pycode.ModuleAnalyzer()``
- 2.4 - 2.4
- 4.0 - 4.0

View File

@ -10,8 +10,11 @@ import builtins
import os import os
import shutil import shutil
import sys import sys
import warnings
from typing import Any, Callable, IO, List from typing import Any, Callable, IO, List
from sphinx.deprecation import RemovedInSphinx50Warning
FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()
@ -135,6 +138,14 @@ class path(str):
f.write(text) f.write(text)
def text(self, encoding: str = 'utf-8', **kwargs: Any) -> str: def text(self, encoding: str = 'utf-8', **kwargs: Any) -> str:
"""
Returns the text in the file.
"""
warnings.warn('Path.text() is deprecated. Please use read_text() instead.',
RemovedInSphinx50Warning, stacklevel=2)
return self.read_text(encoding, **kwargs)
def read_text(self, encoding: str = 'utf-8', **kwargs: Any) -> str:
""" """
Returns the text in the file. Returns the text in the file.
""" """
@ -142,6 +153,14 @@ class path(str):
return f.read() return f.read()
def bytes(self) -> builtins.bytes: def bytes(self) -> builtins.bytes:
"""
Returns the bytes in the file.
"""
warnings.warn('Path.bytes() is deprecated. Please use read_bytes() instead.',
RemovedInSphinx50Warning, stacklevel=2)
return self.read_bytes()
def read_bytes(self) -> builtins.bytes:
""" """
Returns the bytes in the file. Returns the bytes in the file.
""" """

View File

@ -45,7 +45,7 @@ def nonascii_srcdir(request, rootdir, sphinx_test_tempdir):
""")) """))
master_doc = srcdir / 'index.txt' master_doc = srcdir / 'index.txt'
master_doc.write_text(master_doc.text() + dedent(""" master_doc.write_text(master_doc.read_text() + dedent("""
.. toctree:: .. toctree::
%(test_name)s/%(test_name)s %(test_name)s/%(test_name)s

View File

@ -17,7 +17,7 @@ def test_build(app):
app.build() app.build()
# TODO: Use better checking of html content # TODO: Use better checking of html content
htmltext = (app.outdir / 'changes.html').text() htmltext = (app.outdir / 'changes.html').read_text()
assert 'New in version 0.6: Some funny stuff.' in htmltext assert 'New in version 0.6: Some funny stuff.' in htmltext
assert 'Changed in version 0.6: Even more funny stuff.' in htmltext assert 'Changed in version 0.6: Even more funny stuff.' in htmltext
assert 'Deprecated since version 0.6: Boring stuff.' in htmltext assert 'Deprecated since version 0.6: Boring stuff.' in htmltext

View File

@ -67,11 +67,11 @@ class EPUBElementTree:
@pytest.mark.sphinx('epub', testroot='basic') @pytest.mark.sphinx('epub', testroot='basic')
def test_build_epub(app): def test_build_epub(app):
app.build() app.build()
assert (app.outdir / 'mimetype').text() == 'application/epub+zip' assert (app.outdir / 'mimetype').read_text() == 'application/epub+zip'
assert (app.outdir / 'META-INF' / 'container.xml').exists() assert (app.outdir / 'META-INF' / 'container.xml').exists()
# toc.ncx # toc.ncx
toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').text()) toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').read_text())
assert toc.find("./ncx:docTitle/ncx:text").text == 'Python' assert toc.find("./ncx:docTitle/ncx:text").text == 'Python'
# toc.ncx / head # toc.ncx / head
@ -91,7 +91,7 @@ def test_build_epub(app):
assert navlabel.text == 'The basic Sphinx documentation for testing' assert navlabel.text == 'The basic Sphinx documentation for testing'
# content.opf # content.opf
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').text()) opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
# content.opf / metadata # content.opf / metadata
metadata = opf.find("./idpf:metadata") metadata = opf.find("./idpf:metadata")
@ -143,7 +143,7 @@ def test_build_epub(app):
assert reference.get('href') == 'index.xhtml' assert reference.get('href') == 'index.xhtml'
# nav.xhtml # nav.xhtml
nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').text()) nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').read_text())
assert nav.attrib == {'lang': 'en', assert nav.attrib == {'lang': 'en',
'{http://www.w3.org/XML/1998/namespace}lang': 'en'} '{http://www.w3.org/XML/1998/namespace}lang': 'en'}
assert nav.find("./xhtml:head/xhtml:title").text == 'Table of Contents' assert nav.find("./xhtml:head/xhtml:title").text == 'Table of Contents'
@ -163,7 +163,7 @@ def test_epub_cover(app):
app.build() app.build()
# content.opf / metadata # content.opf / metadata
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').text()) opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
cover_image = opf.find("./idpf:manifest/idpf:item[@href='%s']" % app.config.epub_cover[0]) cover_image = opf.find("./idpf:manifest/idpf:item[@href='%s']" % app.config.epub_cover[0])
cover = opf.find("./idpf:metadata/idpf:meta[@name='cover']") cover = opf.find("./idpf:metadata/idpf:meta[@name='cover']")
assert cover assert cover
@ -175,7 +175,7 @@ def test_nested_toc(app):
app.build() app.build()
# toc.ncx # toc.ncx
toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').bytes()) toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').read_bytes())
assert toc.find("./ncx:docTitle/ncx:text").text == 'Python' assert toc.find("./ncx:docTitle/ncx:text").text == 'Python'
# toc.ncx / navPoint # toc.ncx / navPoint
@ -205,7 +205,7 @@ def test_nested_toc(app):
anchor = elem.find("./xhtml:a") anchor = elem.find("./xhtml:a")
return (anchor.get('href'), anchor.text) return (anchor.get('href'), anchor.text)
nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').bytes()) nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').read_bytes())
toc = nav.findall("./xhtml:body/xhtml:nav/xhtml:ol/xhtml:li") toc = nav.findall("./xhtml:body/xhtml:nav/xhtml:ol/xhtml:li")
assert len(toc) == 4 assert len(toc) == 4
assert navinfo(toc[0]) == ('index.xhtml', assert navinfo(toc[0]) == ('index.xhtml',
@ -230,7 +230,7 @@ def test_escaped_toc(app):
app.build() app.build()
# toc.ncx # toc.ncx
toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').bytes()) toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').read_bytes())
assert toc.find("./ncx:docTitle/ncx:text").text == 'need <b>"escaped"</b> project' assert toc.find("./ncx:docTitle/ncx:text").text == 'need <b>"escaped"</b> project'
# toc.ncx / navPoint # toc.ncx / navPoint
@ -260,7 +260,7 @@ def test_escaped_toc(app):
anchor = elem.find("./xhtml:a") anchor = elem.find("./xhtml:a")
return (anchor.get('href'), anchor.text) return (anchor.get('href'), anchor.text)
nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').bytes()) nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').read_bytes())
toc = nav.findall("./xhtml:body/xhtml:nav/xhtml:ol/xhtml:li") toc = nav.findall("./xhtml:body/xhtml:nav/xhtml:ol/xhtml:li")
assert len(toc) == 4 assert len(toc) == 4
assert navinfo(toc[0]) == ('index.xhtml', assert navinfo(toc[0]) == ('index.xhtml',
@ -286,7 +286,7 @@ def test_epub_writing_mode(app):
app.build() app.build()
# horizontal / page-progression-direction # horizontal / page-progression-direction
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').text()) opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
assert opf.find("./idpf:spine").get('page-progression-direction') == 'ltr' assert opf.find("./idpf:spine").get('page-progression-direction') == 'ltr'
# horizontal / ibooks:scroll-axis # horizontal / ibooks:scroll-axis
@ -294,7 +294,7 @@ def test_epub_writing_mode(app):
assert metadata.find("./idpf:meta[@property='ibooks:scroll-axis']").text == 'vertical' assert metadata.find("./idpf:meta[@property='ibooks:scroll-axis']").text == 'vertical'
# horizontal / writing-mode (CSS) # horizontal / writing-mode (CSS)
css = (app.outdir / '_static' / 'epub.css').text() css = (app.outdir / '_static' / 'epub.css').read_text()
assert 'writing-mode: horizontal-tb;' in css assert 'writing-mode: horizontal-tb;' in css
# vertical # vertical
@ -303,7 +303,7 @@ def test_epub_writing_mode(app):
app.build() app.build()
# vertical / page-progression-direction # vertical / page-progression-direction
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').text()) opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
assert opf.find("./idpf:spine").get('page-progression-direction') == 'rtl' assert opf.find("./idpf:spine").get('page-progression-direction') == 'rtl'
# vertical / ibooks:scroll-axis # vertical / ibooks:scroll-axis
@ -311,7 +311,7 @@ def test_epub_writing_mode(app):
assert metadata.find("./idpf:meta[@property='ibooks:scroll-axis']").text == 'horizontal' assert metadata.find("./idpf:meta[@property='ibooks:scroll-axis']").text == 'horizontal'
# vertical / writing-mode (CSS) # vertical / writing-mode (CSS)
css = (app.outdir / '_static' / 'epub.css').text() css = (app.outdir / '_static' / 'epub.css').read_text()
assert 'writing-mode: vertical-rl;' in css assert 'writing-mode: vertical-rl;' in css
@ -319,7 +319,7 @@ def test_epub_writing_mode(app):
def test_epub_anchor_id(app): def test_epub_anchor_id(app):
app.build() app.build()
html = (app.outdir / 'index.xhtml').text() html = (app.outdir / 'index.xhtml').read_text()
assert '<p id="std-setting-STATICFILES_FINDERS">blah blah blah</p>' in html assert '<p id="std-setting-STATICFILES_FINDERS">blah blah blah</p>' in html
assert '<span id="std-setting-STATICFILES_SECTION"></span><h1>blah blah blah</h1>' in html assert '<span id="std-setting-STATICFILES_SECTION"></span><h1>blah blah blah</h1>' in html
assert 'see <a class="reference internal" href="#std-setting-STATICFILES_FINDERS">' in html assert 'see <a class="reference internal" href="#std-setting-STATICFILES_FINDERS">' in html
@ -330,7 +330,7 @@ def test_epub_assets(app):
app.builder.build_all() app.builder.build_all()
# epub_sytlesheets (same as html_css_files) # epub_sytlesheets (same as html_css_files)
content = (app.outdir / 'index.xhtml').text() content = (app.outdir / 'index.xhtml').read_text()
assert ('<link rel="stylesheet" type="text/css" href="_static/css/style.css" />' assert ('<link rel="stylesheet" type="text/css" href="_static/css/style.css" />'
in content) in content)
assert ('<link media="print" rel="stylesheet" title="title" type="text/css" ' assert ('<link media="print" rel="stylesheet" title="title" type="text/css" '
@ -343,7 +343,7 @@ def test_epub_css_files(app):
app.builder.build_all() app.builder.build_all()
# epub_css_files # epub_css_files
content = (app.outdir / 'index.xhtml').text() content = (app.outdir / 'index.xhtml').read_text()
assert '<link rel="stylesheet" type="text/css" href="_static/css/epub.css" />' in content assert '<link rel="stylesheet" type="text/css" href="_static/css/epub.css" />' in content
# files in html_css_files are not outputed # files in html_css_files are not outputed
@ -360,7 +360,7 @@ def test_html_download_role(app, status, warning):
app.build() app.build()
assert not (app.outdir / '_downloads' / 'dummy.dat').exists() assert not (app.outdir / '_downloads' / 'dummy.dat').exists()
content = (app.outdir / 'index.xhtml').text() content = (app.outdir / 'index.xhtml').read_text()
assert ('<li><p><code class="xref download docutils literal notranslate">' assert ('<li><p><code class="xref download docutils literal notranslate">'
'<span class="pre">dummy.dat</span></code></p></li>' in content) '<span class="pre">dummy.dat</span></code></p></li>' in content)
assert ('<li><p><code class="xref download docutils literal notranslate">' assert ('<li><p><code class="xref download docutils literal notranslate">'

View File

@ -31,7 +31,7 @@ def test_build_gettext(app):
assert (app.outdir / 'subdir.pot').isfile() assert (app.outdir / 'subdir.pot').isfile()
# regression test for issue #960 # regression test for issue #960
catalog = (app.outdir / 'markup.pot').text() catalog = (app.outdir / 'markup.pot').read_text()
assert 'msgid "something, something else, something more"' in catalog assert 'msgid "something, something else, something more"' in catalog
@ -84,7 +84,7 @@ def test_gettext_index_entries(app):
return m.groups()[0] return m.groups()[0]
return None return None
pot = (app.outdir / 'index_entries.pot').text() pot = (app.outdir / 'index_entries.pot').read_text()
msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f] msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f]
expected_msgids = [ expected_msgids = [
@ -133,7 +133,7 @@ def test_gettext_disable_index_entries(app):
return m.groups()[0] return m.groups()[0]
return None return None
pot = (app.outdir / 'index_entries.pot').text() pot = (app.outdir / 'index_entries.pot').read_text()
msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f] msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f]
expected_msgids = [ expected_msgids = [
@ -156,7 +156,7 @@ def test_gettext_template(app):
app.builder.build_all() app.builder.build_all()
assert (app.outdir / 'sphinx.pot').isfile() assert (app.outdir / 'sphinx.pot').isfile()
result = (app.outdir / 'sphinx.pot').text() result = (app.outdir / 'sphinx.pot').read_text()
assert "Welcome" in result assert "Welcome" in result
assert "Sphinx %(version)s" in result assert "Sphinx %(version)s" in result
@ -166,7 +166,7 @@ def test_gettext_template_msgid_order_in_sphinxpot(app):
app.builder.build_all() app.builder.build_all()
assert (app.outdir / 'sphinx.pot').isfile() assert (app.outdir / 'sphinx.pot').isfile()
result = (app.outdir / 'sphinx.pot').text() result = (app.outdir / 'sphinx.pot').read_text()
assert re.search( assert re.search(
('msgid "Template 1".*' ('msgid "Template 1".*'
'msgid "This is Template 1\\.".*' 'msgid "This is Template 1\\.".*'

View File

@ -426,7 +426,7 @@ def test_html_download(app):
app.build() app.build()
# subdir/includes.html # subdir/includes.html
result = (app.outdir / 'subdir' / 'includes.html').text() result = (app.outdir / 'subdir' / 'includes.html').read_text()
pattern = ('<a class="reference download internal" download="" ' pattern = ('<a class="reference download internal" download="" '
'href="../(_downloads/.*/img.png)">') 'href="../(_downloads/.*/img.png)">')
matched = re.search(pattern, result) matched = re.search(pattern, result)
@ -435,7 +435,7 @@ def test_html_download(app):
filename = matched.group(1) filename = matched.group(1)
# includes.html # includes.html
result = (app.outdir / 'includes.html').text() result = (app.outdir / 'includes.html').read_text()
pattern = ('<a class="reference download internal" download="" ' pattern = ('<a class="reference download internal" download="" '
'href="(_downloads/.*/img.png)">') 'href="(_downloads/.*/img.png)">')
matched = re.search(pattern, result) matched = re.search(pattern, result)
@ -454,7 +454,7 @@ def test_html_download_role(app, status, warning):
digest_another = md5(b'another/dummy.dat').hexdigest() digest_another = md5(b'another/dummy.dat').hexdigest()
assert (app.outdir / '_downloads' / digest_another / 'dummy.dat').exists() assert (app.outdir / '_downloads' / digest_another / 'dummy.dat').exists()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert (('<li><p><a class="reference download internal" download="" ' assert (('<li><p><a class="reference download internal" download="" '
'href="_downloads/%s/dummy.dat">' 'href="_downloads/%s/dummy.dat">'
'<code class="xref download docutils literal notranslate">' '<code class="xref download docutils literal notranslate">'
@ -646,7 +646,7 @@ def test_numfig_disabled(app, cached_etree_parse, fname, expect):
def test_numfig_without_numbered_toctree_warn(app, warning): def test_numfig_without_numbered_toctree_warn(app, warning):
app.build() app.build()
# remove :numbered: option # remove :numbered: option
index = (app.srcdir / 'index.rst').text() index = (app.srcdir / 'index.rst').read_text()
index = re.sub(':numbered:.*', '', index) index = re.sub(':numbered:.*', '', index)
(app.srcdir / 'index.rst').write_text(index) (app.srcdir / 'index.rst').write_text(index)
app.builder.build_all() app.builder.build_all()
@ -746,7 +746,7 @@ def test_numfig_without_numbered_toctree_warn(app, warning):
confoverrides={'numfig': True}) confoverrides={'numfig': True})
def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect): def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect):
# remove :numbered: option # remove :numbered: option
index = (app.srcdir / 'index.rst').text() index = (app.srcdir / 'index.rst').read_text()
index = re.sub(':numbered:.*', '', index) index = re.sub(':numbered:.*', '', index)
(app.srcdir / 'index.rst').write_text(index) (app.srcdir / 'index.rst').write_text(index)
@ -1189,7 +1189,7 @@ def test_html_assets(app):
assert not (app.outdir / '_static' / '.htaccess').exists() assert not (app.outdir / '_static' / '.htaccess').exists()
assert not (app.outdir / '_static' / '.htpasswd').exists() assert not (app.outdir / '_static' / '.htpasswd').exists()
assert (app.outdir / '_static' / 'API.html').exists() assert (app.outdir / '_static' / 'API.html').exists()
assert (app.outdir / '_static' / 'API.html').text() == 'Sphinx-1.4.4' assert (app.outdir / '_static' / 'API.html').read_text() == 'Sphinx-1.4.4'
assert (app.outdir / '_static' / 'css' / 'style.css').exists() assert (app.outdir / '_static' / 'css' / 'style.css').exists()
assert (app.outdir / '_static' / 'js' / 'custom.js').exists() assert (app.outdir / '_static' / 'js' / 'custom.js').exists()
assert (app.outdir / '_static' / 'rimg.png').exists() assert (app.outdir / '_static' / 'rimg.png').exists()
@ -1210,7 +1210,7 @@ def test_html_assets(app):
assert not (app.outdir / 'subdir' / '.htpasswd').exists() assert not (app.outdir / 'subdir' / '.htpasswd').exists()
# html_css_files # html_css_files
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert '<link rel="stylesheet" type="text/css" href="_static/css/style.css" />' in content assert '<link rel="stylesheet" type="text/css" href="_static/css/style.css" />' in content
assert ('<link media="print" rel="stylesheet" title="title" type="text/css" ' assert ('<link media="print" rel="stylesheet" title="title" type="text/css" '
'href="https://example.com/custom.css" />' in content) 'href="https://example.com/custom.css" />' in content)
@ -1249,7 +1249,7 @@ def test_html_sourcelink_suffix_empty(app):
def test_html_entity(app): def test_html_entity(app):
app.builder.build_all() app.builder.build_all()
valid_entities = {'amp', 'lt', 'gt', 'quot', 'apos'} valid_entities = {'amp', 'lt', 'gt', 'quot', 'apos'}
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
for entity in re.findall(r'&([a-z]+);', content, re.M): for entity in re.findall(r'&([a-z]+);', content, re.M):
assert entity not in valid_entities assert entity not in valid_entities
@ -1284,7 +1284,7 @@ def test_html_inventory(app):
@pytest.mark.sphinx('html', testroot='images', confoverrides={'html_sourcelink_suffix': ''}) @pytest.mark.sphinx('html', testroot='images', confoverrides={'html_sourcelink_suffix': ''})
def test_html_anchor_for_figure(app): def test_html_anchor_for_figure(app):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert ('<p class="caption"><span class="caption-text">The caption of pic</span>' assert ('<p class="caption"><span class="caption-text">The caption of pic</span>'
'<a class="headerlink" href="#id1" title="Permalink to this image">¶</a></p>' '<a class="headerlink" href="#id1" title="Permalink to this image">¶</a></p>'
in content) in content)
@ -1293,7 +1293,7 @@ def test_html_anchor_for_figure(app):
@pytest.mark.sphinx('html', testroot='directives-raw') @pytest.mark.sphinx('html', testroot='directives-raw')
def test_html_raw_directive(app, status, warning): def test_html_raw_directive(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
# standard case # standard case
assert 'standalone raw directive (HTML)' in result assert 'standalone raw directive (HTML)' in result
@ -1337,7 +1337,7 @@ def test_alternate_stylesheets(app, cached_etree_parse, fname, expect):
@pytest.mark.sphinx('html', testroot='html_style') @pytest.mark.sphinx('html', testroot='html_style')
def test_html_style(app, status, warning): def test_html_style(app, status, warning):
app.build() app.build()
result = (app.outdir / 'index.html').text() result = (app.outdir / 'index.html').read_text()
assert '<link rel="stylesheet" href="_static/default.css" type="text/css" />' in result assert '<link rel="stylesheet" href="_static/default.css" type="text/css" />' in result
assert ('<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />' assert ('<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />'
not in result) not in result)
@ -1347,7 +1347,7 @@ def test_html_style(app, status, warning):
def test_html_remote_images(app, status, warning): def test_html_remote_images(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert ('<img alt="https://www.python.org/static/img/python-logo.png" ' assert ('<img alt="https://www.python.org/static/img/python-logo.png" '
'src="https://www.python.org/static/img/python-logo.png" />' in result) 'src="https://www.python.org/static/img/python-logo.png" />' in result)
assert not (app.outdir / 'python-logo.png').exists() assert not (app.outdir / 'python-logo.png').exists()
@ -1359,7 +1359,7 @@ def test_html_sidebar(app, status, warning):
# default for alabaster # default for alabaster
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert ('<div class="sphinxsidebar" role="navigation" ' assert ('<div class="sphinxsidebar" role="navigation" '
'aria-label="main navigation">' in result) 'aria-label="main navigation">' in result)
assert '<h1 class="logo"><a href="#">Python</a></h1>' in result assert '<h1 class="logo"><a href="#">Python</a></h1>' in result
@ -1374,7 +1374,7 @@ def test_html_sidebar(app, status, warning):
# only relations.html # only relations.html
app.config.html_sidebars = {'**': ['relations.html']} app.config.html_sidebars = {'**': ['relations.html']}
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert ('<div class="sphinxsidebar" role="navigation" ' assert ('<div class="sphinxsidebar" role="navigation" '
'aria-label="main navigation">' in result) 'aria-label="main navigation">' in result)
assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result
@ -1388,7 +1388,7 @@ def test_html_sidebar(app, status, warning):
# no sidebars # no sidebars
app.config.html_sidebars = {'**': []} app.config.html_sidebars = {'**': []}
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert ('<div class="sphinxsidebar" role="navigation" ' assert ('<div class="sphinxsidebar" role="navigation" '
'aria-label="main navigation">' not in result) 'aria-label="main navigation">' not in result)
assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result
@ -1419,10 +1419,10 @@ def test_html_manpage(app, cached_etree_parse, fname, expect):
def test_html_baseurl(app, status, warning): def test_html_baseurl(app, status, warning):
app.build() app.build()
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert '<link rel="canonical" href="https://example.com/index.html" />' in result assert '<link rel="canonical" href="https://example.com/index.html" />' in result
result = (app.outdir / 'qux' / 'index.html').text(encoding='utf8') result = (app.outdir / 'qux' / 'index.html').read_text(encoding='utf8')
assert '<link rel="canonical" href="https://example.com/qux/index.html" />' in result assert '<link rel="canonical" href="https://example.com/qux/index.html" />' in result
@ -1432,10 +1432,10 @@ def test_html_baseurl(app, status, warning):
def test_html_baseurl_and_html_file_suffix(app, status, warning): def test_html_baseurl_and_html_file_suffix(app, status, warning):
app.build() app.build()
result = (app.outdir / 'index.htm').text(encoding='utf8') result = (app.outdir / 'index.htm').read_text(encoding='utf8')
assert '<link rel="canonical" href="https://example.com/subdir/index.htm" />' in result assert '<link rel="canonical" href="https://example.com/subdir/index.htm" />' in result
result = (app.outdir / 'qux' / 'index.htm').text(encoding='utf8') result = (app.outdir / 'qux' / 'index.htm').read_text(encoding='utf8')
assert '<link rel="canonical" href="https://example.com/subdir/qux/index.htm" />' in result assert '<link rel="canonical" href="https://example.com/subdir/qux/index.htm" />' in result

View File

@ -113,7 +113,7 @@ def test_build_latex_doc(app, status, warning, engine, docclass):
@pytest.mark.sphinx('latex') @pytest.mark.sphinx('latex')
def test_writer(app, status, warning): def test_writer(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'sphinxtests.tex').text(encoding='utf8') result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
assert ('\\begin{sphinxfigure-in-table}\n\\centering\n\\capstart\n' assert ('\\begin{sphinxfigure-in-table}\n\\centering\n\\capstart\n'
'\\noindent\\sphinxincludegraphics{{img}.png}\n' '\\noindent\\sphinxincludegraphics{{img}.png}\n'
@ -156,7 +156,7 @@ def test_latex_warnings(app, status, warning):
@pytest.mark.sphinx('latex', testroot='basic') @pytest.mark.sphinx('latex', testroot='basic')
def test_latex_basic(app, status, warning): def test_latex_basic(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8') result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -168,7 +168,7 @@ def test_latex_basic(app, status, warning):
@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'zh'}) @pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'zh'})
def test_latex_additional_settings_for_language_code(app, status, warning): def test_latex_additional_settings_for_language_code(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8') result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -178,7 +178,7 @@ def test_latex_additional_settings_for_language_code(app, status, warning):
@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'el'}) @pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'el'})
def test_latex_additional_settings_for_greek(app, status, warning): def test_latex_additional_settings_for_greek(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8') result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -189,7 +189,7 @@ def test_latex_additional_settings_for_greek(app, status, warning):
@pytest.mark.sphinx('latex', testroot='latex-title') @pytest.mark.sphinx('latex', testroot='latex-title')
def test_latex_title_after_admonitions(app, status, warning): def test_latex_title_after_admonitions(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8') result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -200,7 +200,7 @@ def test_latex_title_after_admonitions(app, status, warning):
confoverrides={'release': '1.0'}) confoverrides={'release': '1.0'})
def test_latex_release(app, status, warning): def test_latex_release(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8') result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -212,7 +212,7 @@ def test_latex_release(app, status, warning):
confoverrides={'numfig': True}) confoverrides={'numfig': True})
def test_numref(app, status, warning): def test_numref(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -238,7 +238,7 @@ def test_numref(app, status, warning):
'\\nameref{\\detokenize{foo:foo}}}') in result '\\nameref{\\detokenize{foo:foo}}}') in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table }}' in result assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table }}' in result
@ -254,7 +254,7 @@ def test_numref(app, status, warning):
'section': 'SECTION-%s'}}) 'section': 'SECTION-%s'}})
def test_numref_with_prefix1(app, status, warning): def test_numref_with_prefix1(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -286,7 +286,7 @@ def test_numref_with_prefix1(app, status, warning):
'\\nameref{\\detokenize{foo:foo}}}') in result '\\nameref{\\detokenize{foo:foo}}}') in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result
@ -302,7 +302,7 @@ def test_numref_with_prefix1(app, status, warning):
'section': 'SECTION_%s_'}}) 'section': 'SECTION_%s_'}})
def test_numref_with_prefix2(app, status, warning): def test_numref_with_prefix2(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -328,7 +328,7 @@ def test_numref_with_prefix2(app, status, warning):
'\\nameref{\\detokenize{foo:foo}}}') in result '\\nameref{\\detokenize{foo:foo}}}') in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
assert r'\def\fnum@figure{\figurename\thefigure{}.}' in result assert r'\def\fnum@figure{\figurename\thefigure{}.}' in result
@ -342,7 +342,7 @@ def test_numref_with_prefix2(app, status, warning):
confoverrides={'numfig': True, 'language': 'ja'}) confoverrides={'numfig': True, 'language': 'ja'})
def test_numref_with_language_ja(app, status, warning): def test_numref_with_language_ja(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -368,7 +368,7 @@ def test_numref_with_language_ja(app, status, warning):
'\\nameref{\\detokenize{foo:foo}}}') in result '\\nameref{\\detokenize{foo:foo}}}') in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert '\\@iden{\\renewcommand{\\figurename}{図 }}' in result assert '\\@iden{\\renewcommand{\\figurename}{図 }}' in result
assert '\\@iden{\\renewcommand{\\tablename}{表 }}' in result assert '\\@iden{\\renewcommand{\\tablename}{表 }}' in result
@ -379,10 +379,10 @@ def test_numref_with_language_ja(app, status, warning):
def test_latex_obey_numfig_is_false(app, status, warning): def test_latex_obey_numfig_is_false(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8') result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage{sphinx}' in result assert '\\usepackage{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8') result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage{sphinx}' in result assert '\\usepackage{sphinx}' in result
@ -392,10 +392,10 @@ def test_latex_obey_numfig_is_false(app, status, warning):
def test_latex_obey_numfig_secnum_depth_is_zero(app, status, warning): def test_latex_obey_numfig_secnum_depth_is_zero(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8') result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8') result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
@ -405,10 +405,10 @@ def test_latex_obey_numfig_secnum_depth_is_zero(app, status, warning):
def test_latex_obey_numfig_secnum_depth_is_two(app, status, warning): def test_latex_obey_numfig_secnum_depth_is_two(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8') result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=2,mathnumfig]{sphinx}' in result assert '\\usepackage[,numfigreset=2,mathnumfig]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8') result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=3,mathnumfig]{sphinx}' in result assert '\\usepackage[,numfigreset=3,mathnumfig]{sphinx}' in result
@ -418,10 +418,10 @@ def test_latex_obey_numfig_secnum_depth_is_two(app, status, warning):
def test_latex_obey_numfig_but_math_numfig_false(app, status, warning): def test_latex_obey_numfig_but_math_numfig_false(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8') result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=1]{sphinx}' in result assert '\\usepackage[,numfigreset=1]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8') result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=2]{sphinx}' in result assert '\\usepackage[,numfigreset=2]{sphinx}' in result
@ -430,7 +430,7 @@ def test_latex_add_latex_package(app, status, warning):
app.add_latex_package('foo') app.add_latex_package('foo')
app.add_latex_package('bar', 'baz') app.add_latex_package('bar', 'baz')
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8') result = (app.outdir / 'test.tex').read_text(encoding='utf8')
assert '\\usepackage{foo}' in result assert '\\usepackage{foo}' in result
assert '\\usepackage[baz]{bar}' in result assert '\\usepackage[baz]{bar}' in result
@ -438,7 +438,7 @@ def test_latex_add_latex_package(app, status, warning):
@pytest.mark.sphinx('latex', testroot='latex-babel') @pytest.mark.sphinx('latex', testroot='latex-babel')
def test_babel_with_no_language_settings(app, status, warning): def test_babel_with_no_language_settings(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -451,7 +451,7 @@ def test_babel_with_no_language_settings(app, status, warning):
assert '\\shorthandoff' not in result assert '\\shorthandoff' not in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{page}' in result assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
@ -463,7 +463,7 @@ def test_babel_with_no_language_settings(app, status, warning):
confoverrides={'language': 'de'}) confoverrides={'language': 'de'})
def test_babel_with_language_de(app, status, warning): def test_babel_with_language_de(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -476,7 +476,7 @@ def test_babel_with_language_de(app, status, warning):
assert '\\shorthandoff{"}' in result assert '\\shorthandoff{"}' in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{Seite}' in result assert r'\def\pageautorefname{Seite}' in result
assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
@ -488,7 +488,7 @@ def test_babel_with_language_de(app, status, warning):
confoverrides={'language': 'ru'}) confoverrides={'language': 'ru'})
def test_babel_with_language_ru(app, status, warning): def test_babel_with_language_ru(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -501,7 +501,7 @@ def test_babel_with_language_ru(app, status, warning):
assert '\\shorthandoff{"}' in result assert '\\shorthandoff{"}' in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{страница}' in result assert r'\def\pageautorefname{страница}' in result
assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.\@{} }}' in result
@ -513,7 +513,7 @@ def test_babel_with_language_ru(app, status, warning):
confoverrides={'language': 'tr'}) confoverrides={'language': 'tr'})
def test_babel_with_language_tr(app, status, warning): def test_babel_with_language_tr(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -526,7 +526,7 @@ def test_babel_with_language_tr(app, status, warning):
assert '\\shorthandoff{=}' in result assert '\\shorthandoff{=}' in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{sayfa}' in result assert r'\def\pageautorefname{sayfa}' in result
assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.\@{} }}' in result
@ -538,7 +538,7 @@ def test_babel_with_language_tr(app, status, warning):
confoverrides={'language': 'ja'}) confoverrides={'language': 'ja'})
def test_babel_with_language_ja(app, status, warning): def test_babel_with_language_ja(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -550,7 +550,7 @@ def test_babel_with_language_ja(app, status, warning):
assert '\\shorthandoff' not in result assert '\\shorthandoff' not in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{ページ}' in result assert r'\def\pageautorefname{ページ}' in result
assert '\\@iden{\\renewcommand{\\figurename}{Fig.\\@{} }}' in result assert '\\@iden{\\renewcommand{\\figurename}{Fig.\\@{} }}' in result
@ -562,7 +562,7 @@ def test_babel_with_language_ja(app, status, warning):
confoverrides={'language': 'unknown'}) confoverrides={'language': 'unknown'})
def test_babel_with_unknown_language(app, status, warning): def test_babel_with_unknown_language(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -577,7 +577,7 @@ def test_babel_with_unknown_language(app, status, warning):
assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue() assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue()
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{page}' in result assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
@ -589,7 +589,7 @@ def test_babel_with_unknown_language(app, status, warning):
confoverrides={'language': 'de', 'latex_engine': 'lualatex'}) confoverrides={'language': 'de', 'latex_engine': 'lualatex'})
def test_polyglossia_with_language_de(app, status, warning): def test_polyglossia_with_language_de(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -603,7 +603,7 @@ def test_polyglossia_with_language_de(app, status, warning):
assert '\\shorthandoff' not in result assert '\\shorthandoff' not in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{Seite}' in result assert r'\def\pageautorefname{Seite}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
@ -615,7 +615,7 @@ def test_polyglossia_with_language_de(app, status, warning):
confoverrides={'language': 'de-1901', 'latex_engine': 'lualatex'}) confoverrides={'language': 'de-1901', 'latex_engine': 'lualatex'})
def test_polyglossia_with_language_de_1901(app, status, warning): def test_polyglossia_with_language_de_1901(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -629,7 +629,7 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
assert '\\shorthandoff' not in result assert '\\shorthandoff' not in result
# sphinxmessages.sty # sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result) print(result)
assert r'\def\pageautorefname{page}' in result assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
@ -639,7 +639,7 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
@pytest.mark.sphinx('latex') @pytest.mark.sphinx('latex')
def test_footnote(app, status, warning): def test_footnote(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'sphinxtests.tex').text(encoding='utf8') result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -666,7 +666,7 @@ def test_footnote(app, status, warning):
@pytest.mark.sphinx('latex', testroot='footnotes') @pytest.mark.sphinx('latex', testroot='footnotes')
def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning): def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -707,7 +707,7 @@ def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning):
confoverrides={'latex_show_urls': 'inline'}) confoverrides={'latex_show_urls': 'inline'})
def test_latex_show_urls_is_inline(app, status, warning): def test_latex_show_urls_is_inline(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -752,7 +752,7 @@ def test_latex_show_urls_is_inline(app, status, warning):
confoverrides={'latex_show_urls': 'footnote'}) confoverrides={'latex_show_urls': 'footnote'})
def test_latex_show_urls_is_footnote(app, status, warning): def test_latex_show_urls_is_footnote(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -806,7 +806,7 @@ def test_latex_show_urls_is_footnote(app, status, warning):
confoverrides={'latex_show_urls': 'no'}) confoverrides={'latex_show_urls': 'no'})
def test_latex_show_urls_is_no(app, status, warning): def test_latex_show_urls_is_no(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -856,7 +856,7 @@ def test_latex_show_urls_footnote_and_substitutions(app, status, warning):
@pytest.mark.sphinx('latex', testroot='image-in-section') @pytest.mark.sphinx('latex', testroot='image-in-section')
def test_image_in_section(app, status, warning): def test_image_in_section(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -882,7 +882,7 @@ def test_latex_logo_if_not_found(app, status, warning):
@pytest.mark.sphinx('latex', testroot='toctree-maxdepth') @pytest.mark.sphinx('latex', testroot='toctree-maxdepth')
def test_toctree_maxdepth_manual(app, status, warning): def test_toctree_maxdepth_manual(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -899,7 +899,7 @@ def test_toctree_maxdepth_manual(app, status, warning):
]}) ]})
def test_toctree_maxdepth_howto(app, status, warning): def test_toctree_maxdepth_howto(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -913,7 +913,7 @@ def test_toctree_maxdepth_howto(app, status, warning):
confoverrides={'master_doc': 'foo'}) confoverrides={'master_doc': 'foo'})
def test_toctree_not_found(app, status, warning): def test_toctree_not_found(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -927,7 +927,7 @@ def test_toctree_not_found(app, status, warning):
confoverrides={'master_doc': 'bar'}) confoverrides={'master_doc': 'bar'})
def test_toctree_without_maxdepth(app, status, warning): def test_toctree_without_maxdepth(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -940,7 +940,7 @@ def test_toctree_without_maxdepth(app, status, warning):
confoverrides={'master_doc': 'qux'}) confoverrides={'master_doc': 'qux'})
def test_toctree_with_deeper_maxdepth(app, status, warning): def test_toctree_with_deeper_maxdepth(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -953,7 +953,7 @@ def test_toctree_with_deeper_maxdepth(app, status, warning):
confoverrides={'latex_toplevel_sectioning': None}) confoverrides={'latex_toplevel_sectioning': None})
def test_latex_toplevel_sectioning_is_None(app, status, warning): def test_latex_toplevel_sectioning_is_None(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -965,7 +965,7 @@ def test_latex_toplevel_sectioning_is_None(app, status, warning):
confoverrides={'latex_toplevel_sectioning': 'part'}) confoverrides={'latex_toplevel_sectioning': 'part'})
def test_latex_toplevel_sectioning_is_part(app, status, warning): def test_latex_toplevel_sectioning_is_part(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -983,7 +983,7 @@ def test_latex_toplevel_sectioning_is_part(app, status, warning):
]}) ]})
def test_latex_toplevel_sectioning_is_part_with_howto(app, status, warning): def test_latex_toplevel_sectioning_is_part_with_howto(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -997,7 +997,7 @@ def test_latex_toplevel_sectioning_is_part_with_howto(app, status, warning):
confoverrides={'latex_toplevel_sectioning': 'chapter'}) confoverrides={'latex_toplevel_sectioning': 'chapter'})
def test_latex_toplevel_sectioning_is_chapter(app, status, warning): def test_latex_toplevel_sectioning_is_chapter(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -1013,7 +1013,7 @@ def test_latex_toplevel_sectioning_is_chapter(app, status, warning):
]}) ]})
def test_latex_toplevel_sectioning_is_chapter_with_howto(app, status, warning): def test_latex_toplevel_sectioning_is_chapter_with_howto(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -1025,7 +1025,7 @@ def test_latex_toplevel_sectioning_is_chapter_with_howto(app, status, warning):
confoverrides={'latex_toplevel_sectioning': 'section'}) confoverrides={'latex_toplevel_sectioning': 'section'})
def test_latex_toplevel_sectioning_is_section(app, status, warning): def test_latex_toplevel_sectioning_is_section(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -1036,7 +1036,7 @@ def test_latex_toplevel_sectioning_is_section(app, status, warning):
@pytest.mark.sphinx('latex', testroot='maxlistdepth') @pytest.mark.sphinx('latex', testroot='maxlistdepth')
def test_maxlistdepth_at_ten(app, status, warning): def test_maxlistdepth_at_ten(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
@ -1049,14 +1049,14 @@ def test_maxlistdepth_at_ten(app, status, warning):
@pytest.mark.test_params(shared_result='latex-table') @pytest.mark.test_params(shared_result='latex-table')
def test_latex_table_tabulars(app, status, warning): def test_latex_table_tabulars(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
tables = {} tables = {}
for chap in re.split(r'\\(?:section|chapter){', result)[1:]: for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
sectname, content = chap.split('}', 1) sectname, content = chap.split('}', 1)
tables[sectname] = content.strip() tables[sectname] = content.strip()
def get_expected(name): def get_expected(name):
return (app.srcdir / 'expects' / (name + '.tex')).text().strip() return (app.srcdir / 'expects' / (name + '.tex')).read_text().strip()
# simple_table # simple_table
actual = tables['simple table'] actual = tables['simple table']
@ -1120,14 +1120,14 @@ def test_latex_table_tabulars(app, status, warning):
@pytest.mark.test_params(shared_result='latex-table') @pytest.mark.test_params(shared_result='latex-table')
def test_latex_table_longtable(app, status, warning): def test_latex_table_longtable(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
tables = {} tables = {}
for chap in re.split(r'\\(?:section|chapter){', result)[1:]: for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
sectname, content = chap.split('}', 1) sectname, content = chap.split('}', 1)
tables[sectname] = content.strip() tables[sectname] = content.strip()
def get_expected(name): def get_expected(name):
return (app.srcdir / 'expects' / (name + '.tex')).text().strip() return (app.srcdir / 'expects' / (name + '.tex')).read_text().strip()
# longtable # longtable
actual = tables['longtable'] actual = tables['longtable']
@ -1181,14 +1181,14 @@ def test_latex_table_longtable(app, status, warning):
@pytest.mark.test_params(shared_result='latex-table') @pytest.mark.test_params(shared_result='latex-table')
def test_latex_table_complex_tables(app, status, warning): def test_latex_table_complex_tables(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
tables = {} tables = {}
for chap in re.split(r'\\(?:section|renewcommand){', result)[1:]: for chap in re.split(r'\\(?:section|renewcommand){', result)[1:]:
sectname, content = chap.split('}', 1) sectname, content = chap.split('}', 1)
tables[sectname] = content.strip() tables[sectname] = content.strip()
def get_expected(name): def get_expected(name):
return (app.srcdir / 'expects' / (name + '.tex')).text().strip() return (app.srcdir / 'expects' / (name + '.tex')).read_text().strip()
# grid table # grid table
actual = tables['grid table'] actual = tables['grid table']
@ -1205,7 +1205,7 @@ def test_latex_table_complex_tables(app, status, warning):
confoverrides={'templates_path': ['_mytemplates/latex']}) confoverrides={'templates_path': ['_mytemplates/latex']})
def test_latex_table_custom_template_caseA(app, status, warning): def test_latex_table_custom_template_caseA(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert 'SALUT LES COPAINS' in result assert 'SALUT LES COPAINS' in result
@ -1213,7 +1213,7 @@ def test_latex_table_custom_template_caseA(app, status, warning):
confoverrides={'templates_path': ['_mytemplates']}) confoverrides={'templates_path': ['_mytemplates']})
def test_latex_table_custom_template_caseB(app, status, warning): def test_latex_table_custom_template_caseB(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert 'SALUT LES COPAINS' not in result assert 'SALUT LES COPAINS' not in result
@ -1221,14 +1221,14 @@ def test_latex_table_custom_template_caseB(app, status, warning):
@pytest.mark.test_params(shared_result='latex-table') @pytest.mark.test_params(shared_result='latex-table')
def test_latex_table_custom_template_caseC(app, status, warning): def test_latex_table_custom_template_caseC(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert 'SALUT LES COPAINS' not in result assert 'SALUT LES COPAINS' not in result
@pytest.mark.sphinx('latex', testroot='directives-raw') @pytest.mark.sphinx('latex', testroot='directives-raw')
def test_latex_raw_directive(app, status, warning): def test_latex_raw_directive(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
# standard case # standard case
assert 'standalone raw directive (HTML)' not in result assert 'standalone raw directive (HTML)' not in result
@ -1244,7 +1244,7 @@ def test_latex_raw_directive(app, status, warning):
def test_latex_images(app, status, warning): def test_latex_images(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
# images are copied # images are copied
assert '\\sphinxincludegraphics{{python-logo}.png}' in result assert '\\sphinxincludegraphics{{python-logo}.png}' in result
@ -1268,7 +1268,7 @@ def test_latex_images(app, status, warning):
def test_latex_index(app, status, warning): def test_latex_index(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert ('A \\index{famous@\\spxentry{famous}}famous ' assert ('A \\index{famous@\\spxentry{famous}}famous '
'\\index{equation@\\spxentry{equation}}equation:\n' in result) '\\index{equation@\\spxentry{equation}}equation:\n' in result)
assert ('\n\\index{Einstein@\\spxentry{Einstein}}' assert ('\n\\index{Einstein@\\spxentry{Einstein}}'
@ -1282,8 +1282,8 @@ def test_latex_index(app, status, warning):
def test_latex_equations(app, status, warning): def test_latex_equations(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
expected = (app.srcdir / 'expects' / 'latex-equations.tex').text().strip() expected = (app.srcdir / 'expects' / 'latex-equations.tex').read_text().strip()
assert expected in result assert expected in result
@ -1292,7 +1292,7 @@ def test_latex_equations(app, status, warning):
def test_latex_image_in_parsed_literal(app, status, warning): def test_latex_image_in_parsed_literal(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert ('{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}' assert ('{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}'
'{\\sphinxincludegraphics[height=2.00000cm]{{pic}.png}}' '{\\sphinxincludegraphics[height=2.00000cm]{{pic}.png}}'
'}AFTER') in result '}AFTER') in result
@ -1302,7 +1302,7 @@ def test_latex_image_in_parsed_literal(app, status, warning):
def test_latex_nested_enumerated_list(app, status, warning): def test_latex_nested_enumerated_list(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert ('\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n' assert ('\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n'
'\\setcounter{enumi}{4}\n' in result) '\\setcounter{enumi}{4}\n' in result)
assert ('\\sphinxsetlistlabels{\\alph}{enumii}{enumiii}{}{.}%\n' assert ('\\sphinxsetlistlabels{\\alph}{enumii}{enumiii}{}{.}%\n'
@ -1319,7 +1319,7 @@ def test_latex_nested_enumerated_list(app, status, warning):
def test_latex_thebibliography(app, status, warning): def test_latex_thebibliography(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(result) print(result)
assert ('\\begin{sphinxthebibliography}{AuthorYe}\n' assert ('\\begin{sphinxthebibliography}{AuthorYe}\n'
'\\bibitem[AuthorYear]{index:authoryear}\n' '\\bibitem[AuthorYear]{index:authoryear}\n'
@ -1332,7 +1332,7 @@ def test_latex_thebibliography(app, status, warning):
def test_latex_glossary(app, status, warning): def test_latex_glossary(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert ('\\item[{änhlich\\index{änhlich@\\spxentry{änhlich}|spxpagem}' assert ('\\item[{änhlich\\index{änhlich@\\spxentry{änhlich}|spxpagem}'
r'\phantomsection' r'\phantomsection'
r'\label{\detokenize{index:term-anhlich}}}] \leavevmode' in result) r'\label{\detokenize{index:term-anhlich}}}] \leavevmode' in result)
@ -1356,7 +1356,7 @@ def test_latex_glossary(app, status, warning):
def test_latex_labels(app, status, warning): def test_latex_labels(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
# figures # figures
assert (r'\caption{labeled figure}' assert (r'\caption{labeled figure}'
@ -1403,7 +1403,7 @@ def test_latex_labels(app, status, warning):
@pytest.mark.sphinx('latex', testroot='latex-figure-in-admonition') @pytest.mark.sphinx('latex', testroot='latex-figure-in-admonition')
def test_latex_figure_in_admonition(app, status, warning): def test_latex_figure_in_admonition(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert(r'\begin{figure}[H]' in result) assert(r'\begin{figure}[H]' in result)
@ -1433,7 +1433,7 @@ def test_includegraphics_oversized(app, status, warning):
@pytest.mark.sphinx('latex', testroot='index_on_title') @pytest.mark.sphinx('latex', testroot='index_on_title')
def test_index_on_title(app, status, warning): def test_index_on_title(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert ('\\chapter{Test for index in top level title}\n' assert ('\\chapter{Test for index in top level title}\n'
'\\label{\\detokenize{contents:test-for-index-in-top-level-title}}' '\\label{\\detokenize{contents:test-for-index-in-top-level-title}}'
'\\index{index@\\spxentry{index}}\n' '\\index{index@\\spxentry{index}}\n'
@ -1444,7 +1444,7 @@ def test_index_on_title(app, status, warning):
confoverrides={'latex_engine': 'pdflatex'}) confoverrides={'latex_engine': 'pdflatex'})
def test_texescape_for_non_unicode_supported_engine(app, status, warning): def test_texescape_for_non_unicode_supported_engine(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text() result = (app.outdir / 'python.tex').read_text()
print(result) print(result)
assert 'script small e: e' in result assert 'script small e: e' in result
assert 'double struck italic small i: i' in result assert 'double struck italic small i: i' in result
@ -1456,7 +1456,7 @@ def test_texescape_for_non_unicode_supported_engine(app, status, warning):
confoverrides={'latex_engine': 'xelatex'}) confoverrides={'latex_engine': 'xelatex'})
def test_texescape_for_unicode_supported_engine(app, status, warning): def test_texescape_for_unicode_supported_engine(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text() result = (app.outdir / 'python.tex').read_text()
print(result) print(result)
assert 'script small e: e' in result assert 'script small e: e' in result
assert 'double struck italic small i: i' in result assert 'double struck italic small i: i' in result
@ -1468,7 +1468,7 @@ def test_texescape_for_unicode_supported_engine(app, status, warning):
confoverrides={'latex_elements': {'extrapackages': r'\usepackage{foo}'}}) confoverrides={'latex_elements': {'extrapackages': r'\usepackage{foo}'}})
def test_latex_elements_extrapackages(app, status, warning): def test_latex_elements_extrapackages(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'test.tex').text() result = (app.outdir / 'test.tex').read_text()
assert r'\usepackage{foo}' in result assert r'\usepackage{foo}' in result

View File

@ -17,7 +17,7 @@ def test_defaults(app, status, warning):
app.builder.build_all() app.builder.build_all()
assert (app.outdir / 'output.txt').exists() assert (app.outdir / 'output.txt').exists()
content = (app.outdir / 'output.txt').text() content = (app.outdir / 'output.txt').read_text()
print(content) print(content)
# looking for '#top' and 'does-not-exist' not found should fail # looking for '#top' and 'does-not-exist' not found should fail
@ -44,7 +44,7 @@ def test_anchors_ignored(app, status, warning):
app.builder.build_all() app.builder.build_all()
assert (app.outdir / 'output.txt').exists() assert (app.outdir / 'output.txt').exists()
content = (app.outdir / 'output.txt').text() content = (app.outdir / 'output.txt').read_text()
# expect all ok when excluding #top # expect all ok when excluding #top
assert not content assert not content

View File

@ -19,7 +19,7 @@ def test_all(app, status, warning):
app.builder.build_all() app.builder.build_all()
assert (app.outdir / 'sphinxtests.1').exists() assert (app.outdir / 'sphinxtests.1').exists()
content = (app.outdir / 'sphinxtests.1').text() content = (app.outdir / 'sphinxtests.1').read_text()
assert r'\fBprint \fP\fIi\fP\fB\en\fP' in content assert r'\fBprint \fP\fIi\fP\fB\en\fP' in content
assert r'\fBmanpage\en\fP' in content assert r'\fBmanpage\en\fP' in content
@ -33,7 +33,7 @@ def test_all(app, status, warning):
@pytest.mark.sphinx('man', testroot='directive-code') @pytest.mark.sphinx('man', testroot='directive-code')
def test_captioned_code_block(app, status, warning): def test_captioned_code_block(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.1').text() content = (app.outdir / 'python.1').read_text()
assert ('.sp\n' assert ('.sp\n'
'caption \\fItest\\fP rb\n' 'caption \\fItest\\fP rb\n'
@ -64,5 +64,5 @@ def test_default_man_pages():
@pytest.mark.sphinx('man', testroot='markup-rubric') @pytest.mark.sphinx('man', testroot='markup-rubric')
def test_rubric(app, status, warning): def test_rubric(app, status, warning):
app.build() app.build()
content = (app.outdir / 'python.1').text() content = (app.outdir / 'python.1').read_text()
assert 'This is a rubric\n' in content assert 'This is a rubric\n' in content

View File

@ -49,7 +49,7 @@ def test_texinfo_warnings(app, status, warning):
def test_texinfo(app, status, warning): def test_texinfo(app, status, warning):
TexinfoTranslator.ignore_missing_images = True TexinfoTranslator.ignore_missing_images = True
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'sphinxtests.texi').text(encoding='utf8') result = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
assert ('@anchor{markup doc}@anchor{11}' assert ('@anchor{markup doc}@anchor{11}'
'@anchor{markup id1}@anchor{12}' '@anchor{markup id1}@anchor{12}'
'@anchor{markup testing-various-markup}@anchor{13}' in result) '@anchor{markup testing-various-markup}@anchor{13}' in result)
@ -70,7 +70,7 @@ def test_texinfo(app, status, warning):
def test_texinfo_rubric(app, status, warning): def test_texinfo_rubric(app, status, warning):
app.build() app.build()
output = (app.outdir / 'python.texi').text() output = (app.outdir / 'python.texi').read_text()
assert '@heading This is a rubric' in output assert '@heading This is a rubric' in output
assert '@heading This is a multiline rubric' in output assert '@heading This is a multiline rubric' in output
@ -79,7 +79,7 @@ def test_texinfo_rubric(app, status, warning):
def test_texinfo_citation(app, status, warning): def test_texinfo_citation(app, status, warning):
app.builder.build_all() app.builder.build_all()
output = (app.outdir / 'python.texi').text() output = (app.outdir / 'python.texi').read_text()
assert 'This is a citation ref; @ref{1,,[CITE1]} and @ref{2,,[CITE2]}.' in output assert 'This is a citation ref; @ref{1,,[CITE1]} and @ref{2,,[CITE2]}.' in output
assert ('@anchor{index cite1}@anchor{1}@w{(CITE1)} \n' assert ('@anchor{index cite1}@anchor{1}@w{(CITE1)} \n'
'This is a citation\n') in output 'This is a citation\n') in output

View File

@ -26,7 +26,7 @@ def with_text_app(*args, **kw):
@with_text_app() @with_text_app()
def test_maxwitdh_with_prefix(app, status, warning): def test_maxwitdh_with_prefix(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'maxwidth.txt').text() result = (app.outdir / 'maxwidth.txt').read_text()
lines = result.splitlines() lines = result.splitlines()
line_widths = [column_width(line) for line in lines] line_widths = [column_width(line) for line in lines]
@ -49,7 +49,7 @@ def test_maxwitdh_with_prefix(app, status, warning):
def test_lineblock(app, status, warning): def test_lineblock(app, status, warning):
# regression test for #1109: need empty line after line block # regression test for #1109: need empty line after line block
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'lineblock.txt').text() result = (app.outdir / 'lineblock.txt').read_text()
expect = ( expect = (
"* one\n" "* one\n"
"\n" "\n"
@ -64,7 +64,7 @@ def test_lineblock(app, status, warning):
@with_text_app() @with_text_app()
def test_nonascii_title_line(app, status, warning): def test_nonascii_title_line(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'nonascii_title.txt').text() result = (app.outdir / 'nonascii_title.txt').read_text()
expect_underline = '*********' expect_underline = '*********'
result_underline = result.splitlines()[1].strip() result_underline = result.splitlines()[1].strip()
assert expect_underline == result_underline assert expect_underline == result_underline
@ -73,7 +73,7 @@ def test_nonascii_title_line(app, status, warning):
@with_text_app() @with_text_app()
def test_nonascii_table(app, status, warning): def test_nonascii_table(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'nonascii_table.txt').text() result = (app.outdir / 'nonascii_table.txt').read_text()
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
line_widths = [column_width(line) for line in lines] line_widths = [column_width(line) for line in lines]
assert len(set(line_widths)) == 1 # same widths assert len(set(line_widths)) == 1 # same widths
@ -82,7 +82,7 @@ def test_nonascii_table(app, status, warning):
@with_text_app() @with_text_app()
def test_nonascii_maxwidth(app, status, warning): def test_nonascii_maxwidth(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'nonascii_maxwidth.txt').text() result = (app.outdir / 'nonascii_maxwidth.txt').read_text()
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
line_widths = [column_width(line) for line in lines] line_widths = [column_width(line) for line in lines]
assert max(line_widths) < MAXWIDTH assert max(line_widths) < MAXWIDTH
@ -126,7 +126,7 @@ def test_table_cell():
@with_text_app() @with_text_app()
def test_table_with_empty_cell(app, status, warning): def test_table_with_empty_cell(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'table.txt').text() result = (app.outdir / 'table.txt').read_text()
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
assert lines[0] == "+-------+-------+" assert lines[0] == "+-------+-------+"
assert lines[1] == "| XXX | XXX |" assert lines[1] == "| XXX | XXX |"
@ -140,7 +140,7 @@ def test_table_with_empty_cell(app, status, warning):
@with_text_app() @with_text_app()
def test_table_with_rowspan(app, status, warning): def test_table_with_rowspan(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'table_rowspan.txt').text() result = (app.outdir / 'table_rowspan.txt').read_text()
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
assert lines[0] == "+-------+-------+" assert lines[0] == "+-------+-------+"
assert lines[1] == "| XXXXXXXXX |" assert lines[1] == "| XXXXXXXXX |"
@ -154,7 +154,7 @@ def test_table_with_rowspan(app, status, warning):
@with_text_app() @with_text_app()
def test_table_with_colspan(app, status, warning): def test_table_with_colspan(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'table_colspan.txt').text() result = (app.outdir / 'table_colspan.txt').read_text()
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
assert lines[0] == "+-------+-------+" assert lines[0] == "+-------+-------+"
assert lines[1] == "| XXX | XXX |" assert lines[1] == "| XXX | XXX |"
@ -168,7 +168,7 @@ def test_table_with_colspan(app, status, warning):
@with_text_app() @with_text_app()
def test_table_with_colspan_left(app, status, warning): def test_table_with_colspan_left(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'table_colspan_left.txt').text() result = (app.outdir / 'table_colspan_left.txt').read_text()
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
assert lines[0] == "+-------+-------+" assert lines[0] == "+-------+-------+"
assert lines[1] == "| XXX | XXX |" assert lines[1] == "| XXX | XXX |"
@ -182,7 +182,7 @@ def test_table_with_colspan_left(app, status, warning):
@with_text_app() @with_text_app()
def test_table_with_colspan_and_rowspan(app, status, warning): def test_table_with_colspan_and_rowspan(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'table_colspan_and_rowspan.txt').text() result = (app.outdir / 'table_colspan_and_rowspan.txt').read_text()
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
assert result assert result
assert lines[0] == "+-------+-------+-------+" assert lines[0] == "+-------+-------+-------+"
@ -197,7 +197,7 @@ def test_table_with_colspan_and_rowspan(app, status, warning):
@with_text_app() @with_text_app()
def test_list_items_in_admonition(app, status, warning): def test_list_items_in_admonition(app, status, warning):
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'listitems.txt').text() result = (app.outdir / 'listitems.txt').read_text()
lines = [line.rstrip() for line in result.splitlines()] lines = [line.rstrip() for line in result.splitlines()]
assert lines[0] == "See also:" assert lines[0] == "See also:"
assert lines[1] == "" assert lines[1] == ""
@ -209,7 +209,7 @@ def test_list_items_in_admonition(app, status, warning):
@with_text_app() @with_text_app()
def test_secnums(app, status, warning): def test_secnums(app, status, warning):
app.builder.build_all() app.builder.build_all()
index = (app.outdir / 'index.txt').text(encoding='utf8') index = (app.outdir / 'index.txt').read_text(encoding='utf8')
lines = index.splitlines() lines = index.splitlines()
assert lines[0] == "* 1. Section A" assert lines[0] == "* 1. Section A"
assert lines[1] == "" assert lines[1] == ""
@ -218,7 +218,7 @@ def test_secnums(app, status, warning):
assert lines[4] == " * 2.1. Sub Ba" assert lines[4] == " * 2.1. Sub Ba"
assert lines[5] == "" assert lines[5] == ""
assert lines[6] == " * 2.2. Sub Bb" assert lines[6] == " * 2.2. Sub Bb"
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8') doc2 = (app.outdir / 'doc2.txt').read_text(encoding='utf8')
expect = ( expect = (
"2. Section B\n" "2. Section B\n"
"************\n" "************\n"
@ -235,7 +235,7 @@ def test_secnums(app, status, warning):
app.config.text_secnumber_suffix = " " app.config.text_secnumber_suffix = " "
app.builder.build_all() app.builder.build_all()
index = (app.outdir / 'index.txt').text(encoding='utf8') index = (app.outdir / 'index.txt').read_text(encoding='utf8')
lines = index.splitlines() lines = index.splitlines()
assert lines[0] == "* 1 Section A" assert lines[0] == "* 1 Section A"
assert lines[1] == "" assert lines[1] == ""
@ -244,7 +244,7 @@ def test_secnums(app, status, warning):
assert lines[4] == " * 2.1 Sub Ba" assert lines[4] == " * 2.1 Sub Ba"
assert lines[5] == "" assert lines[5] == ""
assert lines[6] == " * 2.2 Sub Bb" assert lines[6] == " * 2.2 Sub Bb"
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8') doc2 = (app.outdir / 'doc2.txt').read_text(encoding='utf8')
expect = ( expect = (
"2 Section B\n" "2 Section B\n"
"***********\n" "***********\n"
@ -261,7 +261,7 @@ def test_secnums(app, status, warning):
app.config.text_add_secnumbers = False app.config.text_add_secnumbers = False
app.builder.build_all() app.builder.build_all()
index = (app.outdir / 'index.txt').text(encoding='utf8') index = (app.outdir / 'index.txt').read_text(encoding='utf8')
lines = index.splitlines() lines = index.splitlines()
assert lines[0] == "* Section A" assert lines[0] == "* Section A"
assert lines[1] == "" assert lines[1] == ""
@ -270,7 +270,7 @@ def test_secnums(app, status, warning):
assert lines[4] == " * Sub Ba" assert lines[4] == " * Sub Ba"
assert lines[5] == "" assert lines[5] == ""
assert lines[6] == " * Sub Bb" assert lines[6] == " * Sub Bb"
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8') doc2 = (app.outdir / 'doc2.txt').read_text(encoding='utf8')
expect = ( expect = (
"Section B\n" "Section B\n"
"*********\n" "*********\n"

View File

@ -32,5 +32,5 @@ def expect_date(request, monkeypatch):
@pytest.mark.sphinx('html', testroot='correct-year') @pytest.mark.sphinx('html', testroot='correct-year')
def test_correct_year(expect_date, app): def test_correct_year(expect_date, app):
app.build() app.build()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert expect_date in content assert expect_date in content

View File

@ -36,7 +36,7 @@ def test_LiteralIncludeReader(literal_inc_path):
options = {'lineno-match': True} options = {'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read() content, lines = reader.read()
assert content == literal_inc_path.text() assert content == literal_inc_path.read_text()
assert lines == 13 assert lines == 13
assert reader.lineno_start == 1 assert reader.lineno_start == 1
@ -46,7 +46,7 @@ def test_LiteralIncludeReader_lineno_start(literal_inc_path):
options = {'lineno-start': 4} options = {'lineno-start': 4}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read() content, lines = reader.read()
assert content == literal_inc_path.text() assert content == literal_inc_path.read_text()
assert lines == 13 assert lines == 13
assert reader.lineno_start == 4 assert reader.lineno_start == 4
@ -324,7 +324,7 @@ def test_force_option(app, status, warning):
@pytest.mark.sphinx('html', testroot='directive-code') @pytest.mark.sphinx('html', testroot='directive-code')
def test_code_block_caption_html(app, status, warning): def test_code_block_caption_html(app, status, warning):
app.builder.build(['caption']) app.builder.build(['caption'])
html = (app.outdir / 'caption.html').text() html = (app.outdir / 'caption.html').read_text()
caption = ('<div class="code-block-caption">' caption = ('<div class="code-block-caption">'
'<span class="caption-number">Listing 1 </span>' '<span class="caption-number">Listing 1 </span>'
'<span class="caption-text">caption <em>test</em> rb' '<span class="caption-text">caption <em>test</em> rb'
@ -336,7 +336,7 @@ def test_code_block_caption_html(app, status, warning):
@pytest.mark.sphinx('latex', testroot='directive-code') @pytest.mark.sphinx('latex', testroot='directive-code')
def test_code_block_caption_latex(app, status, warning): def test_code_block_caption_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
latex = (app.outdir / 'python.tex').text() latex = (app.outdir / 'python.tex').read_text()
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}' caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}' label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}'
link = '\\hyperref[\\detokenize{caption:name-test-rb}]' \ link = '\\hyperref[\\detokenize{caption:name-test-rb}]' \
@ -349,7 +349,7 @@ def test_code_block_caption_latex(app, status, warning):
@pytest.mark.sphinx('latex', testroot='directive-code') @pytest.mark.sphinx('latex', testroot='directive-code')
def test_code_block_namedlink_latex(app, status, warning): def test_code_block_namedlink_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
latex = (app.outdir / 'python.tex').text() latex = (app.outdir / 'python.tex').read_text()
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-rb}}}' label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-rb}}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-rb}]'\ link1 = '\\hyperref[\\detokenize{caption:name-test-rb}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}' '{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
@ -366,7 +366,7 @@ def test_code_block_namedlink_latex(app, status, warning):
@pytest.mark.sphinx('latex', testroot='directive-code') @pytest.mark.sphinx('latex', testroot='directive-code')
def test_code_block_emphasize_latex(app, status, warning): def test_code_block_emphasize_latex(app, status, warning):
app.builder.build(['emphasize']) app.builder.build(['emphasize'])
latex = (app.outdir / 'python.tex').text().replace('\r\n', '\n') latex = (app.outdir / 'python.tex').read_text().replace('\r\n', '\n')
includes = '\\fvset{hllines={, 5, 6, 13, 14, 15, 24, 25, 26,}}%\n' includes = '\\fvset{hllines={, 5, 6, 13, 14, 15, 24, 25, 26,}}%\n'
assert includes in latex assert includes in latex
includes = '\\end{sphinxVerbatim}\n\\sphinxresetverbatimhllines\n' includes = '\\end{sphinxVerbatim}\n\\sphinxresetverbatimhllines\n'
@ -379,7 +379,7 @@ def test_literal_include(app, status, warning):
et = etree_parse(app.outdir / 'index.xml') et = etree_parse(app.outdir / 'index.xml')
secs = et.findall('./section/section') secs = et.findall('./section/section')
literal_include = secs[1].findall('literal_block') literal_include = secs[1].findall('literal_block')
literal_src = (app.srcdir / 'literal.inc').text() literal_src = (app.srcdir / 'literal.inc').read_text()
assert len(literal_include) > 0 assert len(literal_include) > 0
actual = literal_include[0].text actual = literal_include[0].text
assert actual == literal_src assert actual == literal_src
@ -412,7 +412,7 @@ def test_literal_include_block_start_with_comment_or_brank(app, status, warning)
@pytest.mark.sphinx('html', testroot='directive-code') @pytest.mark.sphinx('html', testroot='directive-code')
def test_literal_include_linenos(app, status, warning): def test_literal_include_linenos(app, status, warning):
app.builder.build(['linenos']) app.builder.build(['linenos'])
html = (app.outdir / 'linenos.html').text() html = (app.outdir / 'linenos.html').read_text()
# :linenos: # :linenos:
assert ('<td class="linenos"><div class="linenodiv"><pre>' assert ('<td class="linenos"><div class="linenodiv"><pre>'
@ -458,7 +458,7 @@ def test_literal_include_linenos(app, status, warning):
@pytest.mark.sphinx('latex', testroot='directive-code') @pytest.mark.sphinx('latex', testroot='directive-code')
def test_literalinclude_file_whole_of_emptyline(app, status, warning): def test_literalinclude_file_whole_of_emptyline(app, status, warning):
app.builder.build_all() app.builder.build_all()
latex = (app.outdir / 'python.tex').text().replace('\r\n', '\n') latex = (app.outdir / 'python.tex').read_text().replace('\r\n', '\n')
includes = ( includes = (
'\\begin{sphinxVerbatim}' '\\begin{sphinxVerbatim}'
'[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n' '[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n'
@ -472,7 +472,7 @@ def test_literalinclude_file_whole_of_emptyline(app, status, warning):
@pytest.mark.sphinx('html', testroot='directive-code') @pytest.mark.sphinx('html', testroot='directive-code')
def test_literalinclude_caption_html(app, status, warning): def test_literalinclude_caption_html(app, status, warning):
app.builder.build('index') app.builder.build('index')
html = (app.outdir / 'caption.html').text() html = (app.outdir / 'caption.html').read_text()
caption = ('<div class="code-block-caption">' caption = ('<div class="code-block-caption">'
'<span class="caption-number">Listing 2 </span>' '<span class="caption-number">Listing 2 </span>'
'<span class="caption-text">caption <strong>test</strong> py' '<span class="caption-text">caption <strong>test</strong> py'
@ -484,7 +484,7 @@ def test_literalinclude_caption_html(app, status, warning):
@pytest.mark.sphinx('latex', testroot='directive-code') @pytest.mark.sphinx('latex', testroot='directive-code')
def test_literalinclude_caption_latex(app, status, warning): def test_literalinclude_caption_latex(app, status, warning):
app.builder.build('index') app.builder.build('index')
latex = (app.outdir / 'python.tex').text() latex = (app.outdir / 'python.tex').read_text()
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}' caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}' label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}'
link = '\\hyperref[\\detokenize{caption:name-test-py}]' \ link = '\\hyperref[\\detokenize{caption:name-test-py}]' \
@ -497,7 +497,7 @@ def test_literalinclude_caption_latex(app, status, warning):
@pytest.mark.sphinx('latex', testroot='directive-code') @pytest.mark.sphinx('latex', testroot='directive-code')
def test_literalinclude_namedlink_latex(app, status, warning): def test_literalinclude_namedlink_latex(app, status, warning):
app.builder.build('index') app.builder.build('index')
latex = (app.outdir / 'python.tex').text() latex = (app.outdir / 'python.tex').read_text()
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-py}}}' label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-py}}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-py}]'\ link1 = '\\hyperref[\\detokenize{caption:name-test-py}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}' '{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
@ -584,7 +584,7 @@ def test_code_block_highlighted(app, status, warning):
@pytest.mark.sphinx('html', testroot='directive-code') @pytest.mark.sphinx('html', testroot='directive-code')
def test_linenothreshold(app, status, warning): def test_linenothreshold(app, status, warning):
app.builder.build(['linenothreshold']) app.builder.build(['linenothreshold'])
html = (app.outdir / 'linenothreshold.html').text() html = (app.outdir / 'linenothreshold.html').read_text()
lineos_head = '<td class="linenos"><div class="linenodiv"><pre>' lineos_head = '<td class="linenos"><div class="linenodiv"><pre>'
lineos_tail = '</pre></div></td>' lineos_tail = '</pre></div></td>'

View File

@ -891,14 +891,14 @@ def test_build_domain_cpp_with_add_function_parentheses_is_True(app, status, war
] ]
f = 'roles.html' f = 'roles.html'
t = (app.outdir / f).text() t = (app.outdir / f).read_text()
for s in rolePatterns: for s in rolePatterns:
check(s, t, f) check(s, t, f)
for s in parenPatterns: for s in parenPatterns:
check(s, t, f) check(s, t, f)
f = 'any-role.html' f = 'any-role.html'
t = (app.outdir / f).text() t = (app.outdir / f).read_text()
for s in parenPatterns: for s in parenPatterns:
check(s, t, f) check(s, t, f)
@ -934,14 +934,14 @@ def test_build_domain_cpp_with_add_function_parentheses_is_False(app, status, wa
] ]
f = 'roles.html' f = 'roles.html'
t = (app.outdir / f).text() t = (app.outdir / f).read_text()
for s in rolePatterns: for s in rolePatterns:
check(s, t, f) check(s, t, f)
for s in parenPatterns: for s in parenPatterns:
check(s, t, f) check(s, t, f)
f = 'any-role.html' f = 'any-role.html'
t = (app.outdir / f).text() t = (app.outdir / f).read_text()
for s in parenPatterns: for s in parenPatterns:
check(s, t, f) check(s, t, f)
@ -951,7 +951,7 @@ def test_xref_consistency(app, status, warning):
app.builder.build_all() app.builder.build_all()
test = 'xref_consistency.html' test = 'xref_consistency.html'
output = (app.outdir / test).text() output = (app.outdir / test).read_text()
def classes(role, tag): def classes(role, tag):
pattern = (r'{role}-role:.*?' pattern = (r'{role}-role:.*?'

View File

@ -371,5 +371,5 @@ def test_productionlist(app, status, warning):
('SecondLine', 'firstLineRule.html#grammar-token-_secondline', 'SecondLine'), ('SecondLine', 'firstLineRule.html#grammar-token-_secondline', 'SecondLine'),
] ]
text = (app.outdir / 'LineContinuation.html').text() text = (app.outdir / 'LineContinuation.html').read_text()
assert "A</strong> ::= B C D E F G" in text assert "A</strong> ::= B C D E F G" in text

View File

@ -275,7 +275,7 @@ def test_multibyte_parameters(make_app, apidoc):
assert (outdir / 'conf.py').isfile() assert (outdir / 'conf.py').isfile()
assert (outdir / 'index.rst').isfile() assert (outdir / 'index.rst').isfile()
conf_py = (outdir / 'conf.py').text() conf_py = (outdir / 'conf.py').read_text()
assert "project = 'プロジェクト名'" in conf_py assert "project = 'プロジェクト名'" in conf_py
assert "author = '著者名'" in conf_py assert "author = '著者名'" in conf_py
assert "version = 'バージョン'" in conf_py assert "version = 'バージョン'" in conf_py
@ -408,13 +408,13 @@ def test_private(tempdir):
# without --private option # without --private option
apidoc_main(['-o', tempdir, tempdir]) apidoc_main(['-o', tempdir, tempdir])
assert (tempdir / 'hello.rst').exists() assert (tempdir / 'hello.rst').exists()
assert ':private-members:' not in (tempdir / 'hello.rst').text() assert ':private-members:' not in (tempdir / 'hello.rst').read_text()
assert not (tempdir / '_world.rst').exists() assert not (tempdir / '_world.rst').exists()
# with --private option # with --private option
apidoc_main(['--private', '-f', '-o', tempdir, tempdir]) apidoc_main(['--private', '-f', '-o', tempdir, tempdir])
assert (tempdir / 'hello.rst').exists() assert (tempdir / 'hello.rst').exists()
assert ':private-members:' in (tempdir / 'hello.rst').text() assert ':private-members:' in (tempdir / 'hello.rst').read_text()
assert (tempdir / '_world.rst').exists() assert (tempdir / '_world.rst').exists()
@ -426,7 +426,7 @@ def test_toc_file(tempdir):
apidoc_main(['-o', tempdir, tempdir]) apidoc_main(['-o', tempdir, tempdir])
assert (outdir / 'modules.rst').exists() assert (outdir / 'modules.rst').exists()
content = (outdir / 'modules.rst').text() content = (outdir / 'modules.rst').read_text()
assert content == ("test_toc_file0\n" assert content == ("test_toc_file0\n"
"==============\n" "==============\n"
"\n" "\n"
@ -442,7 +442,7 @@ def test_module_file(tempdir):
apidoc_main(['-o', tempdir, tempdir]) apidoc_main(['-o', tempdir, tempdir])
assert (outdir / 'example.rst').exists() assert (outdir / 'example.rst').exists()
content = (outdir / 'example.rst').text() content = (outdir / 'example.rst').read_text()
assert content == ("example module\n" assert content == ("example module\n"
"==============\n" "==============\n"
"\n" "\n"
@ -458,7 +458,7 @@ def test_module_file_noheadings(tempdir):
apidoc_main(['--no-headings', '-o', tempdir, tempdir]) apidoc_main(['--no-headings', '-o', tempdir, tempdir])
assert (outdir / 'example.rst').exists() assert (outdir / 'example.rst').exists()
content = (outdir / 'example.rst').text() content = (outdir / 'example.rst').read_text()
assert content == (".. automodule:: example\n" assert content == (".. automodule:: example\n"
" :members:\n" " :members:\n"
" :undoc-members:\n" " :undoc-members:\n"
@ -477,7 +477,7 @@ def test_package_file(tempdir):
assert (outdir / 'testpkg.rst').exists() assert (outdir / 'testpkg.rst').exists()
assert (outdir / 'testpkg.subpkg.rst').exists() assert (outdir / 'testpkg.subpkg.rst').exists()
content = (outdir / 'testpkg.rst').text() content = (outdir / 'testpkg.rst').read_text()
assert content == ("testpkg package\n" assert content == ("testpkg package\n"
"===============\n" "===============\n"
"\n" "\n"
@ -516,7 +516,7 @@ def test_package_file(tempdir):
" :undoc-members:\n" " :undoc-members:\n"
" :show-inheritance:\n") " :show-inheritance:\n")
content = (outdir / 'testpkg.subpkg.rst').text() content = (outdir / 'testpkg.subpkg.rst').read_text()
assert content == ("testpkg.subpkg package\n" assert content == ("testpkg.subpkg package\n"
"======================\n" "======================\n"
"\n" "\n"
@ -538,7 +538,7 @@ def test_package_file_separate(tempdir):
assert (outdir / 'testpkg.rst').exists() assert (outdir / 'testpkg.rst').exists()
assert (outdir / 'testpkg.example.rst').exists() assert (outdir / 'testpkg.example.rst').exists()
content = (outdir / 'testpkg.rst').text() content = (outdir / 'testpkg.rst').read_text()
assert content == ("testpkg package\n" assert content == ("testpkg package\n"
"===============\n" "===============\n"
"\n" "\n"
@ -557,7 +557,7 @@ def test_package_file_separate(tempdir):
" :undoc-members:\n" " :undoc-members:\n"
" :show-inheritance:\n") " :show-inheritance:\n")
content = (outdir / 'testpkg.example.rst').text() content = (outdir / 'testpkg.example.rst').read_text()
assert content == ("testpkg.example module\n" assert content == ("testpkg.example module\n"
"======================\n" "======================\n"
"\n" "\n"
@ -574,7 +574,7 @@ def test_package_file_module_first(tempdir):
(outdir / 'testpkg' / 'example.py').write_text('') (outdir / 'testpkg' / 'example.py').write_text('')
apidoc_main(['--module-first', '-o', tempdir, tempdir]) apidoc_main(['--module-first', '-o', tempdir, tempdir])
content = (outdir / 'testpkg.rst').text() content = (outdir / 'testpkg.rst').read_text()
assert content == ("testpkg package\n" assert content == ("testpkg package\n"
"===============\n" "===============\n"
"\n" "\n"
@ -603,7 +603,7 @@ def test_package_file_without_submodules(tempdir):
apidoc_main(['-o', tempdir, tempdir / 'testpkg']) apidoc_main(['-o', tempdir, tempdir / 'testpkg'])
assert (outdir / 'testpkg.rst').exists() assert (outdir / 'testpkg.rst').exists()
content = (outdir / 'testpkg.rst').text() content = (outdir / 'testpkg.rst').read_text()
assert content == ("testpkg package\n" assert content == ("testpkg package\n"
"===============\n" "===============\n"
"\n" "\n"
@ -623,7 +623,7 @@ def test_namespace_package_file(tempdir):
apidoc_main(['--implicit-namespace', '-o', tempdir, tempdir / 'testpkg']) apidoc_main(['--implicit-namespace', '-o', tempdir, tempdir / 'testpkg'])
assert (outdir / 'testpkg.rst').exists() assert (outdir / 'testpkg.rst').exists()
content = (outdir / 'testpkg.rst').text() content = (outdir / 'testpkg.rst').read_text()
assert content == ("testpkg namespace\n" assert content == ("testpkg namespace\n"
"=================\n" "=================\n"
"\n" "\n"

View File

@ -544,7 +544,7 @@ def test_autodoc_typehints_none(app):
'autodoc_typehints': 'description'}) 'autodoc_typehints': 'description'})
def test_autodoc_typehints_description(app): def test_autodoc_typehints_description(app):
app.build() app.build()
context = (app.outdir / 'index.txt').text() context = (app.outdir / 'index.txt').read_text()
assert ('target.typehints.incr(a, b=1)\n' assert ('target.typehints.incr(a, b=1)\n'
'\n' '\n'
' Parameters:\n' ' Parameters:\n'

View File

@ -21,7 +21,7 @@ from sphinx.util import docutils
def test_autosectionlabel_html(app, status, warning, skipped_labels=False): def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = ('<li><p><a class="reference internal" href="#introduce-of-sphinx">' html = ('<li><p><a class="reference internal" href="#introduce-of-sphinx">'
'<span class=".*?">Introduce of Sphinx</span></a></p></li>') '<span class=".*?">Introduce of Sphinx</span></a></p></li>')
assert re.search(html, content, re.S) assert re.search(html, content, re.S)
@ -69,7 +69,7 @@ def test_autosectionlabel_prefix_document_html(app, status, warning):
def test_autosectionlabel_maxdepth(app, status, warning): def test_autosectionlabel_maxdepth(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
# depth: 1 # depth: 1
html = ('<li><p><a class="reference internal" href="#test-ext-autosectionlabel">' html = ('<li><p><a class="reference internal" href="#test-ext-autosectionlabel">'

View File

@ -210,13 +210,13 @@ def test_autosummary_generate(app, status, warning):
assert doctree[3][0][0][2][2].astext() == 'autosummary_dummy_module.bar(x[, y])\n\n' assert doctree[3][0][0][2][2].astext() == 'autosummary_dummy_module.bar(x[, y])\n\n'
assert doctree[3][0][0][2][3].astext() == 'autosummary_importfail\n\n' assert doctree[3][0][0][2][3].astext() == 'autosummary_importfail\n\n'
module = (app.srcdir / 'generated' / 'autosummary_dummy_module.rst').text() module = (app.srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text()
assert (' .. autosummary::\n' assert (' .. autosummary::\n'
' \n' ' \n'
' Foo\n' ' Foo\n'
' \n' in module) ' \n' in module)
Foo = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.rst').text() Foo = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.rst').read_text()
assert '.. automethod:: __init__' in Foo assert '.. automethod:: __init__' in Foo
assert (' .. autosummary::\n' assert (' .. autosummary::\n'
' \n' ' \n'
@ -239,7 +239,7 @@ def test_autosummary_generate_overwrite1(app_params, make_app):
(srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('') (srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('')
app = make_app(*args, **kwargs) app = make_app(*args, **kwargs)
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').text() content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text()
assert content == '' assert content == ''
assert 'autosummary_dummy_module.rst' not in app._warning.getvalue() assert 'autosummary_dummy_module.rst' not in app._warning.getvalue()
@ -254,7 +254,7 @@ def test_autosummary_generate_overwrite2(app_params, make_app):
(srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('') (srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('')
app = make_app(*args, **kwargs) app = make_app(*args, **kwargs)
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').text() content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text()
assert content != '' assert content != ''
assert 'autosummary_dummy_module.rst' not in app._warning.getvalue() assert 'autosummary_dummy_module.rst' not in app._warning.getvalue()
@ -262,7 +262,7 @@ def test_autosummary_generate_overwrite2(app_params, make_app):
@pytest.mark.sphinx('latex', **default_kw) @pytest.mark.sphinx('latex', **default_kw)
def test_autosummary_latex_table_colspec(app, status, warning): def test_autosummary_latex_table_colspec(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
assert r'\begin{longtable}[c]{\X{1}{2}\X{1}{2}}' in result assert r'\begin{longtable}[c]{\X{1}{2}\X{1}{2}}' in result
@ -312,7 +312,7 @@ def test_autosummary_imported_members(app, status, warning):
# generated/foo is generated successfully # generated/foo is generated successfully
assert app.env.get_doctree('generated/autosummary_dummy_package') assert app.env.get_doctree('generated/autosummary_dummy_package')
module = (app.srcdir / 'generated' / 'autosummary_dummy_package.rst').text() module = (app.srcdir / 'generated' / 'autosummary_dummy_package.rst').read_text()
assert (' .. autosummary::\n' assert (' .. autosummary::\n'
' \n' ' \n'
' Bar\n' ' Bar\n'
@ -331,7 +331,7 @@ def test_generate_autosummary_docs_property(app):
mock.return_value = [('target.methods.Base.prop', 'prop', None)] mock.return_value = [('target.methods.Base.prop', 'prop', None)]
generate_autosummary_docs([], output_dir=app.srcdir, builder=app.builder, app=app) generate_autosummary_docs([], output_dir=app.srcdir, builder=app.builder, app=app)
content = (app.srcdir / 'target.methods.Base.prop.rst').text() content = (app.srcdir / 'target.methods.Base.prop.rst').read_text()
assert content == ("target.methods.Base.prop\n" assert content == ("target.methods.Base.prop\n"
"========================\n" "========================\n"
"\n" "\n"
@ -344,7 +344,7 @@ def test_generate_autosummary_docs_property(app):
def test_autosummary_skip_member(app): def test_autosummary_skip_member(app):
app.build() app.build()
content = (app.srcdir / 'generate' / 'target.Foo.rst').text() content = (app.srcdir / 'generate' / 'target.Foo.rst').read_text()
assert 'Foo.skipmeth' not in content assert 'Foo.skipmeth' not in content
assert 'Foo._privatemeth' in content assert 'Foo._privatemeth' in content

View File

@ -17,7 +17,7 @@ import pytest
def test_build(app, status, warning): def test_build(app, status, warning):
app.builder.build_all() app.builder.build_all()
py_undoc = (app.outdir / 'python.txt').text() py_undoc = (app.outdir / 'python.txt').read_text()
assert py_undoc.startswith('Undocumented Python objects\n' assert py_undoc.startswith('Undocumented Python objects\n'
'===========================\n') '===========================\n')
assert 'autodoc_target\n--------------\n' in py_undoc assert 'autodoc_target\n--------------\n' in py_undoc
@ -28,13 +28,13 @@ def test_build(app, status, warning):
assert ' * mod -- No module named mod' # in the "failed import" section assert ' * mod -- No module named mod' # in the "failed import" section
c_undoc = (app.outdir / 'c.txt').text() c_undoc = (app.outdir / 'c.txt').read_text()
assert c_undoc.startswith('Undocumented C API elements\n' assert c_undoc.startswith('Undocumented C API elements\n'
'===========================\n') '===========================\n')
assert 'api.h' in c_undoc assert 'api.h' in c_undoc
assert ' * Py_SphinxTest' in c_undoc assert ' * Py_SphinxTest' in c_undoc
undoc_py, undoc_c = pickle.loads((app.outdir / 'undoc.pickle').bytes()) undoc_py, undoc_c = pickle.loads((app.outdir / 'undoc.pickle').read_bytes())
assert len(undoc_c) == 1 assert len(undoc_c) == 1
# the key is the full path to the header file, which isn't testable # the key is the full path to the header file, which isn't testable
assert list(undoc_c.values())[0] == {('function', 'Py_SphinxTest')} assert list(undoc_c.values())[0] == {('function', 'Py_SphinxTest')}
@ -50,7 +50,7 @@ def test_build(app, status, warning):
@pytest.mark.sphinx('coverage', testroot='ext-coverage') @pytest.mark.sphinx('coverage', testroot='ext-coverage')
def test_coverage_ignore_pyobjects(app, status, warning): def test_coverage_ignore_pyobjects(app, status, warning):
app.builder.build_all() app.builder.build_all()
actual = (app.outdir / 'python.txt').text() actual = (app.outdir / 'python.txt').read_text()
expected = '''Undocumented Python objects expected = '''Undocumented Python objects
=========================== ===========================
coverage_not_ignored coverage_not_ignored

View File

@ -31,4 +31,4 @@ def test_no_cname_for_github_io_domain(app, status, warning):
def test_cname_for_custom_domain(app, status, warning): def test_cname_for_custom_domain(app, status, warning):
app.builder.build_all() app.builder.build_all()
assert (app.outdir / '.nojekyll').exists() assert (app.outdir / '.nojekyll').exists()
assert (app.outdir / 'CNAME').text() == 'sphinx-doc.org' assert (app.outdir / 'CNAME').read_text() == 'sphinx-doc.org'

View File

@ -20,7 +20,7 @@ from sphinx.ext.graphviz import ClickableMapDefinition
def test_graphviz_png_html(app, status, warning): def test_graphviz_png_html(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = (r'<div class="figure align-default" .*?>\s*' html = (r'<div class="figure align-default" .*?>\s*'
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">' r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
r'<span class="caption-text">caption of graph</span>.*</p>\s*</div>') r'<span class="caption-text">caption of graph</span>.*</p>\s*</div>')
@ -51,7 +51,7 @@ def test_graphviz_png_html(app, status, warning):
def test_graphviz_svg_html(app, status, warning): def test_graphviz_svg_html(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = (r'<div class=\"figure align-default\" .*?>\n' html = (r'<div class=\"figure align-default\" .*?>\n'
r'<div class="graphviz"><object data=\".*\.svg\".*>\n' r'<div class="graphviz"><object data=\".*\.svg\".*>\n'
@ -91,7 +91,7 @@ def test_graphviz_svg_html(app, status, warning):
def test_graphviz_latex(app, status, warning): def test_graphviz_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.tex').text() content = (app.outdir / 'python.tex').read_text()
macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n' macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n'
'\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n' '\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n'
'\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}') '\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}')
@ -117,7 +117,7 @@ def test_graphviz_latex(app, status, warning):
def test_graphviz_i18n(app, status, warning): def test_graphviz_i18n(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = '<img src=".*?" alt="digraph {\n BAR -&gt; BAZ\n}" class="graphviz" />' html = '<img src=".*?" alt="digraph {\n BAR -&gt; BAZ\n}" class="graphviz" />'
assert re.search(html, content, re.M) assert re.search(html, content, re.M)

View File

@ -14,6 +14,6 @@ import pytest
@pytest.mark.sphinx('text', testroot='ext-ifconfig') @pytest.mark.sphinx('text', testroot='ext-ifconfig')
def test_ifconfig(app, status, warning): def test_ifconfig(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'index.txt').text() result = (app.outdir / 'index.txt').read_text()
assert 'spam' in result assert 'spam' in result
assert 'ham' not in result assert 'ham' not in result

View File

@ -18,7 +18,7 @@ import pytest
def test_ext_imgconverter(app, status, warning): def test_ext_imgconverter(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.tex').text() content = (app.outdir / 'python.tex').read_text()
assert '\\sphinxincludegraphics{{svgimg}.png}' in content assert '\\sphinxincludegraphics{{svgimg}.png}' in content
assert not (app.outdir / 'svgimg.svg').exists() assert not (app.outdir / 'svgimg.svg').exists()
assert (app.outdir / 'svgimg.png').exists() assert (app.outdir / 'svgimg.png').exists()

View File

@ -138,7 +138,7 @@ def test_inheritance_diagram(app, status, warning):
def test_inheritance_diagram_png_html(app, status, warning): def test_inheritance_diagram_png_html(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
pattern = ('<div class="figure align-default" id="id1">\n' pattern = ('<div class="figure align-default" id="id1">\n'
'<div class="graphviz">' '<div class="graphviz">'
@ -155,7 +155,7 @@ def test_inheritance_diagram_png_html(app, status, warning):
def test_inheritance_diagram_svg_html(app, status, warning): def test_inheritance_diagram_svg_html(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
pattern = ('<div class="figure align-default" id="id1">\n' pattern = ('<div class="figure align-default" id="id1">\n'
'<div class="graphviz">' '<div class="graphviz">'
@ -173,7 +173,7 @@ def test_inheritance_diagram_svg_html(app, status, warning):
def test_inheritance_diagram_latex(app, status, warning): def test_inheritance_diagram_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.tex').text() content = (app.outdir / 'python.tex').read_text()
pattern = ('\\\\begin{figure}\\[htbp]\n\\\\centering\n\\\\capstart\n\n' pattern = ('\\\\begin{figure}\\[htbp]\n\\\\centering\n\\\\capstart\n\n'
'\\\\sphinxincludegraphics\\[\\]{inheritance-\\w+.pdf}\n' '\\\\sphinxincludegraphics\\[\\]{inheritance-\\w+.pdf}\n'
@ -195,7 +195,7 @@ def test_inheritance_diagram_latex_alias(app, status, warning):
assert ('test.Bar', 'test.Bar', ['alias.Foo'], None) in aliased_graph assert ('test.Bar', 'test.Bar', ['alias.Foo'], None) in aliased_graph
assert ('alias.Foo', 'alias.Foo', [], None) in aliased_graph assert ('alias.Foo', 'alias.Foo', [], None) in aliased_graph
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
pattern = ('<div class="figure align-default" id="id1">\n' pattern = ('<div class="figure align-default" id="id1">\n'
'<div class="graphviz">' '<div class="graphviz">'

View File

@ -236,7 +236,7 @@ def test_missing_reference_cppdomain(tempdir, app, status, warning):
load_mappings(app) load_mappings(app)
app.build() app.build()
html = (app.outdir / 'index.html').text() html = (app.outdir / 'index.html').read_text()
assert ('<a class="reference external"' assert ('<a class="reference external"'
' href="https://docs.python.org/index.html#cpp_foo_bar"' ' href="https://docs.python.org/index.html#cpp_foo_bar"'
' title="(in foo v2.0)">' ' title="(in foo v2.0)">'

View File

@ -39,7 +39,7 @@ def test_imgmath_png(app, status, warning):
if "dvipng command 'dvipng' cannot be run" in warning.getvalue(): if "dvipng command 'dvipng' cannot be run" in warning.getvalue():
raise pytest.skip.Exception('dvipng command "dvipng" is not available') raise pytest.skip.Exception('dvipng command "dvipng" is not available')
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"' 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>') 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.S)
@ -57,7 +57,7 @@ def test_imgmath_svg(app, status, warning):
if "dvisvgm command 'dvisvgm' cannot be run" in warning.getvalue(): if "dvisvgm command 'dvisvgm' cannot be run" in warning.getvalue():
raise pytest.skip.Exception('dvisvgm command "dvisvgm" is not available') raise pytest.skip.Exception('dvisvgm command "dvisvgm" is not available')
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"' 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>') 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.S)
@ -69,7 +69,7 @@ def test_imgmath_svg(app, status, warning):
def test_mathjax_options(app, status, warning): def test_mathjax_options(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert ('<script async="async" integrity="sha384-0123456789" ' assert ('<script async="async" integrity="sha384-0123456789" '
'src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?' 'src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?'
'config=TeX-AMS-MML_HTMLorMML"></script>' in content) 'config=TeX-AMS-MML_HTMLorMML"></script>' in content)
@ -80,7 +80,7 @@ def test_mathjax_options(app, status, warning):
def test_mathjax_align(app, status, warning): def test_mathjax_align(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = (r'<div class="math notranslate nohighlight">\s*' html = (r'<div class="math notranslate nohighlight">\s*'
r'\\\[ \\begin\{align\}\\begin\{aligned\}S \&amp;= \\pi r\^2\\\\' r'\\\[ \\begin\{align\}\\begin\{aligned\}S \&amp;= \\pi r\^2\\\\'
r'V \&amp;= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]</div>') r'V \&amp;= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]</div>')
@ -93,7 +93,7 @@ def test_mathjax_align(app, status, warning):
def test_math_number_all_mathjax(app, status, warning): def test_math_number_all_mathjax(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
html = (r'<div class="math notranslate nohighlight" id="equation-index-0">\s*' 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>') 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.S)
@ -104,7 +104,7 @@ def test_math_number_all_mathjax(app, status, warning):
def test_math_number_all_latex(app, status, warning): def test_math_number_all_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.tex').text() content = (app.outdir / 'python.tex').read_text()
macro = (r'\\begin{equation\*}\s*' macro = (r'\\begin{equation\*}\s*'
r'\\begin{split}a\^2\+b\^2=c\^2\\end{split}\s*' r'\\begin{split}a\^2\+b\^2=c\^2\\end{split}\s*'
r'\\end{equation\*}') r'\\end{equation\*}')
@ -134,7 +134,7 @@ def test_math_number_all_latex(app, status, warning):
def test_math_eqref_format_html(app, status, warning): def test_math_eqref_format_html(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'math.html').text() content = (app.outdir / 'math.html').read_text()
html = ('<p>Referencing equation <a class="reference internal" ' html = ('<p>Referencing equation <a class="reference internal" '
'href="#equation-foo">Eq.1</a> and <a class="reference internal" ' 'href="#equation-foo">Eq.1</a> and <a class="reference internal" '
'href="#equation-foo">Eq.1</a>.</p>') 'href="#equation-foo">Eq.1</a>.</p>')
@ -147,7 +147,7 @@ def test_math_eqref_format_html(app, status, warning):
def test_math_eqref_format_latex(app, status, warning): def test_math_eqref_format_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.tex').text() content = (app.outdir / 'python.tex').read_text()
macro = (r'Referencing equation Eq.\\ref{equation:math:foo} and ' macro = (r'Referencing equation Eq.\\ref{equation:math:foo} and '
r'Eq.\\ref{equation:math:foo}.') r'Eq.\\ref{equation:math:foo}.')
assert re.search(macro, content, re.S) assert re.search(macro, content, re.S)
@ -160,7 +160,7 @@ def test_math_eqref_format_latex(app, status, warning):
def test_mathjax_numfig_html(app, status, warning): def test_mathjax_numfig_html(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'math.html').text() content = (app.outdir / 'math.html').read_text()
html = ('<div class="math notranslate nohighlight" id="equation-math-0">\n' html = ('<div class="math notranslate nohighlight" id="equation-math-0">\n'
'<span class="eqno">(1.2)') '<span class="eqno">(1.2)')
assert html in content assert html in content
@ -178,7 +178,7 @@ def test_mathjax_numfig_html(app, status, warning):
def test_imgmath_numfig_html(app, status, warning): def test_imgmath_numfig_html(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'page.html').text() content = (app.outdir / 'page.html').read_text()
html = '<span class="eqno">(3)<a class="headerlink" href="#equation-bar"' html = '<span class="eqno">(3)<a class="headerlink" href="#equation-bar"'
assert html in content assert html in content
html = ('<p>Referencing equations <a class="reference internal" ' html = ('<p>Referencing equations <a class="reference internal" '
@ -218,7 +218,7 @@ def test_math_compat(app, status, warning):
def test_mathjax_config(app, status, warning): def test_mathjax_config(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert ('<script type="text/x-mathjax-config">' assert ('<script type="text/x-mathjax-config">'
'MathJax.Hub.Config({"extensions": ["tex2jax.js"]})' 'MathJax.Hub.Config({"extensions": ["tex2jax.js"]})'
'</script>' in content) '</script>' in content)
@ -229,5 +229,5 @@ def test_mathjax_config(app, status, warning):
def test_mathjax_is_not_installed_if_no_equations(app, status, warning): def test_mathjax_is_not_installed_if_no_equations(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert 'MathJax.js' not in content assert 'MathJax.js' not in content

View File

@ -29,7 +29,7 @@ def test_todo(app, status, warning):
app.builder.build_all() app.builder.build_all()
# check todolist # check todolist
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert ('<p class="admonition-title">Todo</p>\n' assert ('<p class="admonition-title">Todo</p>\n'
'<p>todo in foo</p>') in content '<p>todo in foo</p>') in content
@ -37,7 +37,7 @@ def test_todo(app, status, warning):
'<p>todo in bar</p>') in content '<p>todo in bar</p>') in content
# check todo # check todo
content = (app.outdir / 'foo.html').text() content = (app.outdir / 'foo.html').read_text()
assert ('<p class="admonition-title">Todo</p>\n' assert ('<p class="admonition-title">Todo</p>\n'
'<p>todo in foo</p>') in content '<p>todo in foo</p>') in content
@ -67,7 +67,7 @@ def test_todo_not_included(app, status, warning):
app.builder.build_all() app.builder.build_all()
# check todolist # check todolist
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert ('<p class="admonition-title">Todo</p>\n' assert ('<p class="admonition-title">Todo</p>\n'
'<p>todo in foo</p>') not in content '<p>todo in foo</p>') not in content
@ -75,7 +75,7 @@ def test_todo_not_included(app, status, warning):
'<p>todo in bar</p>') not in content '<p>todo in bar</p>') not in content
# check todo # check todo
content = (app.outdir / 'foo.html').text() content = (app.outdir / 'foo.html').read_text()
assert ('<p class="admonition-title">Todo</p>\n' assert ('<p class="admonition-title">Todo</p>\n'
'<p>todo in foo</p>') not in content '<p>todo in foo</p>') not in content
@ -102,7 +102,7 @@ def test_todo_valid_link(app, status, warning):
# Ensure the LaTeX output is built. # Ensure the LaTeX output is built.
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.tex').text() content = (app.outdir / 'python.tex').read_text()
# Look for the link to foo. Note that there are two of them because the # Look for the link to foo. Note that there are two of them because the
# source document uses todolist twice. We could equally well look for links # source document uses todolist twice. We could equally well look for links

View File

@ -24,7 +24,7 @@ def test_viewcode(app, status, warning):
warnings warnings
) )
result = (app.outdir / 'index.html').text() result = (app.outdir / 'index.html').read_text()
assert result.count('href="_modules/spam/mod1.html#func1"') == 2 assert result.count('href="_modules/spam/mod1.html#func1"') == 2
assert result.count('href="_modules/spam/mod2.html#func2"') == 2 assert result.count('href="_modules/spam/mod2.html#func2"') == 2
assert result.count('href="_modules/spam/mod1.html#Class1"') == 2 assert result.count('href="_modules/spam/mod1.html#Class1"') == 2
@ -37,7 +37,7 @@ def test_viewcode(app, status, warning):
# the next assert fails, until the autodoc bug gets fixed # the next assert fails, until the autodoc bug gets fixed
assert result.count('this is the class attribute class_attr') == 2 assert result.count('this is the class attribute class_attr') == 2
result = (app.outdir / '_modules/spam/mod1.html').text() result = (app.outdir / '_modules/spam/mod1.html').read_text()
result = re.sub('<span class=".*?">', '<span>', result) # filter pygments classes result = re.sub('<span class=".*?">', '<span>', result) # filter pygments classes
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" ' assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
'href="../../index.html#spam.Class1">[docs]</a>' 'href="../../index.html#spam.Class1">[docs]</a>'
@ -53,7 +53,7 @@ def test_viewcode(app, status, warning):
def test_linkcode(app, status, warning): def test_linkcode(app, status, warning):
app.builder.build(['objects']) app.builder.build(['objects'])
stuff = (app.outdir / 'objects.html').text() stuff = (app.outdir / 'objects.html').read_text()
assert 'http://foobar/source/foolib.py' in stuff assert 'http://foobar/source/foolib.py' in stuff
assert 'http://foobar/js/' in stuff assert 'http://foobar/js/' in stuff
@ -65,7 +65,7 @@ def test_linkcode(app, status, warning):
def test_local_source_files(app, status, warning): def test_local_source_files(app, status, warning):
def find_source(app, modname): def find_source(app, modname):
if modname == 'not_a_package': if modname == 'not_a_package':
source = (app.srcdir / 'not_a_package/__init__.py').text() source = (app.srcdir / 'not_a_package/__init__.py').read_text()
tags = { tags = {
'func1': ('def', 1, 1), 'func1': ('def', 1, 1),
'Class1': ('class', 1, 1), 'Class1': ('class', 1, 1),
@ -73,7 +73,7 @@ def test_local_source_files(app, status, warning):
'not_a_package.submodule.Class1': ('class', 1, 1), 'not_a_package.submodule.Class1': ('class', 1, 1),
} }
else: else:
source = (app.srcdir / 'not_a_package/submodule.py').text() source = (app.srcdir / 'not_a_package/submodule.py').read_text()
tags = { tags = {
'not_a_package.submodule.func1': ('def', 11, 15), 'not_a_package.submodule.func1': ('def', 11, 15),
'Class1': ('class', 19, 22), 'Class1': ('class', 19, 22),
@ -93,7 +93,7 @@ def test_local_source_files(app, status, warning):
warnings warnings
) )
result = (app.outdir / 'index.html').text() result = (app.outdir / 'index.html').read_text()
assert result.count('href="_modules/not_a_package.html#func1"') == 1 assert result.count('href="_modules/not_a_package.html#func1"') == 1
assert result.count('href="_modules/not_a_package.html#not_a_package.submodule.func1"') == 1 assert result.count('href="_modules/not_a_package.html#not_a_package.submodule.func1"') == 1
assert result.count('href="_modules/not_a_package/submodule.html#Class1"') == 1 assert result.count('href="_modules/not_a_package/submodule.html#Class1"') == 1

View File

@ -95,7 +95,7 @@ def assert_count(expected_expr, result, count):
@pytest.mark.test_params(shared_result='test_intl_basic') @pytest.mark.test_params(shared_result='test_intl_basic')
def test_text_toctree(app): def test_text_toctree(app):
app.build() app.build()
result = (app.outdir / 'index.txt').text() result = (app.outdir / 'index.txt').read_text()
assert_startswith(result, "CONTENTS\n********\n\nTABLE OF CONTENTS\n") assert_startswith(result, "CONTENTS\n********\n\nTABLE OF CONTENTS\n")
@ -117,7 +117,7 @@ def test_text_emit_warnings(app, warning):
def test_text_warning_node(app): def test_text_warning_node(app):
app.build() app.build()
# test warnings in translation # test warnings in translation
result = (app.outdir / 'warnings.txt').text() result = (app.outdir / 'warnings.txt').read_text()
expect = ("3. I18N WITH REST WARNINGS" expect = ("3. I18N WITH REST WARNINGS"
"\n**************************\n" "\n**************************\n"
"\nLINE OF >>``<<BROKEN LITERAL MARKUP.\n") "\nLINE OF >>``<<BROKEN LITERAL MARKUP.\n")
@ -131,7 +131,7 @@ def test_text_warning_node(app):
def test_text_title_underline(app): def test_text_title_underline(app):
app.build() app.build()
# --- simple translation; check title underlines # --- simple translation; check title underlines
result = (app.outdir / 'bom.txt').text() result = (app.outdir / 'bom.txt').read_text()
expect = ("2. Datei mit UTF-8" expect = ("2. Datei mit UTF-8"
"\n******************\n" # underline matches new translation "\n******************\n" # underline matches new translation
"\nThis file has umlauts: äöü.\n") "\nThis file has umlauts: äöü.\n")
@ -144,7 +144,7 @@ def test_text_title_underline(app):
def test_text_subdirs(app): def test_text_subdirs(app):
app.build() app.build()
# --- check translation in subdirs # --- check translation in subdirs
result = (app.outdir / 'subdir' / 'index.txt').text() result = (app.outdir / 'subdir' / 'index.txt').read_text()
assert_startswith(result, "1. subdir contents\n******************\n") assert_startswith(result, "1. subdir contents\n******************\n")
@ -154,7 +154,7 @@ def test_text_subdirs(app):
def test_text_inconsistency_warnings(app, warning): def test_text_inconsistency_warnings(app, warning):
app.build() app.build()
# --- check warnings for inconsistency in number of references # --- check warnings for inconsistency in number of references
result = (app.outdir / 'refs_inconsistency.txt').text() result = (app.outdir / 'refs_inconsistency.txt').read_text()
expect = ("8. I18N WITH REFS INCONSISTENCY" expect = ("8. I18N WITH REFS INCONSISTENCY"
"\n*******************************\n" "\n*******************************\n"
"\n* FOR CITATION [ref3].\n" "\n* FOR CITATION [ref3].\n"
@ -204,7 +204,7 @@ def test_text_inconsistency_warnings(app, warning):
def test_text_literalblock_warnings(app, warning): def test_text_literalblock_warnings(app, warning):
app.build() app.build()
# --- check warning for literal block # --- check warning for literal block
result = (app.outdir / 'literalblock.txt').text() result = (app.outdir / 'literalblock.txt').read_text()
expect = ("9. I18N WITH LITERAL BLOCK" expect = ("9. I18N WITH LITERAL BLOCK"
"\n**************************\n" "\n**************************\n"
"\nCORRECT LITERAL BLOCK:\n" "\nCORRECT LITERAL BLOCK:\n"
@ -226,7 +226,7 @@ def test_text_literalblock_warnings(app, warning):
def test_text_definition_terms(app): def test_text_definition_terms(app):
app.build() app.build()
# --- definition terms: regression test for #975, #2198, #2205 # --- definition terms: regression test for #975, #2198, #2205
result = (app.outdir / 'definition_terms.txt').text() result = (app.outdir / 'definition_terms.txt').read_text()
expect = ("13. I18N WITH DEFINITION TERMS" expect = ("13. I18N WITH DEFINITION TERMS"
"\n******************************\n" "\n******************************\n"
"\nSOME TERM" "\nSOME TERM"
@ -246,7 +246,7 @@ def test_text_definition_terms(app):
def test_text_glossary_term(app, warning): def test_text_glossary_term(app, warning):
app.build() app.build()
# --- glossary terms: regression test for #1090 # --- glossary terms: regression test for #1090
result = (app.outdir / 'glossary_terms.txt').text() result = (app.outdir / 'glossary_terms.txt').read_text()
expect = ("18. I18N WITH GLOSSARY TERMS" expect = ("18. I18N WITH GLOSSARY TERMS"
"\n****************************\n" "\n****************************\n"
"\nSOME NEW TERM" "\nSOME NEW TERM"
@ -265,7 +265,7 @@ def test_text_glossary_term(app, warning):
def test_text_glossary_term_inconsistencies(app, warning): def test_text_glossary_term_inconsistencies(app, warning):
app.build() app.build()
# --- glossary term inconsistencies: regression test for #1090 # --- glossary term inconsistencies: regression test for #1090
result = (app.outdir / 'glossary_terms_inconsistency.txt').text() result = (app.outdir / 'glossary_terms_inconsistency.txt').read_text()
expect = ("19. I18N WITH GLOSSARY TERMS INCONSISTENCY" expect = ("19. I18N WITH GLOSSARY TERMS INCONSISTENCY"
"\n******************************************\n" "\n******************************************\n"
"\n1. LINK TO *SOME NEW TERM*.\n") "\n1. LINK TO *SOME NEW TERM*.\n")
@ -298,7 +298,7 @@ def test_gettext_section(app):
def test_text_section(app): def test_text_section(app):
app.build() app.build()
# --- section # --- section
result = (app.outdir / 'section.txt').text() result = (app.outdir / 'section.txt').read_text()
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'section.po') expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'section.po')
for expect_msg in [m for m in expect if m.id]: for expect_msg in [m for m in expect if m.id]:
assert expect_msg.string in result assert expect_msg.string in result
@ -310,7 +310,7 @@ def test_text_section(app):
def test_text_seealso(app): def test_text_seealso(app):
app.build() app.build()
# --- seealso # --- seealso
result = (app.outdir / 'seealso.txt').text() result = (app.outdir / 'seealso.txt').read_text()
expect = ("12. I18N WITH SEEALSO" expect = ("12. I18N WITH SEEALSO"
"\n*********************\n" "\n*********************\n"
"\nSee also: SHORT TEXT 1\n" "\nSee also: SHORT TEXT 1\n"
@ -327,7 +327,7 @@ def test_text_seealso(app):
def test_text_figure_captions(app): def test_text_figure_captions(app):
app.build() app.build()
# --- figure captions: regression test for #940 # --- figure captions: regression test for #940
result = (app.outdir / 'figure.txt').text() result = (app.outdir / 'figure.txt').read_text()
expect = ("14. I18N WITH FIGURE CAPTION" expect = ("14. I18N WITH FIGURE CAPTION"
"\n****************************\n" "\n****************************\n"
"\n [image]MY CAPTION OF THE FIGURE\n" "\n [image]MY CAPTION OF THE FIGURE\n"
@ -371,7 +371,7 @@ def test_text_figure_captions(app):
def test_text_rubric(app): def test_text_rubric(app):
app.build() app.build()
# --- rubric: regression test for pull request #190 # --- rubric: regression test for pull request #190
result = (app.outdir / 'rubric.txt').text() result = (app.outdir / 'rubric.txt').read_text()
expect = ("I18N WITH RUBRIC" expect = ("I18N WITH RUBRIC"
"\n****************\n" "\n****************\n"
"\n-[ RUBRIC TITLE ]-\n" "\n-[ RUBRIC TITLE ]-\n"
@ -389,7 +389,7 @@ def test_text_rubric(app):
def test_text_docfields(app): def test_text_docfields(app):
app.build() app.build()
# --- docfields # --- docfields
result = (app.outdir / 'docfields.txt').text() result = (app.outdir / 'docfields.txt').read_text()
expect = ("21. I18N WITH DOCFIELDS" expect = ("21. I18N WITH DOCFIELDS"
"\n***********************\n" "\n***********************\n"
"\nclass Cls1\n" "\nclass Cls1\n"
@ -420,7 +420,7 @@ def test_text_admonitions(app):
# --- admonitions # --- admonitions
# #1206: gettext did not translate admonition directive's title # #1206: gettext did not translate admonition directive's title
# seealso: http://docutils.sourceforge.net/docs/ref/rst/directives.html#admonitions # seealso: http://docutils.sourceforge.net/docs/ref/rst/directives.html#admonitions
result = (app.outdir / 'admonitions.txt').text() result = (app.outdir / 'admonitions.txt').read_text()
directives = ( directives = (
"attention", "caution", "danger", "error", "hint", "attention", "caution", "danger", "error", "hint",
"important", "note", "tip", "warning", "admonition") "important", "note", "tip", "warning", "admonition")
@ -462,7 +462,7 @@ def test_gettext_table(app):
def test_text_table(app): def test_text_table(app):
app.build() app.build()
# --- toctree # --- toctree
result = (app.outdir / 'table.txt').text() result = (app.outdir / 'table.txt').read_text()
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'table.po') expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'table.po')
for expect_msg in [m for m in expect if m.id]: for expect_msg in [m for m in expect if m.id]:
assert expect_msg.string in result assert expect_msg.string in result
@ -486,7 +486,7 @@ def test_gettext_toctree(app):
def test_text_toctree(app): def test_text_toctree(app):
app.build() app.build()
# --- toctree # --- toctree
result = (app.outdir / 'toctree.txt').text() result = (app.outdir / 'toctree.txt').read_text()
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'toctree.po') expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'toctree.po')
for expect_msg in [m for m in expect if m.id]: for expect_msg in [m for m in expect if m.id]:
assert expect_msg.string in result assert expect_msg.string in result
@ -510,7 +510,7 @@ def test_gettext_topic(app):
def test_text_topic(app): def test_text_topic(app):
app.build() app.build()
# --- topic # --- topic
result = (app.outdir / 'topic.txt').text() result = (app.outdir / 'topic.txt').read_text()
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'topic.po') expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'topic.po')
for expect_msg in [m for m in expect if m.id]: for expect_msg in [m for m in expect if m.id]:
assert expect_msg.string in result assert expect_msg.string in result
@ -628,7 +628,7 @@ def test_gettext_dont_rebuild_mo(make_app, app_params):
def test_html_meta(app): def test_html_meta(app):
app.build() app.build()
# --- test for meta # --- test for meta
result = (app.outdir / 'index.html').text() result = (app.outdir / 'index.html').read_text()
expected_expr = '<meta content="TESTDATA FOR I18N" name="description" />' expected_expr = '<meta content="TESTDATA FOR I18N" name="description" />'
assert expected_expr in result assert expected_expr in result
expected_expr = '<meta content="I18N, SPHINX, MARKUP" name="keywords" />' expected_expr = '<meta content="I18N, SPHINX, MARKUP" name="keywords" />'
@ -644,7 +644,7 @@ def test_html_footnotes(app):
app.build() app.build()
# --- test for #955 cant-build-html-with-footnotes-when-using # --- test for #955 cant-build-html-with-footnotes-when-using
# expect no error by build # expect no error by build
(app.outdir / 'footnote.html').text() (app.outdir / 'footnote.html').read_text()
@sphinx_intl @sphinx_intl
@ -653,7 +653,7 @@ def test_html_footnotes(app):
def test_html_undefined_refs(app): def test_html_undefined_refs(app):
app.build() app.build()
# --- links to undefined reference # --- links to undefined reference
result = (app.outdir / 'refs_inconsistency.html').text() result = (app.outdir / 'refs_inconsistency.html').read_text()
expected_expr = ('<a class="reference external" ' expected_expr = ('<a class="reference external" '
'href="http://www.example.com">reference</a>') 'href="http://www.example.com">reference</a>')
@ -675,7 +675,7 @@ def test_html_undefined_refs(app):
def test_html_index_entries(app): def test_html_index_entries(app):
app.build() app.build()
# --- index entries: regression test for #976 # --- index entries: regression test for #976
result = (app.outdir / 'genindex.html').text() result = (app.outdir / 'genindex.html').read_text()
def wrap(tag, keyword): def wrap(tag, keyword):
start_tag = "<%s[^>]*>" % tag start_tag = "<%s[^>]*>" % tag
@ -713,7 +713,7 @@ def test_html_index_entries(app):
def test_html_versionchanges(app): def test_html_versionchanges(app):
app.build() app.build()
# --- versionchanges # --- versionchanges
result = (app.outdir / 'versionchange.html').text() result = (app.outdir / 'versionchange.html').read_text()
def get_content(result, name): def get_content(result, name):
matched = re.search(r'<div class="%s">\n*(.*?)</div>' % name, matched = re.search(r'<div class="%s">\n*(.*?)</div>' % name,
@ -750,7 +750,7 @@ def test_html_docfields(app):
app.build() app.build()
# --- docfields # --- docfields
# expect no error by build # expect no error by build
(app.outdir / 'docfields.html').text() (app.outdir / 'docfields.html').read_text()
@sphinx_intl @sphinx_intl
@ -759,7 +759,7 @@ def test_html_docfields(app):
def test_html_template(app): def test_html_template(app):
app.build() app.build()
# --- gettext template # --- gettext template
result = (app.outdir / 'contents.html').text() result = (app.outdir / 'contents.html').read_text()
assert "WELCOME" in result assert "WELCOME" in result
assert "SPHINX 2013.120" in result assert "SPHINX 2013.120" in result
@ -1056,7 +1056,7 @@ def test_xml_label_targets(app):
def test_additional_targets_should_not_be_translated(app): def test_additional_targets_should_not_be_translated(app):
app.build() app.build()
# [literalblock.txt] # [literalblock.txt]
result = (app.outdir / 'literalblock.html').text() result = (app.outdir / 'literalblock.html').read_text()
# title should be translated # title should be translated
expected_expr = 'CODE-BLOCKS' expected_expr = 'CODE-BLOCKS'
@ -1092,7 +1092,7 @@ def test_additional_targets_should_not_be_translated(app):
# [raw.txt] # [raw.txt]
result = (app.outdir / 'raw.html').text() result = (app.outdir / 'raw.html').read_text()
# raw block should not be translated # raw block should not be translated
expected_expr = """<iframe src="http://sphinx-doc.org"></iframe></div>""" expected_expr = """<iframe src="http://sphinx-doc.org"></iframe></div>"""
@ -1100,7 +1100,7 @@ def test_additional_targets_should_not_be_translated(app):
# [figure.txt] # [figure.txt]
result = (app.outdir / 'figure.html').text() result = (app.outdir / 'figure.html').read_text()
# alt and src for image block should not be translated # alt and src for image block should not be translated
expected_expr = """<img alt="i18n" src="_images/i18n.png" />""" expected_expr = """<img alt="i18n" src="_images/i18n.png" />"""
@ -1130,7 +1130,7 @@ def test_additional_targets_should_not_be_translated(app):
def test_additional_targets_should_be_translated(app): def test_additional_targets_should_be_translated(app):
app.build() app.build()
# [literalblock.txt] # [literalblock.txt]
result = (app.outdir / 'literalblock.html').text() result = (app.outdir / 'literalblock.html').read_text()
# title should be translated # title should be translated
expected_expr = 'CODE-BLOCKS' expected_expr = 'CODE-BLOCKS'
@ -1166,7 +1166,7 @@ def test_additional_targets_should_be_translated(app):
# [raw.txt] # [raw.txt]
result = (app.outdir / 'raw.html').text() result = (app.outdir / 'raw.html').read_text()
# raw block should be translated # raw block should be translated
expected_expr = """<iframe src="HTTP://SPHINX-DOC.ORG"></iframe></div>""" expected_expr = """<iframe src="HTTP://SPHINX-DOC.ORG"></iframe></div>"""
@ -1174,7 +1174,7 @@ def test_additional_targets_should_be_translated(app):
# [figure.txt] # [figure.txt]
result = (app.outdir / 'figure.html').text() result = (app.outdir / 'figure.html').read_text()
# alt and src for image block should be translated # alt and src for image block should be translated
expected_expr = """<img alt="I18N -&gt; IMG" src="_images/img.png" />""" expected_expr = """<img alt="I18N -&gt; IMG" src="_images/img.png" />"""

View File

@ -193,7 +193,7 @@ def test_generated_files_eol(tempdir):
qs.generate(d) qs.generate(d)
def assert_eol(filename, eol): def assert_eol(filename, eol):
content = filename.bytes().decode() content = filename.read_bytes().decode()
assert all([l[-len(eol):] == eol for l in content.splitlines(True)]) assert all([l[-len(eol):] == eol for l in content.splitlines(True)])
assert_eol(tempdir / 'make.bat', '\r\n') assert_eol(tempdir / 'make.bat', '\r\n')

View File

@ -41,7 +41,7 @@ def setup_module():
def jsload(path): def jsload(path):
searchindex = path.text() searchindex = path.read_text()
assert searchindex.startswith('Search.setIndex(') assert searchindex.startswith('Search.setIndex(')
assert searchindex.endswith(')') assert searchindex.endswith(')')
@ -98,7 +98,7 @@ def test_meta_keys_are_handled_for_language_de(app, status, warning):
@pytest.mark.sphinx(testroot='search') @pytest.mark.sphinx(testroot='search')
def test_stemmer_does_not_remove_short_words(app, status, warning): def test_stemmer_does_not_remove_short_words(app, status, warning):
app.builder.build_all() app.builder.build_all()
searchindex = (app.outdir / 'searchindex.js').text() searchindex = (app.outdir / 'searchindex.js').read_text()
assert 'zfs' in searchindex assert 'zfs' in searchindex
@ -112,7 +112,7 @@ def test_stemmer(app, status, warning):
@pytest.mark.sphinx(testroot='search') @pytest.mark.sphinx(testroot='search')
def test_term_in_heading_and_section(app, status, warning): def test_term_in_heading_and_section(app, status, warning):
searchindex = (app.outdir / 'searchindex.js').text() searchindex = (app.outdir / 'searchindex.js').read_text()
# if search term is in the title of one doc and in the text of another # if search term is in the title of one doc and in the text of another
# both documents should be a hit in the search index as a title, # both documents should be a hit in the search index as a title,
# respectively text hit # respectively text hit
@ -247,7 +247,7 @@ def test_IndexBuilder_lookup():
def test_search_index_gen_zh(app, status, warning): def test_search_index_gen_zh(app, status, warning):
app.builder.build_all() app.builder.build_all()
# jsdump fails if search language is 'zh'; hence we just get the text: # jsdump fails if search language is 'zh'; hence we just get the text:
searchindex = (app.outdir / 'searchindex.js').text() searchindex = (app.outdir / 'searchindex.js').read_text()
assert 'chinesetest ' not in searchindex assert 'chinesetest ' not in searchindex
assert 'chinesetest' in searchindex assert 'chinesetest' in searchindex
assert 'chinesetesttwo' in searchindex assert 'chinesetesttwo' in searchindex

View File

@ -94,7 +94,7 @@ def nonascii_srcdir(request, setup_command):
""")) """))
master_doc = srcdir / 'index.txt' master_doc = srcdir / 'index.txt'
master_doc.write_bytes((master_doc.text() + dedent(""" master_doc.write_bytes((master_doc.read_text() + dedent("""
.. toctree:: .. toctree::
%(mb_name)s/%(mb_name)s %(mb_name)s/%(mb_name)s

View File

@ -17,7 +17,7 @@ from sphinx.util import docutils
def test_basic(app, status, warning): def test_basic(app, status, warning):
app.build() app.build()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert '<p> “Sphinx” is a tool that makes it easy …</p>' in content assert '<p> “Sphinx” is a tool that makes it easy …</p>' in content
@ -25,7 +25,7 @@ def test_basic(app, status, warning):
def test_text_builder(app, status, warning): def test_text_builder(app, status, warning):
app.build() app.build()
content = (app.outdir / 'index.txt').text() content = (app.outdir / 'index.txt').read_text()
assert '-- "Sphinx" is a tool that makes it easy ...' in content assert '-- "Sphinx" is a tool that makes it easy ...' in content
@ -33,7 +33,7 @@ def test_text_builder(app, status, warning):
def test_man_builder(app, status, warning): def test_man_builder(app, status, warning):
app.build() app.build()
content = (app.outdir / 'python.1').text() content = (app.outdir / 'python.1').read_text()
assert '\\-\\- "Sphinx" is a tool that makes it easy ...' in content assert '\\-\\- "Sphinx" is a tool that makes it easy ...' in content
@ -41,7 +41,7 @@ def test_man_builder(app, status, warning):
def test_latex_builder(app, status, warning): def test_latex_builder(app, status, warning):
app.build() app.build()
content = (app.outdir / 'python.tex').text() content = (app.outdir / 'python.tex').read_text()
assert '\\textendash{} “Sphinx” is a tool that makes it easy …' in content assert '\\textendash{} “Sphinx” is a tool that makes it easy …' in content
@ -50,7 +50,7 @@ def test_latex_builder(app, status, warning):
def test_ja_html_builder(app, status, warning): def test_ja_html_builder(app, status, warning):
app.build() app.build()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
@ -59,7 +59,7 @@ def test_ja_html_builder(app, status, warning):
def test_smartquotes_disabled(app, status, warning): def test_smartquotes_disabled(app, status, warning):
app.build() app.build()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content assert '<p>-- &quot;Sphinx&quot; is a tool that makes it easy ...</p>' in content
@ -70,7 +70,7 @@ def test_smartquotes_disabled(app, status, warning):
def test_smartquotes_action(app, status, warning): def test_smartquotes_action(app, status, warning):
app.build() app.build()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert '<p>-- “Sphinx” is a tool that makes it easy ...</p>' in content assert '<p>-- “Sphinx” is a tool that makes it easy ...</p>' in content
@ -79,7 +79,7 @@ def test_smartquotes_action(app, status, warning):
def test_smartquotes_excludes_language(app, status, warning): def test_smartquotes_excludes_language(app, status, warning):
app.build() app.build()
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').read_text()
assert '<p> 「Sphinx」 is a tool that makes it easy …</p>' in content assert '<p> 「Sphinx」 is a tool that makes it easy …</p>' in content
@ -88,5 +88,5 @@ def test_smartquotes_excludes_language(app, status, warning):
def test_smartquotes_excludes_builders(app, status, warning): def test_smartquotes_excludes_builders(app, status, warning):
app.build() app.build()
content = (app.outdir / 'python.1').text() content = (app.outdir / 'python.1').read_text()
assert ' “Sphinx” is a tool that makes it easy …' in content assert ' “Sphinx” is a tool that makes it easy …' in content

View File

@ -20,7 +20,7 @@ def test_layout_overloading(make_app, app_params):
setup_documenters(app) setup_documenters(app)
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'index.html').text() result = (app.outdir / 'index.html').read_text()
assert '<!-- layout overloading -->' in result assert '<!-- layout overloading -->' in result
@ -31,5 +31,5 @@ def test_autosummary_class_template_overloading(make_app, app_params):
setup_documenters(app) setup_documenters(app)
app.builder.build_update() app.builder.build_update()
result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').text() result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').read_text()
assert 'autosummary/class.rst method block overloading' in result assert 'autosummary/class.rst method block overloading' in result

View File

@ -76,16 +76,16 @@ def test_js_source(app, status, warning):
v = '3.4.1' v = '3.4.1'
msg = 'jquery.js version does not match to {v}'.format(v=v) msg = 'jquery.js version does not match to {v}'.format(v=v)
jquery_min = (app.outdir / '_static' / 'jquery.js').text() jquery_min = (app.outdir / '_static' / 'jquery.js').read_text()
assert 'jQuery v{v}'.format(v=v) in jquery_min, msg assert 'jQuery v{v}'.format(v=v) in jquery_min, msg
jquery_src = (app.outdir / '_static' / 'jquery-{v}.js'.format(v=v)).text() jquery_src = (app.outdir / '_static' / 'jquery-{v}.js'.format(v=v)).read_text()
assert 'jQuery JavaScript Library v{v}'.format(v=v) in jquery_src, msg assert 'jQuery JavaScript Library v{v}'.format(v=v) in jquery_src, msg
v = '1.3.1' v = '1.3.1'
msg = 'underscore.js version does not match to {v}'.format(v=v) msg = 'underscore.js version does not match to {v}'.format(v=v)
underscore_min = (app.outdir / '_static' / 'underscore.js').text() underscore_min = (app.outdir / '_static' / 'underscore.js').read_text()
assert 'Underscore.js {v}'.format(v=v) in underscore_min, msg assert 'Underscore.js {v}'.format(v=v) in underscore_min, msg
underscore_src = (app.outdir / '_static' / 'underscore-{v}.js'.format(v=v)).text() underscore_src = (app.outdir / '_static' / 'underscore-{v}.js'.format(v=v)).read_text()
assert 'Underscore.js {v}'.format(v=v) in underscore_src, msg assert 'Underscore.js {v}'.format(v=v) in underscore_src, msg
@ -108,12 +108,12 @@ def test_staticfiles(app, status, warning):
app.build() app.build()
assert (app.outdir / '_static' / 'staticimg.png').exists() assert (app.outdir / '_static' / 'staticimg.png').exists()
assert (app.outdir / '_static' / 'statictmpl.html').exists() assert (app.outdir / '_static' / 'statictmpl.html').exists()
assert (app.outdir / '_static' / 'statictmpl.html').text() == ( assert (app.outdir / '_static' / 'statictmpl.html').read_text() == (
'<!-- testing static templates -->\n' '<!-- testing static templates -->\n'
'<html><project>Python</project></html>' '<html><project>Python</project></html>'
) )
result = (app.outdir / 'index.html').text() result = (app.outdir / 'index.html').read_text()
assert '<meta name="testopt" content="optdefault" />' in result assert '<meta name="testopt" content="optdefault" />' in result
@ -122,7 +122,7 @@ def test_theme_sidebars(app, status, warning):
app.build() app.build()
# test-theme specifies globaltoc and searchbox as default sidebars # test-theme specifies globaltoc and searchbox as default sidebars
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert '<h3><a href="#">Table of Contents</a></h3>' in result assert '<h3><a href="#">Table of Contents</a></h3>' in result
assert '<h3>Related Topics</h3>' not in result assert '<h3>Related Topics</h3>' not in result
assert '<h3>This Page</h3>' not in result assert '<h3>This Page</h3>' not in result

View File

@ -41,7 +41,7 @@ def test_singlehtml_toctree(app, status, warning):
@pytest.mark.sphinx(testroot='toctree', srcdir="numbered-toctree") @pytest.mark.sphinx(testroot='toctree', srcdir="numbered-toctree")
def test_numbered_toctree(app, status, warning): def test_numbered_toctree(app, status, warning):
# give argument to :numbered: option # give argument to :numbered: option
index = (app.srcdir / 'index.rst').text() index = (app.srcdir / 'index.rst').read_text()
index = re.sub(':numbered:.*', ':numbered: 1', index) index = re.sub(':numbered:.*', ':numbered: 1', index)
(app.srcdir / 'index.rst').write_text(index) (app.srcdir / 'index.rst').write_text(index)
app.builder.build_all() app.builder.build_all()

View File

@ -13,7 +13,7 @@ import pytest
def test_trim_doctest_flags_html(app, status, warning): def test_trim_doctest_flags_html(app, status, warning):
app.build() app.build()
result = (app.outdir / 'index.html').text(encoding='utf8') result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert 'FOO' not in result assert 'FOO' not in result
assert 'BAR' in result assert 'BAR' in result
assert 'BAZ' not in result assert 'BAZ' not in result
@ -25,7 +25,7 @@ def test_trim_doctest_flags_html(app, status, warning):
def test_trim_doctest_flags_latex(app, status, warning): def test_trim_doctest_flags_latex(app, status, warning):
app.build() app.build()
result = (app.outdir / 'python.tex').text(encoding='utf8') result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert 'FOO' not in result assert 'FOO' not in result
assert 'BAR' in result assert 'BAR' in result
assert 'BAZ' not in result assert 'BAZ' not in result

View File

@ -33,7 +33,7 @@ def test_copy_asset_file(tempdir):
copy_asset_file(src, dest) copy_asset_file(src, dest)
assert dest.exists() assert dest.exists()
assert src.text() == dest.text() assert src.read_text() == dest.read_text()
# copy template file # copy template file
src = (tempdir / 'asset.txt_t') src = (tempdir / 'asset.txt_t')
@ -43,7 +43,7 @@ def test_copy_asset_file(tempdir):
copy_asset_file(src, dest, {'var1': 'template'}, renderer) copy_asset_file(src, dest, {'var1': 'template'}, renderer)
assert not dest.exists() assert not dest.exists()
assert (tempdir / 'output.txt').exists() assert (tempdir / 'output.txt').exists()
assert (tempdir / 'output.txt').text() == '# template data' assert (tempdir / 'output.txt').read_text() == '# template data'
# copy template file to subdir # copy template file to subdir
src = (tempdir / 'asset.txt_t') src = (tempdir / 'asset.txt_t')
@ -53,7 +53,7 @@ def test_copy_asset_file(tempdir):
copy_asset_file(src, subdir1, {'var1': 'template'}, renderer) copy_asset_file(src, subdir1, {'var1': 'template'}, renderer)
assert (subdir1 / 'asset.txt').exists() assert (subdir1 / 'asset.txt').exists()
assert (subdir1 / 'asset.txt').text() == '# template data' assert (subdir1 / 'asset.txt').read_text() == '# template data'
# copy template file without context # copy template file without context
src = (tempdir / 'asset.txt_t') src = (tempdir / 'asset.txt_t')
@ -63,7 +63,7 @@ def test_copy_asset_file(tempdir):
copy_asset_file(src, subdir2) copy_asset_file(src, subdir2)
assert not (subdir2 / 'asset.txt').exists() assert not (subdir2 / 'asset.txt').exists()
assert (subdir2 / 'asset.txt_t').exists() assert (subdir2 / 'asset.txt_t').exists()
assert (subdir2 / 'asset.txt_t').text() == '# {{var1}} data' assert (subdir2 / 'asset.txt_t').read_text() == '# {{var1}} data'
def test_copy_asset(tempdir): def test_copy_asset(tempdir):
@ -91,11 +91,11 @@ def test_copy_asset(tempdir):
copy_asset(source, destdir, context=dict(var1='bar', var2='baz'), renderer=renderer) copy_asset(source, destdir, context=dict(var1='bar', var2='baz'), renderer=renderer)
assert (destdir / 'index.rst').exists() assert (destdir / 'index.rst').exists()
assert (destdir / 'foo.rst').exists() assert (destdir / 'foo.rst').exists()
assert (destdir / 'foo.rst').text() == 'bar.rst' assert (destdir / 'foo.rst').read_text() == 'bar.rst'
assert (destdir / '_static' / 'basic.css').exists() assert (destdir / '_static' / 'basic.css').exists()
assert (destdir / '_templates' / 'layout.html').exists() assert (destdir / '_templates' / 'layout.html').exists()
assert (destdir / '_templates' / 'sidebar.html').exists() assert (destdir / '_templates' / 'sidebar.html').exists()
assert (destdir / '_templates' / 'sidebar.html').text() == 'sidebar: baz' assert (destdir / '_templates' / 'sidebar.html').read_text() == 'sidebar: baz'
# copy with exclusion # copy with exclusion
def excluded(path): def excluded(path):