mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
commit
7970e6c044
@ -70,7 +70,7 @@ def merge_todos(app, env, docnames, other):
|
||||
|
||||
def process_todo_nodes(app, doctree, fromdocname):
|
||||
if not app.config.todo_include_todos:
|
||||
for node in doctree.traverse(todo):
|
||||
for node in doctree.findall(todo):
|
||||
node.parent.remove(node)
|
||||
|
||||
# Replace all todolist nodes with a list of the collected todos.
|
||||
@ -80,7 +80,7 @@ def process_todo_nodes(app, doctree, fromdocname):
|
||||
if not hasattr(env, 'todo_all_todos'):
|
||||
env.todo_all_todos = []
|
||||
|
||||
for node in doctree.traverse(todolist):
|
||||
for node in doctree.findall(todolist):
|
||||
if not app.config.todo_include_todos:
|
||||
node.replace_self([])
|
||||
continue
|
||||
@ -93,7 +93,7 @@ def process_todo_nodes(app, doctree, fromdocname):
|
||||
description = (
|
||||
_('(The original entry is located in %s, line %d and can be found ') %
|
||||
(filename, todo_info['lineno']))
|
||||
para += nodes.Text(description, description)
|
||||
para += nodes.Text(description)
|
||||
|
||||
# Create a reference
|
||||
newnode = nodes.reference('', '')
|
||||
@ -104,7 +104,7 @@ def process_todo_nodes(app, doctree, fromdocname):
|
||||
newnode['refuri'] += '#' + todo_info['target']['refid']
|
||||
newnode.append(innernode)
|
||||
para += newnode
|
||||
para += nodes.Text('.)', '.)')
|
||||
para += nodes.Text('.)')
|
||||
|
||||
# Insert into the todolist
|
||||
content.append(todo_info['todo'])
|
||||
|
2
setup.py
2
setup.py
@ -4,7 +4,7 @@ from setuptools import find_packages, setup
|
||||
|
||||
import sphinx
|
||||
|
||||
with open('README.rst') as f:
|
||||
with open('README.rst', encoding='utf-8') as f:
|
||||
long_desc = f.read()
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
|
@ -18,6 +18,8 @@ if 'PYTHONWARNINGS' not in os.environ:
|
||||
# docutils.io using mode='rU' for open
|
||||
warnings.filterwarnings('ignore', "'U' mode is deprecated",
|
||||
DeprecationWarning, module='docutils.io')
|
||||
warnings.filterwarnings('ignore', 'The frontend.Option class .*',
|
||||
DeprecationWarning, module='docutils.frontend')
|
||||
|
||||
__version__ = '5.0.0+'
|
||||
__released__ = '5.0.0' # used when Sphinx builds its own docs
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Sequence
|
||||
|
||||
import docutils
|
||||
from docutils import nodes
|
||||
from docutils.nodes import Element
|
||||
|
||||
@ -28,7 +29,6 @@ class document(nodes.document):
|
||||
|
||||
def set_id(self, node: Element, msgnode: Element = None,
|
||||
suggested_prefix: str = '') -> str:
|
||||
from sphinx.util import docutils
|
||||
if docutils.__version_info__ >= (0, 16):
|
||||
ret = super().set_id(node, msgnode, suggested_prefix) # type: ignore
|
||||
else:
|
||||
@ -527,8 +527,6 @@ class manpage(nodes.Inline, nodes.FixedTextElement):
|
||||
|
||||
|
||||
def setup(app: "Sphinx") -> Dict[str, Any]:
|
||||
from sphinx.util import docutils # lazy import
|
||||
|
||||
app.add_node(toctree)
|
||||
|
||||
app.add_node(desc)
|
||||
|
@ -483,7 +483,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
metadata['copyright'] = html.escape(self.config.epub_copyright)
|
||||
metadata['scheme'] = html.escape(self.config.epub_scheme)
|
||||
metadata['id'] = html.escape(self.config.epub_identifier)
|
||||
metadata['date'] = html.escape(format_date("%Y-%m-%d"))
|
||||
metadata['date'] = html.escape(format_date("%Y-%m-%d", language='en'))
|
||||
metadata['manifest_items'] = []
|
||||
metadata['spines'] = []
|
||||
metadata['guides'] = []
|
||||
|
@ -88,7 +88,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
|
||||
metadata['contributor'] = html.escape(self.config.epub_contributor)
|
||||
metadata['page_progression_direction'] = PAGE_PROGRESSION_DIRECTIONS.get(writing_mode)
|
||||
metadata['ibook_scroll_axis'] = IBOOK_SCROLL_AXIS.get(writing_mode)
|
||||
metadata['date'] = html.escape(format_date("%Y-%m-%dT%H:%M:%SZ"))
|
||||
metadata['date'] = html.escape(format_date("%Y-%m-%dT%H:%M:%SZ", language='en'))
|
||||
metadata['version'] = html.escape(self.config.version)
|
||||
metadata['epub_version'] = self.config.epub_version
|
||||
return metadata
|
||||
|
@ -5,6 +5,7 @@ import os
|
||||
import posixpath
|
||||
import re
|
||||
import sys
|
||||
import warnings
|
||||
from datetime import datetime
|
||||
from os import path
|
||||
from typing import IO, Any, Dict, Iterable, Iterator, List, Optional, Set, Tuple, Type
|
||||
@ -370,7 +371,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
|
||||
def get_outdated_docs(self) -> Iterator[str]:
|
||||
try:
|
||||
with open(path.join(self.outdir, '.buildinfo')) as fp:
|
||||
with open(path.join(self.outdir, '.buildinfo'), encoding="utf-8") as fp:
|
||||
buildinfo = BuildInfo.load(fp)
|
||||
|
||||
if self.build_info != buildinfo:
|
||||
@ -443,10 +444,14 @@ class StandaloneHTMLBuilder(Builder):
|
||||
self.load_indexer(docnames)
|
||||
|
||||
self.docwriter = HTMLWriter(self)
|
||||
self.docsettings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(self.docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
# DeprecationWarning: The frontend.OptionParser class will be replaced
|
||||
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
|
||||
self.docsettings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(self.docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
self.docsettings.compact_lists = bool(self.config.html_compact_lists)
|
||||
|
||||
# determine the additional indices to include
|
||||
@ -763,11 +768,13 @@ class StandaloneHTMLBuilder(Builder):
|
||||
|
||||
def create_pygments_style_file(self) -> None:
|
||||
"""create a style file for pygments."""
|
||||
with open(path.join(self.outdir, '_static', 'pygments.css'), 'w') as f:
|
||||
with open(path.join(self.outdir, '_static', 'pygments.css'), 'w',
|
||||
encoding="utf-8") as f:
|
||||
f.write(self.highlighter.get_stylesheet())
|
||||
|
||||
if self.dark_highlighter:
|
||||
with open(path.join(self.outdir, '_static', 'pygments_dark.css'), 'w') as f:
|
||||
with open(path.join(self.outdir, '_static', 'pygments_dark.css'), 'w',
|
||||
encoding="utf-8") as f:
|
||||
f.write(self.dark_highlighter.get_stylesheet())
|
||||
|
||||
def copy_translation_js(self) -> None:
|
||||
@ -853,7 +860,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
|
||||
def write_buildinfo(self) -> None:
|
||||
try:
|
||||
with open(path.join(self.outdir, '.buildinfo'), 'w') as fp:
|
||||
with open(path.join(self.outdir, '.buildinfo'), 'w', encoding="utf-8") as fp:
|
||||
self.build_info.dump(fp)
|
||||
except OSError as exc:
|
||||
logger.warning(__('Failed to write build info file: %r'), exc)
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""LaTeX builder."""
|
||||
|
||||
import os
|
||||
import warnings
|
||||
from os import path
|
||||
from typing import Any, Dict, Iterable, List, Tuple, Union
|
||||
|
||||
@ -241,7 +242,7 @@ class LaTeXBuilder(Builder):
|
||||
def write_stylesheet(self) -> None:
|
||||
highlighter = highlighting.PygmentsBridge('latex', self.config.pygments_style)
|
||||
stylesheet = path.join(self.outdir, 'sphinxhighlight.sty')
|
||||
with open(stylesheet, 'w') as f:
|
||||
with open(stylesheet, 'w', encoding="utf-8") as f:
|
||||
f.write('\\NeedsTeXFormat{LaTeX2e}[1995/12/01]\n')
|
||||
f.write('\\ProvidesPackage{sphinxhighlight}'
|
||||
'[2016/05/29 stylesheet for highlighting with pygments]\n')
|
||||
@ -250,10 +251,14 @@ class LaTeXBuilder(Builder):
|
||||
|
||||
def write(self, *ignored: Any) -> None:
|
||||
docwriter = LaTeXWriter(self)
|
||||
docsettings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
# DeprecationWarning: The frontend.OptionParser class will be replaced
|
||||
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
|
||||
docsettings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
|
||||
self.init_document_data()
|
||||
self.write_stylesheet()
|
||||
@ -347,9 +352,9 @@ class LaTeXBuilder(Builder):
|
||||
newnodes: List[Node] = [nodes.emphasis(sectname, sectname)]
|
||||
for subdir, title in self.titles:
|
||||
if docname.startswith(subdir):
|
||||
newnodes.append(nodes.Text(_(' (in '), _(' (in ')))
|
||||
newnodes.append(nodes.Text(_(' (in ')))
|
||||
newnodes.append(nodes.emphasis(title, title))
|
||||
newnodes.append(nodes.Text(')', ')'))
|
||||
newnodes.append(nodes.Text(')'))
|
||||
break
|
||||
else:
|
||||
pass
|
||||
|
@ -73,7 +73,7 @@ class UserTheme(Theme):
|
||||
def __init__(self, name: str, filename: str) -> None:
|
||||
super().__init__(name)
|
||||
self.config = configparser.RawConfigParser()
|
||||
self.config.read(path.join(filename))
|
||||
self.config.read(path.join(filename), encoding='utf-8')
|
||||
|
||||
for key in self.REQUIRED_CONFIG_KEYS:
|
||||
try:
|
||||
|
@ -184,8 +184,10 @@ class CheckExternalLinksBuilder(DummyBuilder):
|
||||
checker = HyperlinkAvailabilityChecker(self.env, self.config)
|
||||
logger.info('')
|
||||
|
||||
with open(path.join(self.outdir, 'output.txt'), 'w') as self.txt_outfile,\
|
||||
open(path.join(self.outdir, 'output.json'), 'w') as self.json_outfile:
|
||||
output_text = path.join(self.outdir, 'output.txt')
|
||||
output_json = path.join(self.outdir, 'output.json')
|
||||
with open(output_text, 'w', encoding="utf-8") as self.txt_outfile,\
|
||||
open(output_json, 'w', encoding="utf-8") as self.json_outfile:
|
||||
for result in checker.check(self.hyperlinks):
|
||||
self.process_result(result)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Manual pages builder."""
|
||||
|
||||
import warnings
|
||||
from os import path
|
||||
from typing import Any, Dict, List, Set, Tuple, Union
|
||||
|
||||
@ -45,10 +46,14 @@ class ManualPageBuilder(Builder):
|
||||
@progress_message(__('writing'))
|
||||
def write(self, *ignored: Any) -> None:
|
||||
docwriter = ManualPageWriter(self)
|
||||
docsettings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
# DeprecationWarning: The frontend.OptionParser class will be replaced
|
||||
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
|
||||
docsettings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
|
||||
for info in self.config.man_pages:
|
||||
docname, name, description, authors, section = info
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Texinfo builder."""
|
||||
|
||||
import os
|
||||
import warnings
|
||||
from os import path
|
||||
from typing import Any, Dict, Iterable, List, Tuple, Union
|
||||
|
||||
@ -101,10 +102,14 @@ class TexinfoBuilder(Builder):
|
||||
with progress_message(__("writing")):
|
||||
self.post_process_images(doctree)
|
||||
docwriter = TexinfoWriter(self)
|
||||
settings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
# DeprecationWarning: The frontend.OptionParser class will be replaced
|
||||
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
|
||||
settings: Any = OptionParser(
|
||||
defaults=self.env.settings,
|
||||
components=(docwriter,),
|
||||
read_config_files=True).get_default_values()
|
||||
settings.author = author
|
||||
settings.title = title
|
||||
settings.texinfo_filename = targetname[:-5] + '.info'
|
||||
@ -150,9 +155,9 @@ class TexinfoBuilder(Builder):
|
||||
newnodes: List[Node] = [nodes.emphasis(sectname, sectname)]
|
||||
for subdir, title in self.titles:
|
||||
if docname.startswith(subdir):
|
||||
newnodes.append(nodes.Text(_(' (in '), _(' (in ')))
|
||||
newnodes.append(nodes.Text(_(' (in ')))
|
||||
newnodes.append(nodes.emphasis(title, title))
|
||||
newnodes.append(nodes.Text(')', ')'))
|
||||
newnodes.append(nodes.Text(')'))
|
||||
break
|
||||
else:
|
||||
pass
|
||||
|
@ -236,7 +236,7 @@ def build_main(argv: List[str] = sys.argv[1:]) -> int:
|
||||
try:
|
||||
warnfile = abspath(args.warnfile)
|
||||
ensuredir(path.dirname(warnfile))
|
||||
warnfp = open(args.warnfile, 'w')
|
||||
warnfp = open(args.warnfile, 'w', encoding="utf-8")
|
||||
except Exception as exc:
|
||||
parser.error(__('cannot open warning file %r: %s') % (
|
||||
args.warnfile, exc))
|
||||
|
@ -367,7 +367,7 @@ def generate(d: Dict, overwrite: bool = True, silent: bool = False, templatedir:
|
||||
conf_path = os.path.join(templatedir, 'conf.py_t') if templatedir else None
|
||||
if not conf_path or not path.isfile(conf_path):
|
||||
conf_path = os.path.join(package_dir, 'templates', 'quickstart', 'conf.py_t')
|
||||
with open(conf_path) as f:
|
||||
with open(conf_path, encoding="utf-8") as f:
|
||||
conf_text = f.read()
|
||||
|
||||
write_file(path.join(srcdir, 'conf.py'), template.render_string(conf_text, d))
|
||||
|
@ -405,7 +405,7 @@ def correct_copyright_year(app: "Sphinx", config: Config) -> None:
|
||||
if getenv('SOURCE_DATE_EPOCH') is not None:
|
||||
for k in ('copyright', 'epub_copyright'):
|
||||
if k in config:
|
||||
replace = r'\g<1>%s' % format_date('%Y')
|
||||
replace = r'\g<1>%s' % format_date('%Y', language='en')
|
||||
config[k] = copyright_year_re.sub(replace, config[k])
|
||||
|
||||
|
||||
|
@ -172,7 +172,7 @@ class Author(SphinxDirective):
|
||||
text = _('Code author: ')
|
||||
else:
|
||||
text = _('Author: ')
|
||||
emph += nodes.Text(text, text)
|
||||
emph += nodes.Text(text)
|
||||
inodes, messages = self.state.inline_text(self.arguments[0], self.lineno)
|
||||
emph.extend(inodes)
|
||||
|
||||
|
@ -102,7 +102,7 @@ class IndexRole(ReferenceRole):
|
||||
|
||||
index = addnodes.index(entries=entries)
|
||||
target = nodes.target('', '', ids=[target_id])
|
||||
text = nodes.Text(title, title)
|
||||
text = nodes.Text(title)
|
||||
self.set_source_info(index)
|
||||
return [index, target, text], []
|
||||
|
||||
|
@ -416,7 +416,7 @@ def token_xrefs(text: str, productionGroup: str = '') -> List[Node]:
|
||||
for m in token_re.finditer(text):
|
||||
if m.start() > pos:
|
||||
txt = text[pos:m.start()]
|
||||
retnodes.append(nodes.Text(txt, txt))
|
||||
retnodes.append(nodes.Text(txt))
|
||||
token = m.group(1)
|
||||
if ':' in token:
|
||||
if token[0] == '~':
|
||||
@ -437,7 +437,7 @@ def token_xrefs(text: str, productionGroup: str = '') -> List[Node]:
|
||||
retnodes.append(refnode)
|
||||
pos = m.end()
|
||||
if pos < len(text):
|
||||
retnodes.append(nodes.Text(text[pos:], text[pos:]))
|
||||
retnodes.append(nodes.Text(text[pos:]))
|
||||
return retnodes
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@ from os import path
|
||||
from typing import (TYPE_CHECKING, Any, Callable, Dict, Generator, Iterator, List, Optional,
|
||||
Set, Tuple, Union)
|
||||
|
||||
import docutils
|
||||
from docutils import nodes
|
||||
from docutils.nodes import Node
|
||||
|
||||
@ -38,7 +39,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
default_settings: Dict[str, Any] = {
|
||||
'auto_id_prefix': 'id',
|
||||
'embed_images': False,
|
||||
'image_loading': 'link',
|
||||
'embed_stylesheet': False,
|
||||
'cloak_email_addresses': True,
|
||||
'pep_base_url': 'https://peps.python.org/',
|
||||
@ -53,6 +54,8 @@ default_settings: Dict[str, Any] = {
|
||||
'file_insertion_enabled': True,
|
||||
'smartquotes_locales': [],
|
||||
}
|
||||
if docutils.__version_info__[:2] <= (0, 17):
|
||||
default_settings['embed_images'] = False
|
||||
|
||||
# This is increased every time an environment attribute is added
|
||||
# or changed to properly invalidate pickle files.
|
||||
|
@ -90,7 +90,7 @@ class CoverageBuilder(Builder):
|
||||
c_objects = self.env.domaindata['c']['objects']
|
||||
for filename in self.c_sourcefiles:
|
||||
undoc: Set[Tuple[str, str]] = set()
|
||||
with open(filename) as f:
|
||||
with open(filename, encoding="utf-8") as f:
|
||||
for line in f:
|
||||
for key, regex in self.c_regexes:
|
||||
match = regex.match(line)
|
||||
@ -108,7 +108,7 @@ class CoverageBuilder(Builder):
|
||||
|
||||
def write_c_coverage(self) -> None:
|
||||
output_file = path.join(self.outdir, 'c.txt')
|
||||
with open(output_file, 'w') as op:
|
||||
with open(output_file, 'w', encoding="utf-8") as op:
|
||||
if self.config.coverage_write_headline:
|
||||
write_header(op, 'Undocumented C API elements', '=')
|
||||
op.write('\n')
|
||||
@ -227,7 +227,7 @@ class CoverageBuilder(Builder):
|
||||
def write_py_coverage(self) -> None:
|
||||
output_file = path.join(self.outdir, 'python.txt')
|
||||
failed = []
|
||||
with open(output_file, 'w') as op:
|
||||
with open(output_file, 'w', encoding="utf-8") as op:
|
||||
if self.config.coverage_write_headline:
|
||||
write_header(op, 'Undocumented Python objects', '=')
|
||||
keys = sorted(self.py_undoc.keys())
|
||||
|
@ -11,13 +11,14 @@ from sphinx.environment import BuildEnvironment
|
||||
|
||||
def create_nojekyll_and_cname(app: Sphinx, env: BuildEnvironment) -> None:
|
||||
if app.builder.format == 'html':
|
||||
open(os.path.join(app.builder.outdir, '.nojekyll'), 'wt').close()
|
||||
open(os.path.join(app.builder.outdir, '.nojekyll'), 'wb').close()
|
||||
|
||||
html_baseurl = app.config.html_baseurl
|
||||
if html_baseurl:
|
||||
domain = urllib.parse.urlparse(html_baseurl).hostname
|
||||
if domain and not domain.endswith(".github.io"):
|
||||
with open(os.path.join(app.builder.outdir, 'CNAME'), 'wt') as f:
|
||||
with open(os.path.join(app.builder.outdir, 'CNAME'), 'w',
|
||||
encoding="utf-8") as f:
|
||||
# NOTE: don't write a trailing newline. The `CNAME` file that's
|
||||
# auto-generated by the Github UI doesn't have one.
|
||||
f.write(domain)
|
||||
|
@ -56,7 +56,7 @@ depthsvgcomment_re = re.compile(r'<!-- DEPTH=(-?\d+) -->')
|
||||
def read_svg_depth(filename: str) -> int:
|
||||
"""Read the depth from comment at last line of SVG file
|
||||
"""
|
||||
with open(filename) as f:
|
||||
with open(filename, encoding="utf-8") as f:
|
||||
for line in f: # noqa: B007
|
||||
pass
|
||||
# Only last line is checked
|
||||
@ -69,7 +69,7 @@ def read_svg_depth(filename: str) -> int:
|
||||
def write_svg_depth(filename: str, depth: int) -> None:
|
||||
"""Write the depth to SVG file as a comment at end of file
|
||||
"""
|
||||
with open(filename, 'a') as f:
|
||||
with open(filename, 'a', encoding="utf-8") as f:
|
||||
f.write('\n<!-- DEPTH=%s -->' % depth)
|
||||
|
||||
|
||||
|
@ -572,7 +572,7 @@ class IntersphinxRoleResolver(ReferencesResolver):
|
||||
default_priority = ReferencesResolver.default_priority - 1
|
||||
|
||||
def run(self, **kwargs: Any) -> None:
|
||||
for node in self.document.traverse(pending_xref):
|
||||
for node in self.document.findall(pending_xref):
|
||||
if 'intersphinx' not in node:
|
||||
continue
|
||||
contnode = cast(nodes.TextElement, node[0].deepcopy())
|
||||
|
@ -159,7 +159,7 @@ class TodoListProcessor:
|
||||
suffix = description[description.find('>>') + 2:]
|
||||
|
||||
para = nodes.paragraph(classes=['todo-source'])
|
||||
para += nodes.Text(prefix, prefix)
|
||||
para += nodes.Text(prefix)
|
||||
|
||||
# Create a reference
|
||||
linktext = nodes.emphasis(_('original entry'), _('original entry'))
|
||||
@ -172,7 +172,7 @@ class TodoListProcessor:
|
||||
pass
|
||||
|
||||
para += reference
|
||||
para += nodes.Text(suffix, suffix)
|
||||
para += nodes.Text(suffix)
|
||||
|
||||
return para
|
||||
|
||||
|
@ -293,7 +293,7 @@ class EmphasizedLiteral(SphinxRole):
|
||||
if len(stack) == 3 and stack[1] == "{" and len(stack[2]) > 0:
|
||||
# emphasized word found
|
||||
if stack[0]:
|
||||
result.append(nodes.Text(stack[0], stack[0]))
|
||||
result.append(nodes.Text(stack[0]))
|
||||
result.append(nodes.emphasis(stack[2], stack[2]))
|
||||
stack = ['']
|
||||
else:
|
||||
@ -310,7 +310,7 @@ class EmphasizedLiteral(SphinxRole):
|
||||
if ''.join(stack):
|
||||
# remaining is treated as Text
|
||||
text = ''.join(stack)
|
||||
result.append(nodes.Text(text, text))
|
||||
result.append(nodes.Text(text))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -449,9 +449,9 @@ class IndexBuilder:
|
||||
"""Returns JS code that will be inserted into language_data.js."""
|
||||
if self.lang.js_stemmer_rawcode:
|
||||
js_dir = path.join(package_dir, 'search', 'minified-js')
|
||||
with open(path.join(js_dir, 'base-stemmer.js')) as js_file:
|
||||
with open(path.join(js_dir, 'base-stemmer.js'), encoding='utf-8') as js_file:
|
||||
base_js = js_file.read()
|
||||
with open(path.join(js_dir, self.lang.js_stemmer_rawcode)) as js_file:
|
||||
with open(path.join(js_dir, self.lang.js_stemmer_rawcode), encoding='utf-8') as js_file:
|
||||
language_js = js_file.read()
|
||||
return ('%s\n%s\nStemmer = %sStemmer;' %
|
||||
(base_js, language_js, self.lang.language_name))
|
||||
|
@ -64,7 +64,7 @@ class Theme:
|
||||
extract_zip(theme_path, self.themedir)
|
||||
|
||||
self.config = configparser.RawConfigParser()
|
||||
self.config.read(path.join(self.themedir, THEMECONF))
|
||||
self.config.read(path.join(self.themedir, THEMECONF), encoding='utf-8')
|
||||
|
||||
try:
|
||||
inherit = self.config.get('theme', 'inherit')
|
||||
|
@ -5,6 +5,7 @@ import unicodedata
|
||||
import warnings
|
||||
from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional, Tuple, cast
|
||||
|
||||
import docutils
|
||||
from docutils import nodes
|
||||
from docutils.nodes import Element, Node, Text
|
||||
from docutils.transforms import Transform, Transformer
|
||||
@ -17,7 +18,7 @@ from sphinx import addnodes
|
||||
from sphinx.config import Config
|
||||
from sphinx.deprecation import RemovedInSphinx60Warning
|
||||
from sphinx.locale import _, __
|
||||
from sphinx.util import docutils, logging
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.docutils import new_document
|
||||
from sphinx.util.i18n import format_date
|
||||
from sphinx.util.nodes import NodeMatcher, apply_source_workaround, is_smartquotable
|
||||
@ -108,7 +109,7 @@ class DefaultSubstitutions(SphinxTransform):
|
||||
# special handling: can also specify a strftime format
|
||||
text = format_date(self.config.today_fmt or _('%b %d, %Y'),
|
||||
language=self.config.language)
|
||||
ref.replace_self(nodes.Text(text, text))
|
||||
ref.replace_self(nodes.Text(text))
|
||||
|
||||
|
||||
class MoveModuleTargets(SphinxTransform):
|
||||
|
@ -128,7 +128,7 @@ class ASTCPPAttribute(ASTAttribute):
|
||||
|
||||
def describe_signature(self, signode: TextElement) -> None:
|
||||
signode.append(addnodes.desc_sig_punctuation('[[', '[['))
|
||||
signode.append(nodes.Text(self.arg, self.arg))
|
||||
signode.append(nodes.Text(self.arg))
|
||||
signode.append(addnodes.desc_sig_punctuation(']]', ']]'))
|
||||
|
||||
|
||||
@ -161,7 +161,7 @@ class ASTGnuAttributeList(ASTAttribute):
|
||||
|
||||
def describe_signature(self, signode: TextElement) -> None:
|
||||
txt = str(self)
|
||||
signode.append(nodes.Text(txt, txt))
|
||||
signode.append(nodes.Text(txt))
|
||||
|
||||
|
||||
class ASTIdAttribute(ASTAttribute):
|
||||
@ -174,7 +174,7 @@ class ASTIdAttribute(ASTAttribute):
|
||||
return self.id
|
||||
|
||||
def describe_signature(self, signode: TextElement) -> None:
|
||||
signode.append(nodes.Text(self.id, self.id))
|
||||
signode.append(nodes.Text(self.id))
|
||||
|
||||
|
||||
class ASTParenAttribute(ASTAttribute):
|
||||
@ -189,7 +189,7 @@ class ASTParenAttribute(ASTAttribute):
|
||||
|
||||
def describe_signature(self, signode: TextElement) -> None:
|
||||
txt = str(self)
|
||||
signode.append(nodes.Text(txt, txt))
|
||||
signode.append(nodes.Text(txt))
|
||||
|
||||
|
||||
class ASTAttributeList(ASTBaseBase):
|
||||
|
@ -17,8 +17,8 @@ from docutils.parsers.rst import Directive, directives, roles
|
||||
from docutils.parsers.rst.states import Inliner
|
||||
from docutils.statemachine import State, StateMachine, StringList
|
||||
from docutils.utils import Reporter, unescape
|
||||
from packaging import version
|
||||
|
||||
from sphinx.deprecation import RemovedInSphinx60Warning, deprecated_alias
|
||||
from sphinx.errors import SphinxError
|
||||
from sphinx.locale import _, __
|
||||
from sphinx.util import logging
|
||||
@ -32,8 +32,14 @@ if TYPE_CHECKING:
|
||||
from sphinx.config import Config
|
||||
from sphinx.environment import BuildEnvironment
|
||||
|
||||
|
||||
__version_info__ = version.parse(docutils.__version__).release
|
||||
deprecated_alias('sphinx.util.docutils',
|
||||
{
|
||||
'__version_info__': docutils.__version_info__,
|
||||
},
|
||||
RemovedInSphinx60Warning,
|
||||
{
|
||||
'__version_info__': 'docutils.__version_info__',
|
||||
})
|
||||
additional_nodes: Set[Type[Element]] = set()
|
||||
|
||||
|
||||
@ -312,7 +318,7 @@ class NullReporter(Reporter):
|
||||
|
||||
|
||||
def is_html5_writer_available() -> bool:
|
||||
return __version_info__ > (0, 13, 0)
|
||||
return docutils.__version_info__ > (0, 13, 0)
|
||||
|
||||
|
||||
@contextmanager
|
||||
@ -338,6 +344,7 @@ class SphinxFileOutput(FileOutput):
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
self.overwrite_if_changed = kwargs.pop('overwrite_if_changed', False)
|
||||
kwargs.setdefault('encoding', 'utf-8')
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def write(self, data: str) -> str:
|
||||
@ -542,7 +549,7 @@ class SphinxTranslator(nodes.NodeVisitor):
|
||||
# Node.findall() is a new interface to traverse a doctree since docutils-0.18.
|
||||
# This applies a patch docutils-0.17 or older to be available Node.findall()
|
||||
# method to use it from our codebase.
|
||||
if __version_info__ < (0, 18):
|
||||
if docutils.__version_info__ < (0, 18):
|
||||
def findall(self, *args, **kwargs):
|
||||
return iter(self.traverse(*args, **kwargs))
|
||||
|
||||
|
@ -27,10 +27,10 @@ import re
|
||||
import warnings
|
||||
from typing import Generator, Iterable, Tuple
|
||||
|
||||
from docutils import __version_info__ as docutils_version
|
||||
from docutils.utils import smartquotes
|
||||
|
||||
from sphinx.deprecation import RemovedInSphinx60Warning
|
||||
from sphinx.util.docutils import __version_info__ as docutils_version
|
||||
|
||||
warnings.warn('sphinx.util.smartypants is deprecated.',
|
||||
RemovedInSphinx60Warning)
|
||||
|
@ -10,6 +10,6 @@ if __name__ == "__main__":
|
||||
|
||||
res_path = \
|
||||
os.path.join(os.path.dirname(mod_resource.__file__), 'resource.txt')
|
||||
with open(res_path) as f:
|
||||
with open(res_path, encoding='utf-8') as f:
|
||||
text = f.read()
|
||||
print("From mod_resource:resource.txt -> {}".format(text))
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
import sys
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
|
||||
from sphinx.util import docutils
|
||||
|
||||
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
def setup_module(rootdir):
|
||||
|
@ -37,14 +37,14 @@ def nonascii_srcdir(request, rootdir, sphinx_test_tempdir):
|
||||
(srcdir / (test_name + '.txt')).write_text(dedent("""
|
||||
nonascii file name page
|
||||
=======================
|
||||
"""))
|
||||
"""), encoding='utf8')
|
||||
|
||||
root_doc = srcdir / 'index.txt'
|
||||
root_doc.write_text(root_doc.read_text() + dedent("""
|
||||
root_doc.write_text(root_doc.read_text(encoding='utf8') + dedent("""
|
||||
.. toctree::
|
||||
|
||||
%(test_name)s/%(test_name)s
|
||||
""" % {'test_name': test_name}))
|
||||
""" % {'test_name': test_name}), encoding='utf8')
|
||||
return srcdir
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ def test_build_all(requests_head, make_app, nonascii_srcdir, buildername):
|
||||
|
||||
|
||||
def test_root_doc_not_found(tempdir, make_app):
|
||||
(tempdir / 'conf.py').write_text('')
|
||||
(tempdir / 'conf.py').write_text('', encoding='utf8')
|
||||
assert tempdir.listdir() == ['conf.py']
|
||||
|
||||
app = make_app('dummy', srcdir=tempdir)
|
||||
|
@ -8,7 +8,7 @@ def test_build(app):
|
||||
app.build()
|
||||
|
||||
# TODO: Use better checking of html content
|
||||
htmltext = (app.outdir / 'changes.html').read_text()
|
||||
htmltext = (app.outdir / 'changes.html').read_text(encoding='utf8')
|
||||
assert 'New in version 0.6: Some 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
|
||||
|
@ -17,7 +17,7 @@ def test_dirhtml(app, status, warning):
|
||||
assert (app.outdir / 'foo/foo_2/index.html').exists()
|
||||
assert (app.outdir / 'bar/index.html').exists()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert 'href="foo/"' in content
|
||||
assert 'href="foo/foo_1/"' in content
|
||||
assert 'href="foo/foo_2/"' in content
|
||||
|
@ -57,11 +57,11 @@ class EPUBElementTree:
|
||||
@pytest.mark.sphinx('epub', testroot='basic')
|
||||
def test_build_epub(app):
|
||||
app.build()
|
||||
assert (app.outdir / 'mimetype').read_text() == 'application/epub+zip'
|
||||
assert (app.outdir / 'mimetype').read_text(encoding='utf8') == 'application/epub+zip'
|
||||
assert (app.outdir / 'META-INF' / 'container.xml').exists()
|
||||
|
||||
# toc.ncx
|
||||
toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').read_text())
|
||||
toc = EPUBElementTree.fromstring((app.outdir / 'toc.ncx').read_text(encoding='utf8'))
|
||||
assert toc.find("./ncx:docTitle/ncx:text").text == 'Python'
|
||||
|
||||
# toc.ncx / head
|
||||
@ -81,7 +81,7 @@ def test_build_epub(app):
|
||||
assert navlabel.text == 'The basic Sphinx documentation for testing'
|
||||
|
||||
# content.opf
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text(encoding='utf8'))
|
||||
|
||||
# content.opf / metadata
|
||||
metadata = opf.find("./idpf:metadata")
|
||||
@ -133,7 +133,7 @@ def test_build_epub(app):
|
||||
assert reference.get('href') == 'index.xhtml'
|
||||
|
||||
# nav.xhtml
|
||||
nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').read_text())
|
||||
nav = EPUBElementTree.fromstring((app.outdir / 'nav.xhtml').read_text(encoding='utf8'))
|
||||
assert nav.attrib == {'lang': 'en',
|
||||
'{http://www.w3.org/XML/1998/namespace}lang': 'en'}
|
||||
assert nav.find("./xhtml:head/xhtml:title").text == 'Table of Contents'
|
||||
@ -153,7 +153,7 @@ def test_epub_cover(app):
|
||||
app.build()
|
||||
|
||||
# content.opf / metadata
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text(encoding='utf8'))
|
||||
cover_image = opf.find("./idpf:manifest/idpf:item[@href='%s']" % app.config.epub_cover[0])
|
||||
cover = opf.find("./idpf:metadata/idpf:meta[@name='cover']")
|
||||
assert cover
|
||||
@ -276,7 +276,7 @@ def test_epub_writing_mode(app):
|
||||
app.build()
|
||||
|
||||
# horizontal / page-progression-direction
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text(encoding='utf8'))
|
||||
assert opf.find("./idpf:spine").get('page-progression-direction') == 'ltr'
|
||||
|
||||
# horizontal / ibooks:scroll-axis
|
||||
@ -284,7 +284,7 @@ def test_epub_writing_mode(app):
|
||||
assert metadata.find("./idpf:meta[@property='ibooks:scroll-axis']").text == 'vertical'
|
||||
|
||||
# horizontal / writing-mode (CSS)
|
||||
css = (app.outdir / '_static' / 'epub.css').read_text()
|
||||
css = (app.outdir / '_static' / 'epub.css').read_text(encoding='utf8')
|
||||
assert 'writing-mode: horizontal-tb;' in css
|
||||
|
||||
# vertical
|
||||
@ -293,7 +293,7 @@ def test_epub_writing_mode(app):
|
||||
app.build()
|
||||
|
||||
# vertical / page-progression-direction
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text())
|
||||
opf = EPUBElementTree.fromstring((app.outdir / 'content.opf').read_text(encoding='utf8'))
|
||||
assert opf.find("./idpf:spine").get('page-progression-direction') == 'rtl'
|
||||
|
||||
# vertical / ibooks:scroll-axis
|
||||
@ -301,7 +301,7 @@ def test_epub_writing_mode(app):
|
||||
assert metadata.find("./idpf:meta[@property='ibooks:scroll-axis']").text == 'horizontal'
|
||||
|
||||
# vertical / writing-mode (CSS)
|
||||
css = (app.outdir / '_static' / 'epub.css').read_text()
|
||||
css = (app.outdir / '_static' / 'epub.css').read_text(encoding='utf8')
|
||||
assert 'writing-mode: vertical-rl;' in css
|
||||
|
||||
|
||||
@ -309,7 +309,7 @@ def test_epub_writing_mode(app):
|
||||
def test_epub_anchor_id(app):
|
||||
app.build()
|
||||
|
||||
html = (app.outdir / 'index.xhtml').read_text()
|
||||
html = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
|
||||
assert ('<p id="std-setting-STATICFILES_FINDERS">'
|
||||
'blah blah blah</p>' in html)
|
||||
assert ('<span id="std-setting-STATICFILES_SECTION"></span>'
|
||||
@ -322,7 +322,7 @@ def test_epub_assets(app):
|
||||
app.builder.build_all()
|
||||
|
||||
# epub_sytlesheets (same as html_css_files)
|
||||
content = (app.outdir / 'index.xhtml').read_text()
|
||||
content = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
|
||||
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" '
|
||||
@ -335,7 +335,7 @@ def test_epub_css_files(app):
|
||||
app.builder.build_all()
|
||||
|
||||
# epub_css_files
|
||||
content = (app.outdir / 'index.xhtml').read_text()
|
||||
content = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
|
||||
assert '<link rel="stylesheet" type="text/css" href="_static/css/epub.css" />' in content
|
||||
|
||||
# files in html_css_files are not outputted
|
||||
@ -350,7 +350,7 @@ def test_html_download_role(app, status, warning):
|
||||
app.build()
|
||||
assert not (app.outdir / '_downloads' / 'dummy.dat').exists()
|
||||
|
||||
content = (app.outdir / 'index.xhtml').read_text()
|
||||
content = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
|
||||
assert ('<li><p><code class="xref download docutils literal notranslate">'
|
||||
'<span class="pre">dummy.dat</span></code></p></li>' in content)
|
||||
assert ('<li><p><code class="xref download docutils literal notranslate">'
|
||||
|
@ -23,7 +23,7 @@ def test_build_gettext(app):
|
||||
assert (app.outdir / 'subdir.pot').isfile()
|
||||
|
||||
# regression test for issue #960
|
||||
catalog = (app.outdir / 'markup.pot').read_text()
|
||||
catalog = (app.outdir / 'markup.pot').read_text(encoding='utf8')
|
||||
assert 'msgid "something, something else, something more"' in catalog
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@ def test_gettext_index_entries(app):
|
||||
return m.groups()[0]
|
||||
return None
|
||||
|
||||
pot = (app.outdir / 'index_entries.pot').read_text()
|
||||
pot = (app.outdir / 'index_entries.pot').read_text(encoding='utf8')
|
||||
msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f]
|
||||
|
||||
expected_msgids = [
|
||||
@ -125,7 +125,7 @@ def test_gettext_disable_index_entries(app):
|
||||
return m.groups()[0]
|
||||
return None
|
||||
|
||||
pot = (app.outdir / 'index_entries.pot').read_text()
|
||||
pot = (app.outdir / 'index_entries.pot').read_text(encoding='utf8')
|
||||
msgids = [_f for _f in map(msgid_getter, pot.splitlines()) if _f]
|
||||
|
||||
expected_msgids = [
|
||||
@ -148,7 +148,7 @@ def test_gettext_template(app):
|
||||
app.builder.build_all()
|
||||
assert (app.outdir / 'sphinx.pot').isfile()
|
||||
|
||||
result = (app.outdir / 'sphinx.pot').read_text()
|
||||
result = (app.outdir / 'sphinx.pot').read_text(encoding='utf8')
|
||||
assert "Welcome" in result
|
||||
assert "Sphinx %(version)s" in result
|
||||
|
||||
@ -158,7 +158,7 @@ def test_gettext_template_msgid_order_in_sphinxpot(app):
|
||||
app.builder.build_all()
|
||||
assert (app.outdir / 'sphinx.pot').isfile()
|
||||
|
||||
result = (app.outdir / 'sphinx.pot').read_text()
|
||||
result = (app.outdir / 'sphinx.pot').read_text(encoding='utf8')
|
||||
assert re.search(
|
||||
('msgid "Template 1".*'
|
||||
'msgid "This is Template 1\\.".*'
|
||||
@ -176,7 +176,7 @@ def test_build_single_pot(app):
|
||||
|
||||
assert (app.outdir / 'documentation.pot').isfile()
|
||||
|
||||
result = (app.outdir / 'documentation.pot').read_text()
|
||||
result = (app.outdir / 'documentation.pot').read_text(encoding='utf8')
|
||||
assert re.search(
|
||||
('msgid "Todo".*'
|
||||
'msgid "Like footnotes.".*'
|
||||
|
@ -5,6 +5,7 @@ import re
|
||||
from itertools import chain, cycle
|
||||
from unittest.mock import ANY, call, patch
|
||||
|
||||
import docutils
|
||||
import pygments
|
||||
import pytest
|
||||
from html5lib import HTMLParser
|
||||
@ -13,7 +14,7 @@ from packaging import version
|
||||
from sphinx.builders.html import validate_html_extra_path, validate_html_static_path
|
||||
from sphinx.errors import ConfigError
|
||||
from sphinx.testing.util import strip_escseq
|
||||
from sphinx.util import docutils, md5
|
||||
from sphinx.util import md5
|
||||
from sphinx.util.inventory import InventoryFile
|
||||
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
@ -479,7 +480,7 @@ def test_html_download(app):
|
||||
app.build()
|
||||
|
||||
# subdir/includes.html
|
||||
result = (app.outdir / 'subdir' / 'includes.html').read_text()
|
||||
result = (app.outdir / 'subdir' / 'includes.html').read_text(encoding='utf8')
|
||||
pattern = ('<a class="reference download internal" download="" '
|
||||
'href="../(_downloads/.*/img.png)">')
|
||||
matched = re.search(pattern, result)
|
||||
@ -488,7 +489,7 @@ def test_html_download(app):
|
||||
filename = matched.group(1)
|
||||
|
||||
# includes.html
|
||||
result = (app.outdir / 'includes.html').read_text()
|
||||
result = (app.outdir / 'includes.html').read_text(encoding='utf8')
|
||||
pattern = ('<a class="reference download internal" download="" '
|
||||
'href="(_downloads/.*/img.png)">')
|
||||
matched = re.search(pattern, result)
|
||||
@ -511,7 +512,7 @@ def test_html_download_role(app, status, warning):
|
||||
digest_another = md5(b'another/dummy.dat').hexdigest()
|
||||
assert (app.outdir / '_downloads' / digest_another / 'dummy.dat').exists()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert (('<li><p><a class="reference download internal" download="" '
|
||||
'href="_downloads/%s/dummy.dat">'
|
||||
'<code class="xref download docutils literal notranslate">'
|
||||
@ -693,9 +694,9 @@ def test_numfig_disabled(app, cached_etree_parse, fname, expect):
|
||||
def test_numfig_without_numbered_toctree_warn(app, warning):
|
||||
app.build()
|
||||
# remove :numbered: option
|
||||
index = (app.srcdir / 'index.rst').read_text()
|
||||
index = (app.srcdir / 'index.rst').read_text(encoding='utf8')
|
||||
index = re.sub(':numbered:.*', '', index)
|
||||
(app.srcdir / 'index.rst').write_text(index)
|
||||
(app.srcdir / 'index.rst').write_text(index, encoding='utf8')
|
||||
app.builder.build_all()
|
||||
|
||||
warnings = warning.getvalue()
|
||||
@ -781,9 +782,9 @@ def test_numfig_without_numbered_toctree_warn(app, warning):
|
||||
confoverrides={'numfig': True})
|
||||
def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect):
|
||||
# remove :numbered: option
|
||||
index = (app.srcdir / 'index.rst').read_text()
|
||||
index = (app.srcdir / 'index.rst').read_text(encoding='utf8')
|
||||
index = re.sub(':numbered:.*', '', index)
|
||||
(app.srcdir / 'index.rst').write_text(index)
|
||||
(app.srcdir / 'index.rst').write_text(index, encoding='utf8')
|
||||
|
||||
if not app.outdir.listdir():
|
||||
app.build()
|
||||
@ -1171,7 +1172,7 @@ def test_html_assets(app):
|
||||
assert not (app.outdir / '_static' / '.htaccess').exists()
|
||||
assert not (app.outdir / '_static' / '.htpasswd').exists()
|
||||
assert (app.outdir / '_static' / 'API.html').exists()
|
||||
assert (app.outdir / '_static' / 'API.html').read_text() == 'Sphinx-1.4.4'
|
||||
assert (app.outdir / '_static' / 'API.html').read_text(encoding='utf8') == 'Sphinx-1.4.4'
|
||||
assert (app.outdir / '_static' / 'css' / 'style.css').exists()
|
||||
assert (app.outdir / '_static' / 'js' / 'custom.js').exists()
|
||||
assert (app.outdir / '_static' / 'rimg.png').exists()
|
||||
@ -1192,7 +1193,7 @@ def test_html_assets(app):
|
||||
assert not (app.outdir / 'subdir' / '.htpasswd').exists()
|
||||
|
||||
# html_css_files
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
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" '
|
||||
'href="https://example.com/custom.css" />' in content)
|
||||
@ -1215,7 +1216,7 @@ def test_assets_order(app):
|
||||
app.add_js_file('lazy.js', priority=900)
|
||||
|
||||
app.builder.build_all()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
# css_files
|
||||
expected = ['_static/early.css', '_static/pygments.css', '_static/alabaster.css',
|
||||
@ -1239,7 +1240,7 @@ def test_javscript_loading_method(app):
|
||||
app.add_js_file('late.js', loading_method='defer')
|
||||
|
||||
app.builder.build_all()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
assert '<script src="_static/normal.js"></script>' in content
|
||||
assert '<script async="async" src="_static/early.js"></script>' in content
|
||||
@ -1274,7 +1275,7 @@ def test_html_sourcelink_suffix_empty(app):
|
||||
def test_html_entity(app):
|
||||
app.builder.build_all()
|
||||
valid_entities = {'amp', 'lt', 'gt', 'quot', 'apos'}
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
for entity in re.findall(r'&([a-z]+);', content, re.M):
|
||||
assert entity not in valid_entities
|
||||
|
||||
@ -1316,7 +1317,7 @@ def test_html_inventory(app):
|
||||
@pytest.mark.sphinx('html', testroot='images', confoverrides={'html_sourcelink_suffix': ''})
|
||||
def test_html_anchor_for_figure(app):
|
||||
app.builder.build_all()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
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>'
|
||||
@ -1330,7 +1331,7 @@ def test_html_anchor_for_figure(app):
|
||||
@pytest.mark.sphinx('html', testroot='directives-raw')
|
||||
def test_html_raw_directive(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
# standard case
|
||||
assert 'standalone raw directive (HTML)' in result
|
||||
@ -1374,7 +1375,7 @@ def test_alternate_stylesheets(app, cached_etree_parse, fname, expect):
|
||||
@pytest.mark.sphinx('html', testroot='html_style')
|
||||
def test_html_style(app, status, warning):
|
||||
app.build()
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<link rel="stylesheet" type="text/css" href="_static/default.css" />' in result
|
||||
assert ('<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />'
|
||||
not in result)
|
||||
@ -1384,7 +1385,7 @@ def test_html_style(app, status, warning):
|
||||
def test_html_remote_images(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<img alt="https://www.python.org/static/img/python-logo.png" '
|
||||
'src="https://www.python.org/static/img/python-logo.png" />' in result)
|
||||
assert not (app.outdir / 'python-logo.png').exists()
|
||||
@ -1394,7 +1395,7 @@ def test_html_remote_images(app, status, warning):
|
||||
def test_html_remote_logo(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<img class="logo" src="https://www.python.org/static/img/python-logo.png" alt="Logo"/>' in result)
|
||||
assert ('<link rel="shortcut icon" href="https://www.python.org/static/favicon.ico"/>' in result)
|
||||
assert not (app.outdir / 'python-logo.png').exists()
|
||||
@ -1404,7 +1405,7 @@ def test_html_remote_logo(app, status, warning):
|
||||
def test_html_local_logo(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<img class="logo" src="_static/img.png" alt="Logo"/>' in result)
|
||||
assert (app.outdir / '_static/img.png').exists()
|
||||
|
||||
@ -1415,7 +1416,7 @@ def test_html_sidebar(app, status, warning):
|
||||
|
||||
# default for alabaster
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<div class="sphinxsidebar" role="navigation" '
|
||||
'aria-label="main navigation">' in result)
|
||||
assert '<h1 class="logo"><a href="#">Python</a></h1>' in result
|
||||
@ -1430,7 +1431,7 @@ def test_html_sidebar(app, status, warning):
|
||||
# only relations.html
|
||||
app.config.html_sidebars = {'**': ['relations.html']}
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<div class="sphinxsidebar" role="navigation" '
|
||||
'aria-label="main navigation">' in result)
|
||||
assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result
|
||||
@ -1444,7 +1445,7 @@ def test_html_sidebar(app, status, warning):
|
||||
# no sidebars
|
||||
app.config.html_sidebars = {'**': []}
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<div class="sphinxsidebar" role="navigation" '
|
||||
'aria-label="main navigation">' not in result)
|
||||
assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result
|
||||
@ -1475,10 +1476,10 @@ def test_html_manpage(app, cached_etree_parse, fname, expect):
|
||||
def test_html_baseurl(app, status, warning):
|
||||
app.build()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<link rel="canonical" href="https://example.com/index.html" />' in result
|
||||
|
||||
result = (app.outdir / 'qux' / 'index.html').read_text()
|
||||
result = (app.outdir / 'qux' / 'index.html').read_text(encoding='utf8')
|
||||
assert '<link rel="canonical" href="https://example.com/qux/index.html" />' in result
|
||||
|
||||
|
||||
@ -1488,10 +1489,10 @@ def test_html_baseurl(app, status, warning):
|
||||
def test_html_baseurl_and_html_file_suffix(app, status, warning):
|
||||
app.build()
|
||||
|
||||
result = (app.outdir / 'index.htm').read_text()
|
||||
result = (app.outdir / 'index.htm').read_text(encoding='utf8')
|
||||
assert '<link rel="canonical" href="https://example.com/subdir/index.htm" />' in result
|
||||
|
||||
result = (app.outdir / 'qux' / 'index.htm').read_text()
|
||||
result = (app.outdir / 'qux' / 'index.htm').read_text(encoding='utf8')
|
||||
assert '<link rel="canonical" href="https://example.com/subdir/qux/index.htm" />' in result
|
||||
|
||||
|
||||
@ -1608,7 +1609,7 @@ def test_validate_html_static_path(app):
|
||||
@pytest.mark.sphinx(testroot='html_scaled_image_link')
|
||||
def test_html_scaled_image_link(app):
|
||||
app.build()
|
||||
context = (app.outdir / 'index.html').read_text()
|
||||
context = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
# no scaled parameters
|
||||
assert re.search('\n<img alt="_images/img.png" src="_images/img.png" />', context)
|
||||
@ -1628,7 +1629,7 @@ def test_html_scaled_image_link(app):
|
||||
confoverrides={'html_codeblock_linenos_style': 'table'})
|
||||
def test_html_codeblock_linenos_style_table(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
if PYGMENTS_VERSION >= (2, 8):
|
||||
assert ('<div class="linenodiv"><pre><span class="normal">1</span>\n'
|
||||
@ -1643,7 +1644,7 @@ def test_html_codeblock_linenos_style_table(app):
|
||||
confoverrides={'html_codeblock_linenos_style': 'inline'})
|
||||
def test_html_codeblock_linenos_style_inline(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
if PYGMENTS_VERSION > (2, 7):
|
||||
assert '<span class="linenos">1</span>' in content
|
||||
@ -1688,7 +1689,7 @@ def test_highlight_options_old(app):
|
||||
confoverrides={'html_permalinks': False})
|
||||
def test_html_permalink_disable(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
assert '<h1>The basic Sphinx documentation for testing</h1>' in content
|
||||
|
||||
@ -1697,7 +1698,7 @@ def test_html_permalink_disable(app):
|
||||
confoverrides={'html_permalinks_icon': '<span>[PERMALINK]</span>'})
|
||||
def test_html_permalink_icon(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
assert ('<h1>The basic Sphinx documentation for testing<a class="headerlink" '
|
||||
'href="#the-basic-sphinx-documentation-for-testing" '
|
||||
@ -1707,6 +1708,6 @@ def test_html_permalink_icon(app):
|
||||
@pytest.mark.sphinx('html', testroot='html_signaturereturn_icon')
|
||||
def test_html_signaturereturn_icon(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
assert ('<span class="sig-return-icon">→</span>' in content)
|
||||
|
@ -104,7 +104,7 @@ def test_build_latex_doc(app, status, warning, engine, docclass):
|
||||
@pytest.mark.sphinx('latex')
|
||||
def test_writer(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'sphinxtests.tex').read_text()
|
||||
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
|
||||
|
||||
assert ('\\begin{sphinxfigure-in-table}\n\\centering\n\\capstart\n'
|
||||
'\\noindent\\sphinxincludegraphics{{img}.png}\n'
|
||||
@ -147,7 +147,7 @@ def test_latex_warnings(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='basic')
|
||||
def test_latex_basic(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'test.tex').read_text()
|
||||
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -240,7 +240,7 @@ def test_latex_theme_options(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'zh'})
|
||||
def test_latex_additional_settings_for_language_code(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'test.tex').read_text()
|
||||
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -250,7 +250,7 @@ def test_latex_additional_settings_for_language_code(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'el'})
|
||||
def test_latex_additional_settings_for_greek(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'test.tex').read_text()
|
||||
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -261,7 +261,7 @@ def test_latex_additional_settings_for_greek(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='latex-title')
|
||||
def test_latex_title_after_admonitions(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'test.tex').read_text()
|
||||
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -272,7 +272,7 @@ def test_latex_title_after_admonitions(app, status, warning):
|
||||
confoverrides={'release': '1.0_0'})
|
||||
def test_latex_release(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'test.tex').read_text()
|
||||
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -284,7 +284,7 @@ def test_latex_release(app, status, warning):
|
||||
confoverrides={'numfig': True})
|
||||
def test_numref(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -310,7 +310,7 @@ def test_numref(app, status, warning):
|
||||
'\\nameref{\\detokenize{foo:foo}}}') in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table }}' in result
|
||||
@ -326,7 +326,7 @@ def test_numref(app, status, warning):
|
||||
'section': 'SECTION-%s'}})
|
||||
def test_numref_with_prefix1(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -358,7 +358,7 @@ def test_numref_with_prefix1(app, status, warning):
|
||||
'\\nameref{\\detokenize{foo:foo}}}') in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
|
||||
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result
|
||||
@ -374,7 +374,7 @@ def test_numref_with_prefix1(app, status, warning):
|
||||
'section': 'SECTION_%s_'}})
|
||||
def test_numref_with_prefix2(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -400,7 +400,7 @@ def test_numref_with_prefix2(app, status, warning):
|
||||
'\\nameref{\\detokenize{foo:foo}}}') in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
|
||||
assert r'\def\fnum@figure{\figurename\thefigure{}.}' in result
|
||||
@ -414,7 +414,7 @@ def test_numref_with_prefix2(app, status, warning):
|
||||
confoverrides={'numfig': True, 'language': 'ja'})
|
||||
def test_numref_with_language_ja(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -440,7 +440,7 @@ def test_numref_with_language_ja(app, status, warning):
|
||||
'\\nameref{\\detokenize{foo:foo}}}') in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert '\\@iden{\\renewcommand{\\figurename}{図 }}' in result
|
||||
assert '\\@iden{\\renewcommand{\\tablename}{表 }}' in result
|
||||
@ -451,10 +451,10 @@ def test_numref_with_language_ja(app, status, warning):
|
||||
def test_latex_obey_numfig_is_false(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text()
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage{sphinx}' in result
|
||||
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text()
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage{sphinx}' in result
|
||||
|
||||
|
||||
@ -464,10 +464,10 @@ def test_latex_obey_numfig_is_false(app, status, warning):
|
||||
def test_latex_obey_numfig_secnum_depth_is_zero(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text()
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
|
||||
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text()
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
|
||||
|
||||
|
||||
@ -477,10 +477,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):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text()
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage[,numfigreset=2,mathnumfig]{sphinx}' in result
|
||||
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text()
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage[,numfigreset=3,mathnumfig]{sphinx}' in result
|
||||
|
||||
|
||||
@ -490,10 +490,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):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text()
|
||||
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage[,numfigreset=1]{sphinx}' in result
|
||||
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text()
|
||||
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage[,numfigreset=2]{sphinx}' in result
|
||||
|
||||
|
||||
@ -502,7 +502,7 @@ def test_latex_add_latex_package(app, status, warning):
|
||||
app.add_latex_package('foo')
|
||||
app.add_latex_package('bar', 'baz')
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'test.tex').read_text()
|
||||
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
|
||||
assert '\\usepackage{foo}' in result
|
||||
assert '\\usepackage[baz]{bar}' in result
|
||||
|
||||
@ -510,7 +510,7 @@ def test_latex_add_latex_package(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='latex-babel')
|
||||
def test_babel_with_no_language_settings(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -523,7 +523,7 @@ def test_babel_with_no_language_settings(app, status, warning):
|
||||
assert '\\shorthandoff{"}' in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{page}' in result
|
||||
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
@ -535,7 +535,7 @@ def test_babel_with_no_language_settings(app, status, warning):
|
||||
confoverrides={'language': 'de'})
|
||||
def test_babel_with_language_de(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -548,7 +548,7 @@ def test_babel_with_language_de(app, status, warning):
|
||||
assert '\\shorthandoff{"}' in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{Seite}' in result
|
||||
assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
@ -560,7 +560,7 @@ def test_babel_with_language_de(app, status, warning):
|
||||
confoverrides={'language': 'ru'})
|
||||
def test_babel_with_language_ru(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -573,7 +573,7 @@ def test_babel_with_language_ru(app, status, warning):
|
||||
assert '\\shorthandoff{"}' in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{страница}' in result
|
||||
assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
@ -585,7 +585,7 @@ def test_babel_with_language_ru(app, status, warning):
|
||||
confoverrides={'language': 'tr'})
|
||||
def test_babel_with_language_tr(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -598,7 +598,7 @@ def test_babel_with_language_tr(app, status, warning):
|
||||
assert '\\shorthandoff{=}' in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{sayfa}' in result
|
||||
assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
@ -610,7 +610,7 @@ def test_babel_with_language_tr(app, status, warning):
|
||||
confoverrides={'language': 'ja'})
|
||||
def test_babel_with_language_ja(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -622,7 +622,7 @@ def test_babel_with_language_ja(app, status, warning):
|
||||
assert '\\shorthandoff' not in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{ページ}' in result
|
||||
assert '\\@iden{\\renewcommand{\\figurename}{Fig.\\@{} }}' in result
|
||||
@ -634,7 +634,7 @@ def test_babel_with_language_ja(app, status, warning):
|
||||
confoverrides={'language': 'unknown'})
|
||||
def test_babel_with_unknown_language(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -649,7 +649,7 @@ def test_babel_with_unknown_language(app, status, warning):
|
||||
assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue()
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{page}' in result
|
||||
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
@ -661,7 +661,7 @@ def test_babel_with_unknown_language(app, status, warning):
|
||||
confoverrides={'language': 'de', 'latex_engine': 'lualatex'})
|
||||
def test_polyglossia_with_language_de(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -675,7 +675,7 @@ def test_polyglossia_with_language_de(app, status, warning):
|
||||
assert '\\shorthandoff' not in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{Seite}' in result
|
||||
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
@ -687,7 +687,7 @@ def test_polyglossia_with_language_de(app, status, warning):
|
||||
confoverrides={'language': 'de-1901', 'latex_engine': 'lualatex'})
|
||||
def test_polyglossia_with_language_de_1901(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -701,7 +701,7 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
|
||||
assert '\\shorthandoff' not in result
|
||||
|
||||
# sphinxmessages.sty
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text()
|
||||
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert r'\def\pageautorefname{page}' in result
|
||||
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
|
||||
@ -711,7 +711,7 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
|
||||
@pytest.mark.sphinx('latex')
|
||||
def test_footnote(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'sphinxtests.tex').read_text()
|
||||
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -739,7 +739,7 @@ def test_footnote(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='footnotes')
|
||||
def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -778,7 +778,7 @@ def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='footnotes')
|
||||
def test_footnote_referred_multiple_times(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -800,7 +800,7 @@ def test_footnote_referred_multiple_times(app, status, warning):
|
||||
confoverrides={'latex_show_urls': 'inline'})
|
||||
def test_latex_show_urls_is_inline(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -857,7 +857,7 @@ def test_latex_show_urls_is_inline(app, status, warning):
|
||||
confoverrides={'latex_show_urls': 'footnote'})
|
||||
def test_latex_show_urls_is_footnote(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -919,7 +919,7 @@ def test_latex_show_urls_is_footnote(app, status, warning):
|
||||
confoverrides={'latex_show_urls': 'no'})
|
||||
def test_latex_show_urls_is_no(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -974,7 +974,7 @@ def test_latex_show_urls_footnote_and_substitutions(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='image-in-section')
|
||||
def test_image_in_section(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1000,7 +1000,7 @@ def test_latex_logo_if_not_found(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='toctree-maxdepth')
|
||||
def test_toctree_maxdepth_manual(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1017,7 +1017,7 @@ def test_toctree_maxdepth_manual(app, status, warning):
|
||||
]})
|
||||
def test_toctree_maxdepth_howto(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1031,7 +1031,7 @@ def test_toctree_maxdepth_howto(app, status, warning):
|
||||
confoverrides={'root_doc': 'foo'})
|
||||
def test_toctree_not_found(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1045,7 +1045,7 @@ def test_toctree_not_found(app, status, warning):
|
||||
confoverrides={'root_doc': 'bar'})
|
||||
def test_toctree_without_maxdepth(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1058,7 +1058,7 @@ def test_toctree_without_maxdepth(app, status, warning):
|
||||
confoverrides={'root_doc': 'qux'})
|
||||
def test_toctree_with_deeper_maxdepth(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1071,7 +1071,7 @@ def test_toctree_with_deeper_maxdepth(app, status, warning):
|
||||
confoverrides={'latex_toplevel_sectioning': None})
|
||||
def test_latex_toplevel_sectioning_is_None(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1083,7 +1083,7 @@ def test_latex_toplevel_sectioning_is_None(app, status, warning):
|
||||
confoverrides={'latex_toplevel_sectioning': 'part'})
|
||||
def test_latex_toplevel_sectioning_is_part(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1101,7 +1101,7 @@ def test_latex_toplevel_sectioning_is_part(app, status, warning):
|
||||
]})
|
||||
def test_latex_toplevel_sectioning_is_part_with_howto(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1115,7 +1115,7 @@ def test_latex_toplevel_sectioning_is_part_with_howto(app, status, warning):
|
||||
confoverrides={'latex_toplevel_sectioning': 'chapter'})
|
||||
def test_latex_toplevel_sectioning_is_chapter(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1131,7 +1131,7 @@ def test_latex_toplevel_sectioning_is_chapter(app, status, warning):
|
||||
]})
|
||||
def test_latex_toplevel_sectioning_is_chapter_with_howto(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1143,7 +1143,7 @@ def test_latex_toplevel_sectioning_is_chapter_with_howto(app, status, warning):
|
||||
confoverrides={'latex_toplevel_sectioning': 'section'})
|
||||
def test_latex_toplevel_sectioning_is_section(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1154,7 +1154,7 @@ def test_latex_toplevel_sectioning_is_section(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='maxlistdepth')
|
||||
def test_maxlistdepth_at_ten(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
@ -1165,7 +1165,7 @@ def test_maxlistdepth_at_ten(app, status, warning):
|
||||
@pytest.mark.test_params(shared_result='latex-table')
|
||||
def test_latex_table_tabulars(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
tables = {}
|
||||
for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
|
||||
sectname, content = chap.split('}', 1)
|
||||
@ -1173,7 +1173,7 @@ def test_latex_table_tabulars(app, status, warning):
|
||||
tables[sectname] = content.strip()
|
||||
|
||||
def get_expected(name):
|
||||
return (app.srcdir / 'expects' / (name + '.tex')).read_text().strip()
|
||||
return (app.srcdir / 'expects' / (name + '.tex')).read_text(encoding='utf8').strip()
|
||||
|
||||
# simple_table
|
||||
actual = tables['simple table']
|
||||
@ -1235,7 +1235,7 @@ def test_latex_table_tabulars(app, status, warning):
|
||||
@pytest.mark.test_params(shared_result='latex-table')
|
||||
def test_latex_table_longtable(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
tables = {}
|
||||
for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
|
||||
sectname, content = chap.split('}', 1)
|
||||
@ -1243,7 +1243,7 @@ def test_latex_table_longtable(app, status, warning):
|
||||
tables[sectname] = content.strip()
|
||||
|
||||
def get_expected(name):
|
||||
return (app.srcdir / 'expects' / (name + '.tex')).read_text().strip()
|
||||
return (app.srcdir / 'expects' / (name + '.tex')).read_text(encoding='utf8').strip()
|
||||
|
||||
# longtable
|
||||
actual = tables['longtable']
|
||||
@ -1295,14 +1295,14 @@ def test_latex_table_longtable(app, status, warning):
|
||||
@pytest.mark.test_params(shared_result='latex-table')
|
||||
def test_latex_table_complex_tables(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
tables = {}
|
||||
for chap in re.split(r'\\(?:section|renewcommand){', result)[1:]:
|
||||
sectname, content = chap.split('}', 1)
|
||||
tables[sectname] = content.strip()
|
||||
|
||||
def get_expected(name):
|
||||
return (app.srcdir / 'expects' / (name + '.tex')).read_text().strip()
|
||||
return (app.srcdir / 'expects' / (name + '.tex')).read_text(encoding='utf8').strip()
|
||||
|
||||
# grid table
|
||||
actual = tables['grid table']
|
||||
@ -1319,7 +1319,7 @@ def test_latex_table_complex_tables(app, status, warning):
|
||||
confoverrides={'templates_path': ['_mytemplates/latex']})
|
||||
def test_latex_table_custom_template_caseA(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert 'SALUT LES COPAINS' in result
|
||||
|
||||
|
||||
@ -1327,7 +1327,7 @@ def test_latex_table_custom_template_caseA(app, status, warning):
|
||||
confoverrides={'templates_path': ['_mytemplates']})
|
||||
def test_latex_table_custom_template_caseB(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert 'SALUT LES COPAINS' not in result
|
||||
|
||||
|
||||
@ -1335,14 +1335,14 @@ def test_latex_table_custom_template_caseB(app, status, warning):
|
||||
@pytest.mark.test_params(shared_result='latex-table')
|
||||
def test_latex_table_custom_template_caseC(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert 'SALUT LES COPAINS' not in result
|
||||
|
||||
|
||||
@pytest.mark.sphinx('latex', testroot='directives-raw')
|
||||
def test_latex_raw_directive(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
|
||||
# standard case
|
||||
assert 'standalone raw directive (HTML)' not in result
|
||||
@ -1358,7 +1358,7 @@ def test_latex_raw_directive(app, status, warning):
|
||||
def test_latex_images(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
|
||||
# images are copied
|
||||
assert '\\sphinxincludegraphics{{python-logo}.png}' in result
|
||||
@ -1382,7 +1382,7 @@ def test_latex_images(app, status, warning):
|
||||
def test_latex_index(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert ('A \\index{famous@\\spxentry{famous}}famous '
|
||||
'\\index{equation@\\spxentry{equation}}equation:\n' in result)
|
||||
assert ('\n\\index{Einstein@\\spxentry{Einstein}}'
|
||||
@ -1396,8 +1396,8 @@ def test_latex_index(app, status, warning):
|
||||
def test_latex_equations(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
expected = (app.srcdir / 'expects' / 'latex-equations.tex').read_text().strip()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
expected = (app.srcdir / 'expects' / 'latex-equations.tex').read_text(encoding='utf8').strip()
|
||||
|
||||
assert expected in result
|
||||
|
||||
@ -1406,7 +1406,7 @@ def test_latex_equations(app, status, warning):
|
||||
def test_latex_image_in_parsed_literal(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert ('{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}'
|
||||
'{\\sphinxincludegraphics[height=2.00000cm]{{pic}.png}}'
|
||||
'}AFTER') in result
|
||||
@ -1416,7 +1416,7 @@ def test_latex_image_in_parsed_literal(app, status, warning):
|
||||
def test_latex_nested_enumerated_list(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert ('\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n'
|
||||
'\\setcounter{enumi}{4}\n' in result)
|
||||
assert ('\\sphinxsetlistlabels{\\alph}{enumii}{enumiii}{}{.}%\n'
|
||||
@ -1433,7 +1433,7 @@ def test_latex_nested_enumerated_list(app, status, warning):
|
||||
def test_latex_thebibliography(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert ('\\begin{sphinxthebibliography}{AuthorYe}\n'
|
||||
'\\bibitem[AuthorYear]{index:authoryear}\n\\sphinxAtStartPar\n'
|
||||
@ -1446,7 +1446,7 @@ def test_latex_thebibliography(app, status, warning):
|
||||
def test_latex_glossary(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert (r'\sphinxlineitem{ähnlich\index{ähnlich@\spxentry{ähnlich}|spxpagem}'
|
||||
r'\phantomsection'
|
||||
r'\label{\detokenize{index:term-ahnlich}}}' in result)
|
||||
@ -1470,7 +1470,7 @@ def test_latex_glossary(app, status, warning):
|
||||
def test_latex_labels(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
|
||||
# figures
|
||||
assert (r'\caption{labeled figure}'
|
||||
@ -1518,7 +1518,7 @@ def test_latex_labels(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='latex-figure-in-admonition')
|
||||
def test_latex_figure_in_admonition(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert(r'\begin{figure}[H]' in result)
|
||||
|
||||
|
||||
@ -1549,7 +1549,7 @@ def test_includegraphics_oversized(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='index_on_title')
|
||||
def test_index_on_title(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert ('\\chapter{Test for index in top level title}\n'
|
||||
'\\label{\\detokenize{contents:test-for-index-in-top-level-title}}'
|
||||
'\\index{index@\\spxentry{index}}\n'
|
||||
@ -1560,7 +1560,7 @@ def test_index_on_title(app, status, warning):
|
||||
confoverrides={'latex_engine': 'pdflatex'})
|
||||
def test_texescape_for_non_unicode_supported_engine(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert 'script small e: e' in result
|
||||
assert 'double struck italic small i: i' in result
|
||||
@ -1572,7 +1572,7 @@ def test_texescape_for_non_unicode_supported_engine(app, status, warning):
|
||||
confoverrides={'latex_engine': 'xelatex'})
|
||||
def test_texescape_for_unicode_supported_engine(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(result)
|
||||
assert 'script small e: e' in result
|
||||
assert 'double struck italic small i: i' in result
|
||||
@ -1584,7 +1584,7 @@ def test_texescape_for_unicode_supported_engine(app, status, warning):
|
||||
confoverrides={'latex_elements': {'extrapackages': r'\usepackage{foo}'}})
|
||||
def test_latex_elements_extrapackages(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'test.tex').read_text()
|
||||
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
|
||||
assert r'\usepackage{foo}' in result
|
||||
|
||||
|
||||
@ -1597,6 +1597,6 @@ def test_latex_nested_tables(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='latex-container')
|
||||
def test_latex_container(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert r'\begin{sphinxuseclass}{classname}' in result
|
||||
assert r'\end{sphinxuseclass}' in result
|
||||
|
@ -28,7 +28,7 @@ def test_defaults(app):
|
||||
app.build()
|
||||
|
||||
assert (app.outdir / 'output.txt').exists()
|
||||
content = (app.outdir / 'output.txt').read_text()
|
||||
content = (app.outdir / 'output.txt').read_text(encoding='utf8')
|
||||
|
||||
print(content)
|
||||
# looking for '#top' and '#does-not-exist' not found should fail
|
||||
@ -49,7 +49,7 @@ def test_defaults_json(app):
|
||||
app.build()
|
||||
|
||||
assert (app.outdir / 'output.json').exists()
|
||||
content = (app.outdir / 'output.json').read_text()
|
||||
content = (app.outdir / 'output.json').read_text(encoding='utf8')
|
||||
print(content)
|
||||
|
||||
rows = [json.loads(x) for x in content.splitlines()]
|
||||
@ -110,7 +110,7 @@ def test_anchors_ignored(app):
|
||||
app.build()
|
||||
|
||||
assert (app.outdir / 'output.txt').exists()
|
||||
content = (app.outdir / 'output.txt').read_text()
|
||||
content = (app.outdir / 'output.txt').read_text(encoding='utf8')
|
||||
|
||||
# expect all ok when excluding #top
|
||||
assert not content
|
||||
@ -124,7 +124,7 @@ def test_raises_for_invalid_status(app):
|
||||
|
||||
with http_server(InternalServerErrorHandler):
|
||||
app.build()
|
||||
content = (app.outdir / 'output.txt').read_text()
|
||||
content = (app.outdir / 'output.txt').read_text(encoding='utf8')
|
||||
assert content == (
|
||||
"index.rst:1: [broken] http://localhost:7777/#anchor: "
|
||||
"500 Server Error: Internal Server Error "
|
||||
@ -247,7 +247,7 @@ def test_follows_redirects_on_HEAD(app, capsys, warning):
|
||||
with http_server(make_redirect_handler(support_head=True)):
|
||||
app.build()
|
||||
stdout, stderr = capsys.readouterr()
|
||||
content = (app.outdir / 'output.txt').read_text()
|
||||
content = (app.outdir / 'output.txt').read_text(encoding='utf8')
|
||||
assert content == (
|
||||
"index.rst:1: [redirected with Found] "
|
||||
"http://localhost:7777/ to http://localhost:7777/?redirected=1\n"
|
||||
@ -266,7 +266,7 @@ def test_follows_redirects_on_GET(app, capsys, warning):
|
||||
with http_server(make_redirect_handler(support_head=False)):
|
||||
app.build()
|
||||
stdout, stderr = capsys.readouterr()
|
||||
content = (app.outdir / 'output.txt').read_text()
|
||||
content = (app.outdir / 'output.txt').read_text(encoding='utf8')
|
||||
assert content == (
|
||||
"index.rst:1: [redirected with Found] "
|
||||
"http://localhost:7777/ to http://localhost:7777/?redirected=1\n"
|
||||
@ -289,7 +289,7 @@ def test_linkcheck_allowed_redirects(app, warning):
|
||||
with http_server(make_redirect_handler(support_head=False)):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
records = [json.loads(l) for l in fp.readlines()]
|
||||
|
||||
assert len(records) == 2
|
||||
@ -318,7 +318,7 @@ def test_invalid_ssl(app):
|
||||
with http_server(OKHandler):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = json.load(fp)
|
||||
assert content["status"] == "broken"
|
||||
assert content["filename"] == "index.rst"
|
||||
@ -332,7 +332,7 @@ def test_connect_to_selfsigned_fails(app):
|
||||
with https_server(OKHandler):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = json.load(fp)
|
||||
assert content["status"] == "broken"
|
||||
assert content["filename"] == "index.rst"
|
||||
@ -347,7 +347,7 @@ def test_connect_to_selfsigned_with_tls_verify_false(app):
|
||||
with https_server(OKHandler):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = json.load(fp)
|
||||
assert content == {
|
||||
"code": 0,
|
||||
@ -365,7 +365,7 @@ def test_connect_to_selfsigned_with_tls_cacerts(app):
|
||||
with https_server(OKHandler):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = json.load(fp)
|
||||
assert content == {
|
||||
"code": 0,
|
||||
@ -383,7 +383,7 @@ def test_connect_to_selfsigned_with_requests_env_var(monkeypatch, app):
|
||||
with https_server(OKHandler):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = json.load(fp)
|
||||
assert content == {
|
||||
"code": 0,
|
||||
@ -401,7 +401,7 @@ def test_connect_to_selfsigned_nonexistent_cert_file(app):
|
||||
with https_server(OKHandler):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = json.load(fp)
|
||||
assert content == {
|
||||
"code": 0,
|
||||
@ -429,7 +429,7 @@ def test_TooManyRedirects_on_HEAD(app):
|
||||
with http_server(InfiniteRedirectOnHeadHandler):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = json.load(fp)
|
||||
assert content == {
|
||||
"code": 0,
|
||||
@ -463,7 +463,7 @@ def test_too_many_requests_retry_after_int_delay(app, capsys, status):
|
||||
mock.patch("sphinx.builders.linkcheck.DEFAULT_DELAY", 0), \
|
||||
mock.patch("sphinx.builders.linkcheck.QUEUE_POLL_SECS", 0.01):
|
||||
app.build()
|
||||
content = (app.outdir / 'output.json').read_text()
|
||||
content = (app.outdir / 'output.json').read_text(encoding='utf8')
|
||||
assert json.loads(content) == {
|
||||
"filename": "index.rst",
|
||||
"lineno": 1,
|
||||
@ -489,7 +489,7 @@ def test_too_many_requests_retry_after_HTTP_date(app, capsys):
|
||||
retry_after = wsgiref.handlers.format_date_time(time.mktime(now))
|
||||
with http_server(make_retry_after_handler([(429, retry_after), (200, None)])):
|
||||
app.build()
|
||||
content = (app.outdir / 'output.json').read_text()
|
||||
content = (app.outdir / 'output.json').read_text(encoding='utf8')
|
||||
assert json.loads(content) == {
|
||||
"filename": "index.rst",
|
||||
"lineno": 1,
|
||||
@ -512,7 +512,7 @@ def test_too_many_requests_retry_after_without_header(app, capsys):
|
||||
with http_server(make_retry_after_handler([(429, None), (200, None)])),\
|
||||
mock.patch("sphinx.builders.linkcheck.DEFAULT_DELAY", 0):
|
||||
app.build()
|
||||
content = (app.outdir / 'output.json').read_text()
|
||||
content = (app.outdir / 'output.json').read_text(encoding='utf8')
|
||||
assert json.loads(content) == {
|
||||
"filename": "index.rst",
|
||||
"lineno": 1,
|
||||
@ -535,7 +535,7 @@ def test_too_many_requests_user_timeout(app, capsys):
|
||||
app.config.linkcheck_rate_limit_timeout = 0.0
|
||||
with http_server(make_retry_after_handler([(429, None)])):
|
||||
app.build()
|
||||
content = (app.outdir / 'output.json').read_text()
|
||||
content = (app.outdir / 'output.json').read_text(encoding='utf8')
|
||||
assert json.loads(content) == {
|
||||
"filename": "index.rst",
|
||||
"lineno": 1,
|
||||
@ -606,9 +606,9 @@ class ConnectionResetHandler(http.server.BaseHTTPRequestHandler):
|
||||
def test_get_after_head_raises_connection_error(app):
|
||||
with http_server(ConnectionResetHandler):
|
||||
app.build()
|
||||
content = (app.outdir / 'output.txt').read_text()
|
||||
content = (app.outdir / 'output.txt').read_text(encoding='utf8')
|
||||
assert not content
|
||||
content = (app.outdir / 'output.json').read_text()
|
||||
content = (app.outdir / 'output.json').read_text(encoding='utf8')
|
||||
assert json.loads(content) == {
|
||||
"filename": "index.rst",
|
||||
"lineno": 1,
|
||||
@ -623,7 +623,7 @@ def test_get_after_head_raises_connection_error(app):
|
||||
def test_linkcheck_exclude_documents(app):
|
||||
app.build()
|
||||
|
||||
with open(app.outdir / 'output.json') as fp:
|
||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||
content = [json.loads(record) for record in fp]
|
||||
|
||||
assert content == [
|
||||
|
@ -11,7 +11,7 @@ def test_all(app, status, warning):
|
||||
app.builder.build_all()
|
||||
assert (app.outdir / 'sphinxtests.1').exists()
|
||||
|
||||
content = (app.outdir / 'sphinxtests.1').read_text()
|
||||
content = (app.outdir / 'sphinxtests.1').read_text(encoding='utf8')
|
||||
assert r'\fBprint \fP\fIi\fP\fB\en\fP' in content
|
||||
assert r'\fBmanpage\en\fP' in content
|
||||
|
||||
@ -35,7 +35,7 @@ def test_all(app, status, warning):
|
||||
def test_man_pages_empty_description(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'title.1').read_text()
|
||||
content = (app.outdir / 'title.1').read_text(encoding='utf8')
|
||||
assert r'title \-' not in content
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ def test_man_make_section_directory(app, status, warning):
|
||||
@pytest.mark.sphinx('man', testroot='directive-code')
|
||||
def test_captioned_code_block(app, status, warning):
|
||||
app.builder.build_all()
|
||||
content = (app.outdir / 'python.1').read_text()
|
||||
content = (app.outdir / 'python.1').read_text(encoding='utf8')
|
||||
|
||||
assert ('.sp\n'
|
||||
'caption \\fItest\\fP rb\n'
|
||||
@ -80,5 +80,5 @@ def test_default_man_pages():
|
||||
@pytest.mark.sphinx('man', testroot='markup-rubric')
|
||||
def test_rubric(app, status, warning):
|
||||
app.build()
|
||||
content = (app.outdir / 'python.1').read_text()
|
||||
content = (app.outdir / 'python.1').read_text(encoding='utf8')
|
||||
assert 'This is a rubric\n' in content
|
||||
|
@ -41,7 +41,7 @@ def test_texinfo_warnings(app, status, warning):
|
||||
def test_texinfo(app, status, warning):
|
||||
TexinfoTranslator.ignore_missing_images = True
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'sphinxtests.texi').read_text()
|
||||
result = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
|
||||
assert ('@anchor{markup doc}@anchor{11}'
|
||||
'@anchor{markup id1}@anchor{12}'
|
||||
'@anchor{markup testing-various-markup}@anchor{13}' in result)
|
||||
@ -62,7 +62,7 @@ def test_texinfo(app, status, warning):
|
||||
def test_texinfo_rubric(app, status, warning):
|
||||
app.build()
|
||||
|
||||
output = (app.outdir / 'python.texi').read_text()
|
||||
output = (app.outdir / 'python.texi').read_text(encoding='utf8')
|
||||
assert '@heading This is a rubric' in output
|
||||
assert '@heading This is a multiline rubric' in output
|
||||
|
||||
@ -71,7 +71,7 @@ def test_texinfo_rubric(app, status, warning):
|
||||
def test_texinfo_citation(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
output = (app.outdir / 'python.texi').read_text()
|
||||
output = (app.outdir / 'python.texi').read_text(encoding='utf8')
|
||||
assert 'This is a citation ref; @ref{1,,[CITE1]} and @ref{2,,[CITE2]}.' in output
|
||||
assert ('@anchor{index cite1}@anchor{1}@w{(CITE1)} \n'
|
||||
'This is a citation\n') in output
|
||||
@ -110,20 +110,20 @@ def test_texinfo_escape_id(app, status, warning):
|
||||
def test_texinfo_footnote(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
output = (app.outdir / 'python.texi').read_text()
|
||||
output = (app.outdir / 'python.texi').read_text(encoding='utf8')
|
||||
assert 'First footnote: @footnote{\nFirst\n}' in output
|
||||
|
||||
|
||||
@pytest.mark.sphinx('texinfo')
|
||||
def test_texinfo_xrefs(app, status, warning):
|
||||
app.builder.build_all()
|
||||
output = (app.outdir / 'sphinxtests.texi').read_text()
|
||||
output = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
|
||||
assert re.search(r'@ref{\w+,,--plugin\.option}', output)
|
||||
|
||||
# Now rebuild it without xrefs
|
||||
app.config.texinfo_cross_references = False
|
||||
app.builder.build_all()
|
||||
output = (app.outdir / 'sphinxtests.texi').read_text()
|
||||
output = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
|
||||
assert not re.search(r'@ref{\w+,,--plugin\.option}', output)
|
||||
assert 'Link to perl +p, --ObjC++, --plugin.option, create-auth-token, arg and -j' in output
|
||||
|
||||
@ -132,7 +132,7 @@ def test_texinfo_xrefs(app, status, warning):
|
||||
def test_texinfo_samp_with_variable(app, status, warning):
|
||||
app.build()
|
||||
|
||||
output = (app.outdir / 'sphinxtests.texi').read_text()
|
||||
output = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
|
||||
|
||||
assert '@code{@var{variable_only}}' in output
|
||||
assert '@code{@var{variable} and text}' in output
|
||||
|
@ -18,7 +18,7 @@ def with_text_app(*args, **kw):
|
||||
@with_text_app()
|
||||
def test_maxwitdh_with_prefix(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'maxwidth.txt').read_text()
|
||||
result = (app.outdir / 'maxwidth.txt').read_text(encoding='utf8')
|
||||
|
||||
lines = result.splitlines()
|
||||
line_widths = [column_width(line) for line in lines]
|
||||
@ -41,7 +41,7 @@ def test_maxwitdh_with_prefix(app, status, warning):
|
||||
def test_lineblock(app, status, warning):
|
||||
# regression test for #1109: need empty line after line block
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'lineblock.txt').read_text()
|
||||
result = (app.outdir / 'lineblock.txt').read_text(encoding='utf8')
|
||||
expect = (
|
||||
"* one\n"
|
||||
"\n"
|
||||
@ -56,7 +56,7 @@ def test_lineblock(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_nonascii_title_line(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'nonascii_title.txt').read_text()
|
||||
result = (app.outdir / 'nonascii_title.txt').read_text(encoding='utf8')
|
||||
expect_underline = '*********'
|
||||
result_underline = result.splitlines()[1].strip()
|
||||
assert expect_underline == result_underline
|
||||
@ -65,7 +65,7 @@ def test_nonascii_title_line(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_nonascii_table(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'nonascii_table.txt').read_text()
|
||||
result = (app.outdir / 'nonascii_table.txt').read_text(encoding='utf8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
line_widths = [column_width(line) for line in lines]
|
||||
assert len(set(line_widths)) == 1 # same widths
|
||||
@ -74,7 +74,7 @@ def test_nonascii_table(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_nonascii_maxwidth(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'nonascii_maxwidth.txt').read_text()
|
||||
result = (app.outdir / 'nonascii_maxwidth.txt').read_text(encoding='utf8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
line_widths = [column_width(line) for line in lines]
|
||||
assert max(line_widths) < MAXWIDTH
|
||||
@ -118,7 +118,7 @@ def test_table_cell():
|
||||
@with_text_app()
|
||||
def test_table_with_empty_cell(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'table.txt').read_text()
|
||||
result = (app.outdir / 'table.txt').read_text(encoding='utf8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
assert lines[0] == "+-------+-------+"
|
||||
assert lines[1] == "| XXX | XXX |"
|
||||
@ -132,7 +132,7 @@ def test_table_with_empty_cell(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_table_with_rowspan(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'table_rowspan.txt').read_text()
|
||||
result = (app.outdir / 'table_rowspan.txt').read_text(encoding='utf8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
assert lines[0] == "+-------+-------+"
|
||||
assert lines[1] == "| XXXXXXXXX |"
|
||||
@ -146,7 +146,7 @@ def test_table_with_rowspan(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_table_with_colspan(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'table_colspan.txt').read_text()
|
||||
result = (app.outdir / 'table_colspan.txt').read_text(encoding='utf8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
assert lines[0] == "+-------+-------+"
|
||||
assert lines[1] == "| XXX | XXX |"
|
||||
@ -160,7 +160,7 @@ def test_table_with_colspan(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_table_with_colspan_left(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'table_colspan_left.txt').read_text()
|
||||
result = (app.outdir / 'table_colspan_left.txt').read_text(encoding='utf8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
assert lines[0] == "+-------+-------+"
|
||||
assert lines[1] == "| XXX | XXX |"
|
||||
@ -174,7 +174,7 @@ def test_table_with_colspan_left(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_table_with_colspan_and_rowspan(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'table_colspan_and_rowspan.txt').read_text()
|
||||
result = (app.outdir / 'table_colspan_and_rowspan.txt').read_text(encoding='utf8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
assert result
|
||||
assert lines[0] == "+-------+-------+-------+"
|
||||
@ -189,7 +189,7 @@ def test_table_with_colspan_and_rowspan(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_list_items_in_admonition(app, status, warning):
|
||||
app.builder.build_update()
|
||||
result = (app.outdir / 'listitems.txt').read_text()
|
||||
result = (app.outdir / 'listitems.txt').read_text(encoding='utf8')
|
||||
lines = [line.rstrip() for line in result.splitlines()]
|
||||
assert lines[0] == "See also:"
|
||||
assert lines[1] == ""
|
||||
@ -201,7 +201,7 @@ def test_list_items_in_admonition(app, status, warning):
|
||||
@with_text_app()
|
||||
def test_secnums(app, status, warning):
|
||||
app.builder.build_all()
|
||||
index = (app.outdir / 'index.txt').read_text()
|
||||
index = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
lines = index.splitlines()
|
||||
assert lines[0] == "* 1. Section A"
|
||||
assert lines[1] == ""
|
||||
@ -210,7 +210,7 @@ def test_secnums(app, status, warning):
|
||||
assert lines[4] == " * 2.1. Sub Ba"
|
||||
assert lines[5] == ""
|
||||
assert lines[6] == " * 2.2. Sub Bb"
|
||||
doc2 = (app.outdir / 'doc2.txt').read_text()
|
||||
doc2 = (app.outdir / 'doc2.txt').read_text(encoding='utf8')
|
||||
expect = (
|
||||
"2. Section B\n"
|
||||
"************\n"
|
||||
@ -227,7 +227,7 @@ def test_secnums(app, status, warning):
|
||||
|
||||
app.config.text_secnumber_suffix = " "
|
||||
app.builder.build_all()
|
||||
index = (app.outdir / 'index.txt').read_text()
|
||||
index = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
lines = index.splitlines()
|
||||
assert lines[0] == "* 1 Section A"
|
||||
assert lines[1] == ""
|
||||
@ -236,7 +236,7 @@ def test_secnums(app, status, warning):
|
||||
assert lines[4] == " * 2.1 Sub Ba"
|
||||
assert lines[5] == ""
|
||||
assert lines[6] == " * 2.2 Sub Bb"
|
||||
doc2 = (app.outdir / 'doc2.txt').read_text()
|
||||
doc2 = (app.outdir / 'doc2.txt').read_text(encoding='utf8')
|
||||
expect = (
|
||||
"2 Section B\n"
|
||||
"***********\n"
|
||||
@ -253,7 +253,7 @@ def test_secnums(app, status, warning):
|
||||
|
||||
app.config.text_add_secnumbers = False
|
||||
app.builder.build_all()
|
||||
index = (app.outdir / 'index.txt').read_text()
|
||||
index = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
lines = index.splitlines()
|
||||
assert lines[0] == "* Section A"
|
||||
assert lines[1] == ""
|
||||
@ -262,7 +262,7 @@ def test_secnums(app, status, warning):
|
||||
assert lines[4] == " * Sub Ba"
|
||||
assert lines[5] == ""
|
||||
assert lines[6] == " * Sub Bb"
|
||||
doc2 = (app.outdir / 'doc2.txt').read_text()
|
||||
doc2 = (app.outdir / 'doc2.txt').read_text(encoding='utf8')
|
||||
expect = (
|
||||
"Section B\n"
|
||||
"*********\n"
|
||||
|
@ -13,7 +13,7 @@ def test_incremental_reading(app):
|
||||
assert 'subdir/excluded' not in app.env.found_docs
|
||||
|
||||
# before second reading, add, modify and remove source files
|
||||
(app.srcdir / 'new.txt').write_text('New file\n========\n')
|
||||
(app.srcdir / 'new.txt').write_text('New file\n========\n', encoding='utf8')
|
||||
app.env.all_docs['index'] = 0 # mark as modified
|
||||
(app.srcdir / 'autodoc.txt').unlink()
|
||||
|
||||
|
@ -138,7 +138,7 @@ def test_errors_warnings(logger, tempdir):
|
||||
assert 'conf.py' in str(excinfo.value)
|
||||
|
||||
# test the automatic conversion of 2.x only code in configs
|
||||
(tempdir / 'conf.py').write_text('project = u"Jägermeister"\n')
|
||||
(tempdir / 'conf.py').write_text('project = u"Jägermeister"\n', encoding='utf8')
|
||||
cfg = Config.read(tempdir, {}, None)
|
||||
cfg.init_values()
|
||||
assert cfg.project == 'Jägermeister'
|
||||
@ -147,7 +147,7 @@ def test_errors_warnings(logger, tempdir):
|
||||
|
||||
def test_errors_if_setup_is_not_callable(tempdir, make_app):
|
||||
# test the error to call setup() in the config file
|
||||
(tempdir / 'conf.py').write_text('setup = 1')
|
||||
(tempdir / 'conf.py').write_text('setup = 1', encoding='utf8')
|
||||
with pytest.raises(ConfigError) as excinfo:
|
||||
make_app(srcdir=tempdir)
|
||||
assert 'callable' in str(excinfo.value)
|
||||
@ -155,7 +155,7 @@ def test_errors_if_setup_is_not_callable(tempdir, make_app):
|
||||
|
||||
@pytest.fixture
|
||||
def make_app_with_empty_project(make_app, tempdir):
|
||||
(tempdir / 'conf.py').write_text('')
|
||||
(tempdir / 'conf.py').write_text('', encoding='utf8')
|
||||
|
||||
def _make_app(*args, **kw):
|
||||
kw.setdefault('srcdir', path(tempdir))
|
||||
|
@ -24,5 +24,5 @@ def expect_date(request, monkeypatch):
|
||||
@pytest.mark.sphinx('html', testroot='correct-year')
|
||||
def test_correct_year(expect_date, app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert expect_date in content
|
||||
|
@ -28,7 +28,7 @@ def test_LiteralIncludeReader(literal_inc_path):
|
||||
options = {'lineno-match': True}
|
||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||
content, lines = reader.read()
|
||||
assert content == literal_inc_path.read_text()
|
||||
assert content == literal_inc_path.read_text(encoding='utf8')
|
||||
assert lines == 13
|
||||
assert reader.lineno_start == 1
|
||||
|
||||
@ -38,7 +38,7 @@ def test_LiteralIncludeReader_lineno_start(literal_inc_path):
|
||||
options = {'lineno-start': 4}
|
||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||
content, lines = reader.read()
|
||||
assert content == literal_inc_path.read_text()
|
||||
assert content == literal_inc_path.read_text(encoding='utf8')
|
||||
assert lines == 13
|
||||
assert reader.lineno_start == 4
|
||||
|
||||
@ -337,7 +337,7 @@ def test_force_option(app, status, warning):
|
||||
@pytest.mark.sphinx('html', testroot='directive-code')
|
||||
def test_code_block_caption_html(app, status, warning):
|
||||
app.builder.build(['caption'])
|
||||
html = (app.outdir / 'caption.html').read_text()
|
||||
html = (app.outdir / 'caption.html').read_text(encoding='utf8')
|
||||
caption = ('<div class="code-block-caption">'
|
||||
'<span class="caption-number">Listing 1 </span>'
|
||||
'<span class="caption-text">caption <em>test</em> rb'
|
||||
@ -349,7 +349,7 @@ def test_code_block_caption_html(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='directive-code')
|
||||
def test_code_block_caption_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
latex = (app.outdir / 'python.tex').read_text()
|
||||
latex = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}'
|
||||
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}'
|
||||
link = '\\hyperref[\\detokenize{caption:name-test-rb}]' \
|
||||
@ -362,7 +362,7 @@ def test_code_block_caption_latex(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='directive-code')
|
||||
def test_code_block_namedlink_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
latex = (app.outdir / 'python.tex').read_text()
|
||||
latex = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-rb}}}'
|
||||
link1 = '\\hyperref[\\detokenize{caption:name-test-rb}]'\
|
||||
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
|
||||
@ -379,7 +379,7 @@ def test_code_block_namedlink_latex(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='directive-code')
|
||||
def test_code_block_emphasize_latex(app, status, warning):
|
||||
app.builder.build(['emphasize'])
|
||||
latex = (app.outdir / 'python.tex').read_text().replace('\r\n', '\n')
|
||||
latex = (app.outdir / 'python.tex').read_text(encoding='utf8').replace('\r\n', '\n')
|
||||
includes = '\\fvset{hllines={, 5, 6, 13, 14, 15, 24, 25, 26,}}%\n'
|
||||
assert includes in latex
|
||||
includes = '\\end{sphinxVerbatim}\n\\sphinxresetverbatimhllines\n'
|
||||
@ -392,7 +392,7 @@ def test_literal_include(app, status, warning):
|
||||
et = etree_parse(app.outdir / 'index.xml')
|
||||
secs = et.findall('./section/section')
|
||||
literal_include = secs[1].findall('literal_block')
|
||||
literal_src = (app.srcdir / 'literal.inc').read_text()
|
||||
literal_src = (app.srcdir / 'literal.inc').read_text(encoding='utf8')
|
||||
assert len(literal_include) > 0
|
||||
actual = literal_include[0].text
|
||||
assert actual == literal_src
|
||||
@ -425,7 +425,7 @@ def test_literal_include_block_start_with_comment_or_brank(app, status, warning)
|
||||
@pytest.mark.sphinx('html', testroot='directive-code')
|
||||
def test_literal_include_linenos(app, status, warning):
|
||||
app.builder.build(['linenos'])
|
||||
html = (app.outdir / 'linenos.html').read_text()
|
||||
html = (app.outdir / 'linenos.html').read_text(encoding='utf8')
|
||||
|
||||
# :linenos:
|
||||
assert ('<span class="linenos"> 1</span><span class="c1">'
|
||||
@ -443,7 +443,7 @@ def test_literal_include_linenos(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='directive-code')
|
||||
def test_literalinclude_file_whole_of_emptyline(app, status, warning):
|
||||
app.builder.build_all()
|
||||
latex = (app.outdir / 'python.tex').read_text().replace('\r\n', '\n')
|
||||
latex = (app.outdir / 'python.tex').read_text(encoding='utf8').replace('\r\n', '\n')
|
||||
includes = (
|
||||
'\\begin{sphinxVerbatim}'
|
||||
'[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n'
|
||||
@ -457,7 +457,7 @@ def test_literalinclude_file_whole_of_emptyline(app, status, warning):
|
||||
@pytest.mark.sphinx('html', testroot='directive-code')
|
||||
def test_literalinclude_caption_html(app, status, warning):
|
||||
app.builder.build('index')
|
||||
html = (app.outdir / 'caption.html').read_text()
|
||||
html = (app.outdir / 'caption.html').read_text(encoding='utf8')
|
||||
caption = ('<div class="code-block-caption">'
|
||||
'<span class="caption-number">Listing 2 </span>'
|
||||
'<span class="caption-text">caption <strong>test</strong> py'
|
||||
@ -469,7 +469,7 @@ def test_literalinclude_caption_html(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='directive-code')
|
||||
def test_literalinclude_caption_latex(app, status, warning):
|
||||
app.builder.build('index')
|
||||
latex = (app.outdir / 'python.tex').read_text()
|
||||
latex = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}'
|
||||
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}'
|
||||
link = '\\hyperref[\\detokenize{caption:name-test-py}]' \
|
||||
@ -482,7 +482,7 @@ def test_literalinclude_caption_latex(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', testroot='directive-code')
|
||||
def test_literalinclude_namedlink_latex(app, status, warning):
|
||||
app.builder.build('index')
|
||||
latex = (app.outdir / 'python.tex').read_text()
|
||||
latex = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-py}}}'
|
||||
link1 = '\\hyperref[\\detokenize{caption:name-test-py}]'\
|
||||
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
|
||||
@ -569,7 +569,7 @@ def test_code_block_highlighted(app, status, warning):
|
||||
@pytest.mark.sphinx('html', testroot='directive-code')
|
||||
def test_linenothreshold(app, status, warning):
|
||||
app.builder.build(['linenothreshold'])
|
||||
html = (app.outdir / 'linenothreshold.html').read_text()
|
||||
html = (app.outdir / 'linenothreshold.html').read_text(encoding='utf8')
|
||||
|
||||
# code-block using linenothreshold
|
||||
assert ('<span class="linenos">1</span><span class="k">class</span> '
|
||||
@ -591,7 +591,7 @@ def test_linenothreshold(app, status, warning):
|
||||
def test_code_block_dedent(app, status, warning):
|
||||
app.builder.build(['dedent'])
|
||||
doctree = app.env.get_doctree('dedent')
|
||||
codeblocks = list(doctree.traverse(nodes.literal_block))
|
||||
codeblocks = list(doctree.findall(nodes.literal_block))
|
||||
# Note: comparison string should not have newlines at the beginning or end
|
||||
text_0_indent = '''First line
|
||||
Second line
|
||||
|
@ -620,7 +620,7 @@ def filter_warnings(warning, file):
|
||||
|
||||
|
||||
def extract_role_links(app, filename):
|
||||
t = (app.outdir / filename).read_text()
|
||||
t = (app.outdir / filename).read_text(encoding='utf8')
|
||||
lis = [l for l in t.split('\n') if l.startswith("<li")]
|
||||
entries = []
|
||||
for l in lis:
|
||||
@ -650,7 +650,7 @@ def test_domain_c_build_namespace(app, status, warning):
|
||||
app.builder.build_all()
|
||||
ws = filter_warnings(warning, "namespace")
|
||||
assert len(ws) == 0
|
||||
t = (app.outdir / "namespace.html").read_text()
|
||||
t = (app.outdir / "namespace.html").read_text(encoding='utf8')
|
||||
for id_ in ('NS.NSVar', 'NULLVar', 'ZeroVar', 'NS2.NS3.NS2NS3Var', 'PopVar'):
|
||||
assert 'id="c.{}"'.format(id_) in t
|
||||
|
||||
|
@ -1160,14 +1160,14 @@ def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, war
|
||||
]
|
||||
|
||||
f = 'roles.html'
|
||||
t = (app.outdir / f).read_text()
|
||||
t = (app.outdir / f).read_text(encoding='utf8')
|
||||
for s in rolePatterns:
|
||||
check(s, t, f)
|
||||
for s in parenPatterns:
|
||||
check(s, t, f)
|
||||
|
||||
f = 'any-role.html'
|
||||
t = (app.outdir / f).read_text()
|
||||
t = (app.outdir / f).read_text(encoding='utf8')
|
||||
for s in parenPatterns:
|
||||
check(s, t, f)
|
||||
|
||||
@ -1201,14 +1201,14 @@ def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, wa
|
||||
]
|
||||
|
||||
f = 'roles.html'
|
||||
t = (app.outdir / f).read_text()
|
||||
t = (app.outdir / f).read_text(encoding='utf8')
|
||||
for s in rolePatterns:
|
||||
check(s, t, f)
|
||||
for s in parenPatterns:
|
||||
check(s, t, f)
|
||||
|
||||
f = 'any-role.html'
|
||||
t = (app.outdir / f).read_text()
|
||||
t = (app.outdir / f).read_text(encoding='utf8')
|
||||
for s in parenPatterns:
|
||||
check(s, t, f)
|
||||
|
||||
@ -1218,7 +1218,7 @@ def test_domain_cpp_build_xref_consistency(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
test = 'xref_consistency.html'
|
||||
output = (app.outdir / test).read_text()
|
||||
output = (app.outdir / test).read_text(encoding='utf8')
|
||||
|
||||
def classes(role, tag):
|
||||
pattern = (r'{role}-role:.*?'
|
||||
|
@ -131,7 +131,7 @@ def test_domain_py_xrefs(app, status, warning):
|
||||
def test_domain_py_xrefs_abbreviations(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'abbr.html').read_text()
|
||||
content = (app.outdir / 'abbr.html').read_text(encoding='utf8')
|
||||
assert re.search(r'normal: <a .* href="module.html#module_a.submodule.ModTopLevel.'
|
||||
r'mod_child_1" .*><.*>module_a.submodule.ModTopLevel.mod_child_1\(\)'
|
||||
r'<.*></a>',
|
||||
@ -186,7 +186,7 @@ def test_domain_py_objects(app, status, warning):
|
||||
def test_resolve_xref_for_properties(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'module.html').read_text()
|
||||
content = (app.outdir / 'module.html').read_text(encoding='utf8')
|
||||
assert ('Link to <a class="reference internal" href="#module_a.submodule.ModTopLevel.prop"'
|
||||
' title="module_a.submodule.ModTopLevel.prop">'
|
||||
'<code class="xref py py-attr docutils literal notranslate"><span class="pre">'
|
||||
@ -234,7 +234,7 @@ def test_domain_py_find_obj(app, status, warning):
|
||||
def test_domain_py_canonical(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'canonical.html').read_text()
|
||||
content = (app.outdir / 'canonical.html').read_text(encoding='utf8')
|
||||
assert ('<a class="reference internal" href="#canonical.Foo" title="canonical.Foo">'
|
||||
'<code class="xref py py-class docutils literal notranslate">'
|
||||
'<span class="pre">Foo</span></code></a>' in content)
|
||||
@ -1315,7 +1315,7 @@ def test_noindexentry(app):
|
||||
@pytest.mark.sphinx('html', testroot='domain-py-python_use_unqualified_type_names')
|
||||
def test_python_python_use_unqualified_type_names(app, status, warning):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<span class="n"><a class="reference internal" href="#foo.Name" title="foo.Name">'
|
||||
'<span class="pre">Name</span></a></span>' in content)
|
||||
assert '<span class="n"><span class="pre">foo.Age</span></span>' in content
|
||||
@ -1328,7 +1328,7 @@ def test_python_python_use_unqualified_type_names(app, status, warning):
|
||||
confoverrides={'python_use_unqualified_type_names': False})
|
||||
def test_python_python_use_unqualified_type_names_disabled(app, status, warning):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<span class="n"><a class="reference internal" href="#foo.Name" title="foo.Name">'
|
||||
'<span class="pre">foo.Name</span></a></span>' in content)
|
||||
assert '<span class="n"><span class="pre">foo.Age</span></span>' in content
|
||||
|
@ -408,7 +408,7 @@ def test_productionlist(app, status, warning):
|
||||
('SecondLine', 'firstLineRule.html#grammar-token-SecondLine', 'SecondLine'),
|
||||
]
|
||||
|
||||
text = (app.outdir / 'LineContinuation.html').read_text()
|
||||
text = (app.outdir / 'LineContinuation.html').read_text(encoding='utf8')
|
||||
assert "A</strong> ::= B C D E F G" in text
|
||||
|
||||
|
||||
|
@ -62,16 +62,16 @@ def test_pep_0420_enabled(make_app, apidoc):
|
||||
assert (outdir / 'a.b.e.rst').isfile()
|
||||
assert (outdir / 'a.b.x.rst').isfile()
|
||||
|
||||
with open(outdir / 'a.b.c.rst') as f:
|
||||
with open(outdir / 'a.b.c.rst', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert "automodule:: a.b.c.d\n" in rst
|
||||
assert "automodule:: a.b.c\n" in rst
|
||||
|
||||
with open(outdir / 'a.b.e.rst') as f:
|
||||
with open(outdir / 'a.b.e.rst', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert "automodule:: a.b.e.f\n" in rst
|
||||
|
||||
with open(outdir / 'a.b.x.rst') as f:
|
||||
with open(outdir / 'a.b.x.rst', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert "automodule:: a.b.x.y\n" in rst
|
||||
assert "automodule:: a.b.x\n" not in rst
|
||||
@ -86,15 +86,15 @@ def test_pep_0420_enabled(make_app, apidoc):
|
||||
assert (builddir / 'a.b.e.txt').isfile()
|
||||
assert (builddir / 'a.b.x.txt').isfile()
|
||||
|
||||
with open(builddir / 'a.b.c.txt') as f:
|
||||
with open(builddir / 'a.b.c.txt', encoding='utf-8') as f:
|
||||
txt = f.read()
|
||||
assert "a.b.c package\n" in txt
|
||||
|
||||
with open(builddir / 'a.b.e.txt') as f:
|
||||
with open(builddir / 'a.b.e.txt', encoding='utf-8') as f:
|
||||
txt = f.read()
|
||||
assert "a.b.e.f module\n" in txt
|
||||
|
||||
with open(builddir / 'a.b.x.txt') as f:
|
||||
with open(builddir / 'a.b.x.txt', encoding='utf-8') as f:
|
||||
txt = f.read()
|
||||
assert "a.b.x namespace\n" in txt
|
||||
|
||||
@ -112,15 +112,15 @@ def test_pep_0420_enabled_separate(make_app, apidoc):
|
||||
assert (outdir / 'a.b.x.rst').isfile()
|
||||
assert (outdir / 'a.b.x.y.rst').isfile()
|
||||
|
||||
with open(outdir / 'a.b.c.rst') as f:
|
||||
with open(outdir / 'a.b.c.rst', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert ".. toctree::\n :maxdepth: 4\n\n a.b.c.d\n" in rst
|
||||
|
||||
with open(outdir / 'a.b.e.rst') as f:
|
||||
with open(outdir / 'a.b.e.rst', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert ".. toctree::\n :maxdepth: 4\n\n a.b.e.f\n" in rst
|
||||
|
||||
with open(outdir / 'a.b.x.rst') as f:
|
||||
with open(outdir / 'a.b.x.rst', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert ".. toctree::\n :maxdepth: 4\n\n a.b.x.y\n" in rst
|
||||
|
||||
@ -136,15 +136,15 @@ def test_pep_0420_enabled_separate(make_app, apidoc):
|
||||
assert (builddir / 'a.b.x.txt').isfile()
|
||||
assert (builddir / 'a.b.x.y.txt').isfile()
|
||||
|
||||
with open(builddir / 'a.b.c.txt') as f:
|
||||
with open(builddir / 'a.b.c.txt', encoding='utf-8') as f:
|
||||
txt = f.read()
|
||||
assert "a.b.c package\n" in txt
|
||||
|
||||
with open(builddir / 'a.b.e.f.txt') as f:
|
||||
with open(builddir / 'a.b.e.f.txt', encoding='utf-8') as f:
|
||||
txt = f.read()
|
||||
assert "a.b.e.f module\n" in txt
|
||||
|
||||
with open(builddir / 'a.b.x.txt') as f:
|
||||
with open(builddir / 'a.b.x.txt', encoding='utf-8') as f:
|
||||
txt = f.read()
|
||||
assert "a.b.x namespace\n" in txt
|
||||
|
||||
@ -170,7 +170,7 @@ def test_pep_0420_disabled_top_level_verify(make_app, apidoc):
|
||||
assert (outdir / 'c.rst').isfile()
|
||||
assert not (outdir / 'x.rst').exists()
|
||||
|
||||
with open(outdir / 'c.rst') as f:
|
||||
with open(outdir / 'c.rst', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert "c package\n" in rst
|
||||
assert "automodule:: c.d\n" in rst
|
||||
@ -195,7 +195,7 @@ def test_trailing_underscore(make_app, apidoc):
|
||||
print(app._warning.getvalue())
|
||||
|
||||
builddir = outdir / '_build' / 'text'
|
||||
with open(builddir / 'package_.txt') as f:
|
||||
with open(builddir / 'package_.txt', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert "package_ package\n" in rst
|
||||
assert "package_.module_ module\n" in rst
|
||||
@ -276,7 +276,7 @@ def test_multibyte_parameters(make_app, apidoc):
|
||||
assert (outdir / 'conf.py').isfile()
|
||||
assert (outdir / 'index.rst').isfile()
|
||||
|
||||
conf_py = (outdir / 'conf.py').read_text()
|
||||
conf_py = (outdir / 'conf.py').read_text(encoding='utf8')
|
||||
assert "project = 'プロジェクト名'" in conf_py
|
||||
assert "author = '著者名'" in conf_py
|
||||
assert "version = 'バージョン'" in conf_py
|
||||
@ -296,7 +296,7 @@ def test_extension_parsed(make_app, apidoc):
|
||||
outdir = apidoc.outdir
|
||||
assert (outdir / 'conf.py').isfile()
|
||||
|
||||
with open(outdir / 'conf.py') as f:
|
||||
with open(outdir / 'conf.py', encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
assert "sphinx.ext.mathjax" in rst
|
||||
|
||||
@ -364,7 +364,7 @@ def test_toc_all_references_should_exist_pep420_disabled(make_app, apidoc):
|
||||
|
||||
def extract_toc(path):
|
||||
"""Helper: Extract toc section from package rst file"""
|
||||
with open(path) as f:
|
||||
with open(path, encoding='utf-8') as f:
|
||||
rst = f.read()
|
||||
|
||||
# Read out the part containing the toctree
|
||||
@ -390,12 +390,12 @@ def test_subpackage_in_toc(make_app, apidoc):
|
||||
assert (outdir / 'conf.py').isfile()
|
||||
|
||||
assert (outdir / 'parent.rst').isfile()
|
||||
with open(outdir / 'parent.rst') as f:
|
||||
with open(outdir / 'parent.rst', encoding='utf-8') as f:
|
||||
parent = f.read()
|
||||
assert 'parent.child' in parent
|
||||
|
||||
assert (outdir / 'parent.child.rst').isfile()
|
||||
with open(outdir / 'parent.child.rst') as f:
|
||||
with open(outdir / 'parent.child.rst', encoding='utf-8') as f:
|
||||
parent_child = f.read()
|
||||
assert 'parent.child.foo' in parent_child
|
||||
|
||||
@ -403,31 +403,31 @@ def test_subpackage_in_toc(make_app, apidoc):
|
||||
|
||||
|
||||
def test_private(tempdir):
|
||||
(tempdir / 'hello.py').write_text('')
|
||||
(tempdir / '_world.py').write_text('')
|
||||
(tempdir / 'hello.py').write_text('', encoding='utf8')
|
||||
(tempdir / '_world.py').write_text('', encoding='utf8')
|
||||
|
||||
# without --private option
|
||||
apidoc_main(['-o', tempdir, tempdir])
|
||||
assert (tempdir / 'hello.rst').exists()
|
||||
assert ':private-members:' not in (tempdir / 'hello.rst').read_text()
|
||||
assert ':private-members:' not in (tempdir / 'hello.rst').read_text(encoding='utf8')
|
||||
assert not (tempdir / '_world.rst').exists()
|
||||
|
||||
# with --private option
|
||||
apidoc_main(['--private', '-f', '-o', tempdir, tempdir])
|
||||
assert (tempdir / 'hello.rst').exists()
|
||||
assert ':private-members:' in (tempdir / 'hello.rst').read_text()
|
||||
assert ':private-members:' in (tempdir / 'hello.rst').read_text(encoding='utf8')
|
||||
assert (tempdir / '_world.rst').exists()
|
||||
|
||||
|
||||
def test_toc_file(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'module').makedirs()
|
||||
(outdir / 'example.py').write_text('')
|
||||
(outdir / 'module' / 'example.py').write_text('')
|
||||
(outdir / 'example.py').write_text('', encoding='utf8')
|
||||
(outdir / 'module' / 'example.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['-o', tempdir, tempdir])
|
||||
assert (outdir / 'modules.rst').exists()
|
||||
|
||||
content = (outdir / 'modules.rst').read_text()
|
||||
content = (outdir / 'modules.rst').read_text(encoding='utf8')
|
||||
assert content == ("test_toc_file0\n"
|
||||
"==============\n"
|
||||
"\n"
|
||||
@ -439,11 +439,11 @@ def test_toc_file(tempdir):
|
||||
|
||||
def test_module_file(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'example.py').write_text('')
|
||||
(outdir / 'example.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['-o', tempdir, tempdir])
|
||||
assert (outdir / 'example.rst').exists()
|
||||
|
||||
content = (outdir / 'example.rst').read_text()
|
||||
content = (outdir / 'example.rst').read_text(encoding='utf8')
|
||||
assert content == ("example module\n"
|
||||
"==============\n"
|
||||
"\n"
|
||||
@ -455,11 +455,11 @@ def test_module_file(tempdir):
|
||||
|
||||
def test_module_file_noheadings(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'example.py').write_text('')
|
||||
(outdir / 'example.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['--no-headings', '-o', tempdir, tempdir])
|
||||
assert (outdir / 'example.rst').exists()
|
||||
|
||||
content = (outdir / 'example.rst').read_text()
|
||||
content = (outdir / 'example.rst').read_text(encoding='utf8')
|
||||
assert content == (".. automodule:: example\n"
|
||||
" :members:\n"
|
||||
" :undoc-members:\n"
|
||||
@ -469,16 +469,16 @@ def test_module_file_noheadings(tempdir):
|
||||
def test_package_file(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'testpkg').makedirs()
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('')
|
||||
(outdir / 'testpkg' / 'hello.py').write_text('')
|
||||
(outdir / 'testpkg' / 'world.py').write_text('')
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
|
||||
(outdir / 'testpkg' / 'hello.py').write_text('', encoding='utf8')
|
||||
(outdir / 'testpkg' / 'world.py').write_text('', encoding='utf8')
|
||||
(outdir / 'testpkg' / 'subpkg').makedirs()
|
||||
(outdir / 'testpkg' / 'subpkg' / '__init__.py').write_text('')
|
||||
(outdir / 'testpkg' / 'subpkg' / '__init__.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['-o', tempdir, tempdir / 'testpkg'])
|
||||
assert (outdir / 'testpkg.rst').exists()
|
||||
assert (outdir / 'testpkg.subpkg.rst').exists()
|
||||
|
||||
content = (outdir / 'testpkg.rst').read_text()
|
||||
content = (outdir / 'testpkg.rst').read_text(encoding='utf8')
|
||||
assert content == ("testpkg package\n"
|
||||
"===============\n"
|
||||
"\n"
|
||||
@ -517,7 +517,7 @@ def test_package_file(tempdir):
|
||||
" :undoc-members:\n"
|
||||
" :show-inheritance:\n")
|
||||
|
||||
content = (outdir / 'testpkg.subpkg.rst').read_text()
|
||||
content = (outdir / 'testpkg.subpkg.rst').read_text(encoding='utf8')
|
||||
assert content == ("testpkg.subpkg package\n"
|
||||
"======================\n"
|
||||
"\n"
|
||||
@ -533,13 +533,13 @@ def test_package_file(tempdir):
|
||||
def test_package_file_separate(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'testpkg').makedirs()
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('')
|
||||
(outdir / 'testpkg' / 'example.py').write_text('')
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
|
||||
(outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['--separate', '-o', tempdir, tempdir / 'testpkg'])
|
||||
assert (outdir / 'testpkg.rst').exists()
|
||||
assert (outdir / 'testpkg.example.rst').exists()
|
||||
|
||||
content = (outdir / 'testpkg.rst').read_text()
|
||||
content = (outdir / 'testpkg.rst').read_text(encoding='utf8')
|
||||
assert content == ("testpkg package\n"
|
||||
"===============\n"
|
||||
"\n"
|
||||
@ -559,7 +559,7 @@ def test_package_file_separate(tempdir):
|
||||
" :undoc-members:\n"
|
||||
" :show-inheritance:\n")
|
||||
|
||||
content = (outdir / 'testpkg.example.rst').read_text()
|
||||
content = (outdir / 'testpkg.example.rst').read_text(encoding='utf8')
|
||||
assert content == ("testpkg.example module\n"
|
||||
"======================\n"
|
||||
"\n"
|
||||
@ -572,11 +572,11 @@ def test_package_file_separate(tempdir):
|
||||
def test_package_file_module_first(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'testpkg').makedirs()
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('')
|
||||
(outdir / 'testpkg' / 'example.py').write_text('')
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
|
||||
(outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['--module-first', '-o', tempdir, tempdir])
|
||||
|
||||
content = (outdir / 'testpkg.rst').read_text()
|
||||
content = (outdir / 'testpkg.rst').read_text(encoding='utf8')
|
||||
assert content == ("testpkg package\n"
|
||||
"===============\n"
|
||||
"\n"
|
||||
@ -600,11 +600,11 @@ def test_package_file_module_first(tempdir):
|
||||
def test_package_file_without_submodules(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'testpkg').makedirs()
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('')
|
||||
(outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['-o', tempdir, tempdir / 'testpkg'])
|
||||
assert (outdir / 'testpkg.rst').exists()
|
||||
|
||||
content = (outdir / 'testpkg.rst').read_text()
|
||||
content = (outdir / 'testpkg.rst').read_text(encoding='utf8')
|
||||
assert content == ("testpkg package\n"
|
||||
"===============\n"
|
||||
"\n"
|
||||
@ -620,11 +620,11 @@ def test_package_file_without_submodules(tempdir):
|
||||
def test_namespace_package_file(tempdir):
|
||||
outdir = path(tempdir)
|
||||
(outdir / 'testpkg').makedirs()
|
||||
(outdir / 'testpkg' / 'example.py').write_text('')
|
||||
(outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8')
|
||||
apidoc_main(['--implicit-namespace', '-o', tempdir, tempdir / 'testpkg'])
|
||||
assert (outdir / 'testpkg.rst').exists()
|
||||
|
||||
content = (outdir / 'testpkg.rst').read_text()
|
||||
content = (outdir / 'testpkg.rst').read_text(encoding='utf8')
|
||||
assert content == ("testpkg namespace\n"
|
||||
"=================\n"
|
||||
"\n"
|
||||
|
@ -819,7 +819,7 @@ def test_autodoc_typehints_none_for_overload(app):
|
||||
confoverrides={'autodoc_typehints': "description"})
|
||||
def test_autodoc_typehints_description(app):
|
||||
app.build()
|
||||
context = (app.outdir / 'index.txt').read_text()
|
||||
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert ('target.typehints.incr(a, b=1)\n'
|
||||
'\n'
|
||||
' Parameters:\n'
|
||||
@ -865,10 +865,11 @@ def test_autodoc_typehints_description_no_undoc(app):
|
||||
'.. autofunction:: target.typehints.tuple_args\n'
|
||||
'\n'
|
||||
' :param x: arg\n'
|
||||
' :return: another tuple\n'
|
||||
' :return: another tuple\n',
|
||||
encoding='utf8'
|
||||
)
|
||||
app.build()
|
||||
context = (app.outdir / 'index.txt').read_text()
|
||||
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert ('target.typehints.incr(a, b=1)\n'
|
||||
'\n'
|
||||
'target.typehints.decr(a, b=1)\n'
|
||||
@ -917,10 +918,11 @@ def test_autodoc_typehints_description_no_undoc_doc_rtype(app):
|
||||
'\n'
|
||||
'.. autofunction:: target.typehints.Math.horse\n'
|
||||
'\n'
|
||||
' :return: nothing\n'
|
||||
' :return: nothing\n',
|
||||
encoding='utf8'
|
||||
)
|
||||
app.build()
|
||||
context = (app.outdir / 'index.txt').read_text()
|
||||
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert ('target.typehints.incr(a, b=1)\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
@ -961,10 +963,11 @@ def test_autodoc_typehints_description_no_undoc_doc_rtype(app):
|
||||
def test_autodoc_typehints_description_with_documented_init(app):
|
||||
(app.srcdir / 'index.rst').write_text(
|
||||
'.. autoclass:: target.typehints._ClassWithDocumentedInit\n'
|
||||
' :special-members: __init__\n'
|
||||
' :special-members: __init__\n',
|
||||
encoding='utf8'
|
||||
)
|
||||
app.build()
|
||||
context = (app.outdir / 'index.txt').read_text()
|
||||
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert ('class target.typehints._ClassWithDocumentedInit(x)\n'
|
||||
'\n'
|
||||
' Class docstring.\n'
|
||||
@ -992,10 +995,11 @@ def test_autodoc_typehints_description_with_documented_init(app):
|
||||
def test_autodoc_typehints_description_with_documented_init_no_undoc(app):
|
||||
(app.srcdir / 'index.rst').write_text(
|
||||
'.. autoclass:: target.typehints._ClassWithDocumentedInit\n'
|
||||
' :special-members: __init__\n'
|
||||
' :special-members: __init__\n',
|
||||
encoding='utf8'
|
||||
)
|
||||
app.build()
|
||||
context = (app.outdir / 'index.txt').read_text()
|
||||
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert ('class target.typehints._ClassWithDocumentedInit(x)\n'
|
||||
'\n'
|
||||
' Class docstring.\n'
|
||||
@ -1017,10 +1021,11 @@ def test_autodoc_typehints_description_with_documented_init_no_undoc_doc_rtype(a
|
||||
# docstring.
|
||||
(app.srcdir / 'index.rst').write_text(
|
||||
'.. autoclass:: target.typehints._ClassWithDocumentedInit\n'
|
||||
' :special-members: __init__\n'
|
||||
' :special-members: __init__\n',
|
||||
encoding='utf8'
|
||||
)
|
||||
app.build()
|
||||
context = (app.outdir / 'index.txt').read_text()
|
||||
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert ('class target.typehints._ClassWithDocumentedInit(x)\n'
|
||||
'\n'
|
||||
' Class docstring.\n'
|
||||
@ -1048,10 +1053,11 @@ def test_autodoc_typehints_both(app):
|
||||
'\n'
|
||||
'.. autofunction:: target.typehints.tuple_args\n'
|
||||
'\n'
|
||||
'.. autofunction:: target.overload.sum\n'
|
||||
'.. autofunction:: target.overload.sum\n',
|
||||
encoding='utf8'
|
||||
)
|
||||
app.build()
|
||||
context = (app.outdir / 'index.txt').read_text()
|
||||
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert ('target.typehints.incr(a: int, b: int = 1) -> int\n'
|
||||
'\n'
|
||||
' Parameters:\n'
|
||||
@ -1217,9 +1223,9 @@ def test_autodoc_type_aliases(app):
|
||||
confoverrides={'autodoc_typehints': "description",
|
||||
'autodoc_type_aliases': {'myint': 'myint'}})
|
||||
def test_autodoc_typehints_description_and_type_aliases(app):
|
||||
(app.srcdir / 'autodoc_type_aliases.rst').write_text('.. autofunction:: target.autodoc_type_aliases.sum')
|
||||
(app.srcdir / 'autodoc_type_aliases.rst').write_text('.. autofunction:: target.autodoc_type_aliases.sum', encoding='utf8')
|
||||
app.build()
|
||||
context = (app.outdir / 'autodoc_type_aliases.txt').read_text()
|
||||
context = (app.outdir / 'autodoc_type_aliases.txt').read_text(encoding='utf8')
|
||||
assert ('target.autodoc_type_aliases.sum(x, y)\n'
|
||||
'\n'
|
||||
' docstring\n'
|
||||
|
@ -9,7 +9,7 @@ import pytest
|
||||
def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = ('<li><p><a class="reference internal" href="#introduce-of-sphinx">'
|
||||
'<span class=".*?">Introduce of Sphinx</span></a></p></li>')
|
||||
assert re.search(html, content, re.S)
|
||||
@ -53,7 +53,7 @@ def test_autosectionlabel_prefix_document_html(app, status, warning):
|
||||
def test_autosectionlabel_maxdepth(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
# depth: 1
|
||||
html = ('<li><p><a class="reference internal" href="#test-ext-autosectionlabel">'
|
||||
|
@ -332,7 +332,7 @@ def test_autosummary_generate(app, status, warning):
|
||||
assert doctree[3][0][0][2][4].astext() == 'autosummary_dummy_module.bar(x[, y])\n\n'
|
||||
assert doctree[3][0][0][2][5].astext() == 'autosummary_dummy_module.qux\n\na module-level attribute'
|
||||
|
||||
module = (app.srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text()
|
||||
module = (app.srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text(encoding='utf8')
|
||||
|
||||
assert (' .. autosummary::\n'
|
||||
' \n'
|
||||
@ -345,7 +345,7 @@ def test_autosummary_generate(app, status, warning):
|
||||
' quuz\n'
|
||||
' \n' in module)
|
||||
|
||||
Foo = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.rst').read_text()
|
||||
Foo = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.rst').read_text(encoding='utf8')
|
||||
assert '.. automethod:: __init__' in Foo
|
||||
assert (' .. autosummary::\n'
|
||||
' \n'
|
||||
@ -360,17 +360,17 @@ def test_autosummary_generate(app, status, warning):
|
||||
' ~Foo.value\n'
|
||||
' \n' in Foo)
|
||||
|
||||
FooBar = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.Bar.rst').read_text()
|
||||
FooBar = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.Bar.rst').read_text(encoding='utf8')
|
||||
assert ('.. currentmodule:: autosummary_dummy_module\n'
|
||||
'\n'
|
||||
'.. autoclass:: Foo.Bar\n' in FooBar)
|
||||
|
||||
Foo_value = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.value.rst').read_text()
|
||||
Foo_value = (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.value.rst').read_text(encoding='utf8')
|
||||
assert ('.. currentmodule:: autosummary_dummy_module\n'
|
||||
'\n'
|
||||
'.. autoattribute:: Foo.value' in Foo_value)
|
||||
|
||||
qux = (app.srcdir / 'generated' / 'autosummary_dummy_module.qux.rst').read_text()
|
||||
qux = (app.srcdir / 'generated' / 'autosummary_dummy_module.qux.rst').read_text(encoding='utf8')
|
||||
assert ('.. currentmodule:: autosummary_dummy_module\n'
|
||||
'\n'
|
||||
'.. autodata:: qux' in qux)
|
||||
@ -383,10 +383,10 @@ def test_autosummary_generate_overwrite1(app_params, make_app):
|
||||
srcdir = kwargs.get('srcdir')
|
||||
|
||||
(srcdir / 'generated').makedirs(exist_ok=True)
|
||||
(srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('')
|
||||
(srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('', encoding='utf8')
|
||||
|
||||
app = make_app(*args, **kwargs)
|
||||
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text()
|
||||
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text(encoding='utf8')
|
||||
assert content == ''
|
||||
assert 'autosummary_dummy_module.rst' not in app._warning.getvalue()
|
||||
|
||||
@ -398,10 +398,10 @@ def test_autosummary_generate_overwrite2(app_params, make_app):
|
||||
srcdir = kwargs.get('srcdir')
|
||||
|
||||
(srcdir / 'generated').makedirs(exist_ok=True)
|
||||
(srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('')
|
||||
(srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('', encoding='utf8')
|
||||
|
||||
app = make_app(*args, **kwargs)
|
||||
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text()
|
||||
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text(encoding='utf8')
|
||||
assert content != ''
|
||||
assert 'autosummary_dummy_module.rst' not in app._warning.getvalue()
|
||||
|
||||
@ -425,12 +425,12 @@ def test_autosummary_recursive(app, status, warning):
|
||||
assert (app.srcdir / 'generated' / 'package2.module.rst').exists() is False
|
||||
|
||||
# Check content of recursively generated stub-files
|
||||
content = (app.srcdir / 'generated' / 'package.rst').read_text()
|
||||
content = (app.srcdir / 'generated' / 'package.rst').read_text(encoding='utf8')
|
||||
assert 'package.module' in content
|
||||
assert 'package.package' in content
|
||||
assert 'package.module_importfail' in content
|
||||
|
||||
content = (app.srcdir / 'generated' / 'package.package.rst').read_text()
|
||||
content = (app.srcdir / 'generated' / 'package.package.rst').read_text(encoding='utf8')
|
||||
assert 'package.package.module' in content
|
||||
|
||||
|
||||
@ -465,7 +465,7 @@ def test_autosummary_filename_map(app, status, warning):
|
||||
@pytest.mark.sphinx('latex', **default_kw)
|
||||
def test_autosummary_latex_table_colspec(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert r'\begin{longtable}[c]{\X{1}{2}\X{1}{2}}' in result
|
||||
@ -515,7 +515,7 @@ def test_autosummary_imported_members(app, status, warning):
|
||||
# generated/foo is generated successfully
|
||||
assert app.env.get_doctree('generated/autosummary_dummy_package')
|
||||
|
||||
module = (app.srcdir / 'generated' / 'autosummary_dummy_package.rst').read_text()
|
||||
module = (app.srcdir / 'generated' / 'autosummary_dummy_package.rst').read_text(encoding='utf8')
|
||||
assert (' .. autosummary::\n'
|
||||
' \n'
|
||||
' Bar\n'
|
||||
@ -535,7 +535,7 @@ def test_generate_autosummary_docs_property(app):
|
||||
mock.return_value = [AutosummaryEntry('target.methods.Base.prop', 'prop', None, False)]
|
||||
generate_autosummary_docs([], output_dir=app.srcdir, app=app)
|
||||
|
||||
content = (app.srcdir / 'target.methods.Base.prop.rst').read_text()
|
||||
content = (app.srcdir / 'target.methods.Base.prop.rst').read_text(encoding='utf8')
|
||||
assert content == ("target.methods.Base.prop\n"
|
||||
"========================\n"
|
||||
"\n"
|
||||
@ -548,7 +548,7 @@ def test_generate_autosummary_docs_property(app):
|
||||
def test_autosummary_skip_member(app):
|
||||
app.build()
|
||||
|
||||
content = (app.srcdir / 'generate' / 'target.Foo.rst').read_text()
|
||||
content = (app.srcdir / 'generate' / 'target.Foo.rst').read_text(encoding='utf8')
|
||||
assert 'Foo.skipmeth' not in content
|
||||
assert 'Foo._privatemeth' in content
|
||||
|
||||
@ -557,7 +557,7 @@ def test_autosummary_skip_member(app):
|
||||
def test_autosummary_template(app):
|
||||
app.build()
|
||||
|
||||
content = (app.srcdir / 'generate' / 'target.Foo.rst').read_text()
|
||||
content = (app.srcdir / 'generate' / 'target.Foo.rst').read_text(encoding='utf8')
|
||||
assert 'EMPTY' in content
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ import pytest
|
||||
def test_build(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
py_undoc = (app.outdir / 'python.txt').read_text()
|
||||
py_undoc = (app.outdir / 'python.txt').read_text(encoding='utf8')
|
||||
assert py_undoc.startswith('Undocumented Python objects\n'
|
||||
'===========================\n')
|
||||
assert 'autodoc_target\n--------------\n' in py_undoc
|
||||
@ -22,7 +22,7 @@ def test_build(app, status, warning):
|
||||
|
||||
assert "undocumented py" not in status.getvalue()
|
||||
|
||||
c_undoc = (app.outdir / 'c.txt').read_text()
|
||||
c_undoc = (app.outdir / 'c.txt').read_text(encoding='utf8')
|
||||
assert c_undoc.startswith('Undocumented C API elements\n'
|
||||
'===========================\n')
|
||||
assert 'api.h' in c_undoc
|
||||
@ -46,7 +46,7 @@ def test_build(app, status, warning):
|
||||
@pytest.mark.sphinx('coverage', testroot='ext-coverage')
|
||||
def test_coverage_ignore_pyobjects(app, status, warning):
|
||||
app.builder.build_all()
|
||||
actual = (app.outdir / 'python.txt').read_text()
|
||||
actual = (app.outdir / 'python.txt').read_text(encoding='utf8')
|
||||
expected = '''Undocumented Python objects
|
||||
===========================
|
||||
coverage_not_ignored
|
||||
|
@ -23,4 +23,4 @@ def test_no_cname_for_github_io_domain(app, status, warning):
|
||||
def test_cname_for_custom_domain(app, status, warning):
|
||||
app.builder.build_all()
|
||||
assert (app.outdir / '.nojekyll').exists()
|
||||
assert (app.outdir / 'CNAME').read_text() == 'sphinx-doc.org'
|
||||
assert (app.outdir / 'CNAME').read_text(encoding='utf8') == 'sphinx-doc.org'
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
import re
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
|
||||
from sphinx.ext.graphviz import ClickableMapDefinition
|
||||
from sphinx.util import docutils
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-graphviz')
|
||||
@ -13,7 +13,7 @@ from sphinx.util import docutils
|
||||
def test_graphviz_png_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
html = (r'<div class="figure align-default" .*?>\s*'
|
||||
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
|
||||
@ -56,7 +56,7 @@ def test_graphviz_png_html(app, status, warning):
|
||||
def test_graphviz_svg_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
html = (r'<div class=\"figure align-default\" .*?>\n'
|
||||
@ -118,7 +118,7 @@ def test_graphviz_svg_html(app, status, warning):
|
||||
def test_graphviz_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n'
|
||||
'\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n'
|
||||
'\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}')
|
||||
@ -144,7 +144,7 @@ def test_graphviz_latex(app, status, warning):
|
||||
def test_graphviz_i18n(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = '<img src=".*?" alt="digraph {\n BAR -> BAZ\n}" class="graphviz" />'
|
||||
assert re.search(html, content, re.M)
|
||||
|
||||
|
@ -6,6 +6,6 @@ import pytest
|
||||
@pytest.mark.sphinx('text', testroot='ext-ifconfig')
|
||||
def test_ifconfig(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'index.txt').read_text()
|
||||
result = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert 'spam' in result
|
||||
assert 'ham' not in result
|
||||
|
@ -10,7 +10,7 @@ import pytest
|
||||
def test_ext_imgconverter(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
|
||||
# supported image (not converted)
|
||||
assert '\\sphinxincludegraphics{{img}.pdf}' in content
|
||||
|
@ -4,11 +4,11 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
|
||||
from sphinx.ext.inheritance_diagram import (InheritanceDiagram, InheritanceException,
|
||||
import_classes)
|
||||
from sphinx.util import docutils
|
||||
|
||||
|
||||
@pytest.mark.sphinx(buildername="html", testroot="inheritance")
|
||||
@ -138,7 +138,7 @@ def test_inheritance_diagram(app, status, warning):
|
||||
def test_inheritance_diagram_png_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
pattern = ('<div class="figure align-default" id="id1">\n'
|
||||
@ -163,7 +163,7 @@ def test_inheritance_diagram_png_html(app, status, warning):
|
||||
def test_inheritance_diagram_svg_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
pattern = ('<div class="figure align-default" id="id1">\n'
|
||||
@ -192,7 +192,7 @@ def test_inheritance_diagram_svg_html(app, status, warning):
|
||||
def test_inheritance_diagram_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
|
||||
pattern = ('\\\\begin{figure}\\[htbp]\n\\\\centering\n\\\\capstart\n\n'
|
||||
'\\\\sphinxincludegraphics\\[\\]{inheritance-\\w+.pdf}\n'
|
||||
@ -214,7 +214,7 @@ def test_inheritance_diagram_latex_alias(app, status, warning):
|
||||
assert ('test.Bar', 'test.Bar', ['alias.Foo'], None) in aliased_graph
|
||||
assert ('alias.Foo', 'alias.Foo', [], None) in aliased_graph
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
pattern = ('<div class="figure align-default" id="id1">\n'
|
||||
|
@ -246,7 +246,7 @@ def test_missing_reference_cppdomain(tempdir, app, status, warning):
|
||||
load_mappings(app)
|
||||
|
||||
app.build()
|
||||
html = (app.outdir / 'index.html').read_text()
|
||||
html = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<a class="reference external"'
|
||||
' href="https://docs.python.org/index.html#cpp_foo_bar"'
|
||||
' title="(in foo v2.0)">'
|
||||
@ -533,7 +533,7 @@ def test_intersphinx_role(app, warning):
|
||||
load_mappings(app)
|
||||
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
wStr = warning.getvalue()
|
||||
|
||||
html = '<a class="reference external" href="http://example.org/{}" title="(in foo v2.0)">'
|
||||
|
@ -32,7 +32,7 @@ def test_imgmath_png(app, status, warning):
|
||||
if "dvipng command 'dvipng' cannot be run" in warning.getvalue():
|
||||
raise pytest.skip.Exception('dvipng command "dvipng" is not available')
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"'
|
||||
r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
@ -50,7 +50,7 @@ def test_imgmath_svg(app, status, warning):
|
||||
if "dvisvgm command 'dvisvgm' cannot be run" in warning.getvalue():
|
||||
raise pytest.skip.Exception('dvisvgm command "dvisvgm" is not available')
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"'
|
||||
r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
@ -62,7 +62,7 @@ def test_imgmath_svg(app, status, warning):
|
||||
def test_mathjax_options(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<script async="async" integrity="sha384-0123456789" '
|
||||
'src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">'
|
||||
'</script>' in content)
|
||||
@ -73,7 +73,7 @@ def test_mathjax_options(app, status, warning):
|
||||
def test_mathjax_align(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = (r'<div class="math notranslate nohighlight">\s*'
|
||||
r'\\\[ \\begin\{align\}\\begin\{aligned\}S \&= \\pi r\^2\\\\'
|
||||
r'V \&= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]</div>')
|
||||
@ -86,7 +86,7 @@ def test_mathjax_align(app, status, warning):
|
||||
def test_math_number_all_mathjax(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
html = (r'<div class="math notranslate nohighlight" id="equation-index-0">\s*'
|
||||
r'<span class="eqno">\(1\)<a .*>\xb6</a></span>\\\[a\^2\+b\^2=c\^2\\\]</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
@ -97,7 +97,7 @@ def test_math_number_all_mathjax(app, status, warning):
|
||||
def test_math_number_all_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
macro = (r'\\begin{equation\*}\s*'
|
||||
r'\\begin{split}a\^2\+b\^2=c\^2\\end{split}\s*'
|
||||
r'\\end{equation\*}')
|
||||
@ -127,7 +127,7 @@ def test_math_number_all_latex(app, status, warning):
|
||||
def test_math_eqref_format_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'math.html').read_text()
|
||||
content = (app.outdir / 'math.html').read_text(encoding='utf8')
|
||||
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>.</p>')
|
||||
@ -140,7 +140,7 @@ def test_math_eqref_format_html(app, status, warning):
|
||||
def test_math_eqref_format_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
macro = (r'Referencing equation Eq.\\ref{equation:math:foo} and '
|
||||
r'Eq.\\ref{equation:math:foo}.')
|
||||
assert re.search(macro, content, re.S)
|
||||
@ -153,7 +153,7 @@ def test_math_eqref_format_latex(app, status, warning):
|
||||
def test_mathjax_numfig_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'math.html').read_text()
|
||||
content = (app.outdir / 'math.html').read_text(encoding='utf8')
|
||||
html = ('<div class="math notranslate nohighlight" id="equation-math-0">\n'
|
||||
'<span class="eqno">(1.2)')
|
||||
assert html in content
|
||||
@ -171,7 +171,7 @@ def test_mathjax_numfig_html(app, status, warning):
|
||||
def test_imgmath_numfig_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'page.html').read_text()
|
||||
content = (app.outdir / 'page.html').read_text(encoding='utf8')
|
||||
html = '<span class="eqno">(3)<a class="headerlink" href="#equation-bar"'
|
||||
assert html in content
|
||||
html = ('<p>Referencing equations <a class="reference internal" '
|
||||
@ -211,7 +211,7 @@ def test_math_compat(app, status, warning):
|
||||
def test_mathjax3_config(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert MATHJAX_URL in content
|
||||
assert ('<script defer="defer" src="%s">' % MATHJAX_URL in content)
|
||||
assert ('<script>window.MathJax = {"extensions": ["tex2jax.js"]}</script>' in content)
|
||||
@ -223,7 +223,7 @@ def test_mathjax3_config(app, status, warning):
|
||||
def test_mathjax2_config(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<script async="async" src="%s">' % MATHJAX_URL in content)
|
||||
assert ('<script type="text/x-mathjax-config">'
|
||||
'MathJax.Hub.Config({"extensions": ["tex2jax.js"]})'
|
||||
@ -237,7 +237,7 @@ def test_mathjax2_config(app, status, warning):
|
||||
def test_mathjax_options_async_for_mathjax3(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert MATHJAX_URL in content
|
||||
assert ('<script async="async" src="%s">' % MATHJAX_URL in content)
|
||||
|
||||
@ -249,7 +249,7 @@ def test_mathjax_options_async_for_mathjax3(app, status, warning):
|
||||
def test_mathjax_options_defer_for_mathjax2(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<script defer="defer" src="%s">' % MATHJAX_URL in content)
|
||||
|
||||
|
||||
@ -258,10 +258,10 @@ def test_mathjax_options_defer_for_mathjax2(app, status, warning):
|
||||
def test_mathjax_is_installed_only_if_document_having_math(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert MATHJAX_URL in content
|
||||
|
||||
content = (app.outdir / 'nomath.html').read_text()
|
||||
content = (app.outdir / 'nomath.html').read_text(encoding='utf8')
|
||||
assert MATHJAX_URL not in content
|
||||
|
||||
|
||||
@ -270,7 +270,7 @@ def test_mathjax_is_installed_only_if_document_having_math(app, status, warning)
|
||||
def test_mathjax_is_not_installed_if_no_equations(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert 'MathJax.js' not in content
|
||||
|
||||
|
||||
@ -280,8 +280,8 @@ def test_mathjax_is_installed_if_no_equations_when_forced(app, status, warning):
|
||||
app.set_html_assets_policy('always')
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert MATHJAX_URL in content
|
||||
|
||||
content = (app.outdir / 'nomath.html').read_text()
|
||||
content = (app.outdir / 'nomath.html').read_text(encoding='utf8')
|
||||
assert MATHJAX_URL in content
|
||||
|
@ -17,7 +17,7 @@ def test_todo(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
# check todolist
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<p class="admonition-title">Todo</p>\n'
|
||||
'<p>todo in foo</p>') in content
|
||||
|
||||
@ -25,7 +25,7 @@ def test_todo(app, status, warning):
|
||||
'<p>todo in bar</p>') in content
|
||||
|
||||
# check todo
|
||||
content = (app.outdir / 'foo.html').read_text()
|
||||
content = (app.outdir / 'foo.html').read_text(encoding='utf8')
|
||||
assert ('<p class="admonition-title">Todo</p>\n'
|
||||
'<p>todo in foo</p>') in content
|
||||
|
||||
@ -55,7 +55,7 @@ def test_todo_not_included(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
# check todolist
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<p class="admonition-title">Todo</p>\n'
|
||||
'<p>todo in foo</p>') not in content
|
||||
|
||||
@ -63,7 +63,7 @@ def test_todo_not_included(app, status, warning):
|
||||
'<p>todo in bar</p>') not in content
|
||||
|
||||
# check todo
|
||||
content = (app.outdir / 'foo.html').read_text()
|
||||
content = (app.outdir / 'foo.html').read_text(encoding='utf8')
|
||||
assert ('<p class="admonition-title">Todo</p>\n'
|
||||
'<p>todo in foo</p>') not in content
|
||||
|
||||
@ -90,7 +90,7 @@ def test_todo_valid_link(app, status, warning):
|
||||
# Ensure the LaTeX output is built.
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
|
||||
# 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
|
||||
|
@ -16,7 +16,7 @@ def test_viewcode(app, status, warning):
|
||||
warnings
|
||||
)
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
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/mod1.html#Class1"') == 2
|
||||
@ -29,7 +29,7 @@ def test_viewcode(app, status, warning):
|
||||
# the next assert fails, until the autodoc bug gets fixed
|
||||
assert result.count('this is the class attribute class_attr') == 2
|
||||
|
||||
result = (app.outdir / '_modules/spam/mod1.html').read_text()
|
||||
result = (app.outdir / '_modules/spam/mod1.html').read_text(encoding='utf8')
|
||||
result = re.sub('<span class=".*?">', '<span>', result) # filter pygments classes
|
||||
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
|
||||
'href="../../index.html#spam.Class1">[docs]</a>'
|
||||
@ -47,7 +47,7 @@ def test_viewcode_epub_default(app, status, warning):
|
||||
|
||||
assert not (app.outdir / '_modules/spam/mod1.xhtml').exists()
|
||||
|
||||
result = (app.outdir / 'index.xhtml').read_text()
|
||||
result = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
|
||||
assert result.count('href="_modules/spam/mod1.xhtml#func1"') == 0
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ def test_viewcode_epub_enabled(app, status, warning):
|
||||
|
||||
assert (app.outdir / '_modules/spam/mod1.xhtml').exists()
|
||||
|
||||
result = (app.outdir / 'index.xhtml').read_text()
|
||||
result = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
|
||||
assert result.count('href="_modules/spam/mod1.xhtml#func1"') == 2
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ def test_viewcode_epub_enabled(app, status, warning):
|
||||
def test_linkcode(app, status, warning):
|
||||
app.builder.build(['objects'])
|
||||
|
||||
stuff = (app.outdir / 'objects.html').read_text()
|
||||
stuff = (app.outdir / 'objects.html').read_text(encoding='utf8')
|
||||
|
||||
assert 'http://foobar/source/foolib.py' in stuff
|
||||
assert 'http://foobar/js/' in stuff
|
||||
@ -78,7 +78,7 @@ def test_linkcode(app, status, warning):
|
||||
def test_local_source_files(app, status, warning):
|
||||
def find_source(app, modname):
|
||||
if modname == 'not_a_package':
|
||||
source = (app.srcdir / 'not_a_package/__init__.py').read_text()
|
||||
source = (app.srcdir / 'not_a_package/__init__.py').read_text(encoding='utf8')
|
||||
tags = {
|
||||
'func1': ('def', 1, 1),
|
||||
'Class1': ('class', 1, 1),
|
||||
@ -86,7 +86,7 @@ def test_local_source_files(app, status, warning):
|
||||
'not_a_package.submodule.Class1': ('class', 1, 1),
|
||||
}
|
||||
else:
|
||||
source = (app.srcdir / 'not_a_package/submodule.py').read_text()
|
||||
source = (app.srcdir / 'not_a_package/submodule.py').read_text(encoding='utf8')
|
||||
tags = {
|
||||
'not_a_package.submodule.func1': ('def', 11, 15),
|
||||
'Class1': ('class', 19, 22),
|
||||
@ -106,7 +106,7 @@ def test_local_source_files(app, status, warning):
|
||||
warnings
|
||||
)
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
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/submodule.html#Class1"') == 1
|
||||
|
@ -6,6 +6,7 @@ Runs the text builder in the test root.
|
||||
import os
|
||||
import re
|
||||
|
||||
import docutils
|
||||
import pygments
|
||||
import pytest
|
||||
from babel.messages import mofile, pofile
|
||||
@ -15,7 +16,6 @@ from docutils import nodes
|
||||
from sphinx import locale
|
||||
from sphinx.testing.util import (assert_node, assert_not_re_search, assert_re_search,
|
||||
assert_startswith, etree_parse, path, strip_escseq)
|
||||
from sphinx.util import docutils
|
||||
|
||||
sphinx_intl = pytest.mark.sphinx(
|
||||
testroot='intl',
|
||||
@ -29,7 +29,7 @@ pygments_version = tuple(int(v) for v in pygments.__version__.split('.'))
|
||||
|
||||
|
||||
def read_po(pathname):
|
||||
with pathname.open() as f:
|
||||
with pathname.open(encoding='utf-8') as f:
|
||||
return pofile.read_po(f)
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ def test_text_emit_warnings(app, warning):
|
||||
def test_text_warning_node(app):
|
||||
app.build()
|
||||
# test warnings in translation
|
||||
result = (app.outdir / 'warnings.txt').read_text()
|
||||
result = (app.outdir / 'warnings.txt').read_text(encoding='utf8')
|
||||
expect = ("3. I18N WITH REST WARNINGS"
|
||||
"\n**************************\n"
|
||||
"\nLINE OF >>``<<BROKEN LITERAL MARKUP.\n")
|
||||
@ -119,7 +119,7 @@ def test_text_warning_node(app):
|
||||
def test_text_title_underline(app):
|
||||
app.build()
|
||||
# --- simple translation; check title underlines
|
||||
result = (app.outdir / 'bom.txt').read_text()
|
||||
result = (app.outdir / 'bom.txt').read_text(encoding='utf8')
|
||||
expect = ("2. Datei mit UTF-8"
|
||||
"\n******************\n" # underline matches new translation
|
||||
"\nThis file has umlauts: äöü.\n")
|
||||
@ -132,7 +132,7 @@ def test_text_title_underline(app):
|
||||
def test_text_subdirs(app):
|
||||
app.build()
|
||||
# --- check translation in subdirs
|
||||
result = (app.outdir / 'subdir' / 'index.txt').read_text()
|
||||
result = (app.outdir / 'subdir' / 'index.txt').read_text(encoding='utf8')
|
||||
assert_startswith(result, "1. subdir contents\n******************\n")
|
||||
|
||||
|
||||
@ -142,7 +142,7 @@ def test_text_subdirs(app):
|
||||
def test_text_inconsistency_warnings(app, warning):
|
||||
app.build()
|
||||
# --- check warnings for inconsistency in number of references
|
||||
result = (app.outdir / 'refs_inconsistency.txt').read_text()
|
||||
result = (app.outdir / 'refs_inconsistency.txt').read_text(encoding='utf8')
|
||||
expect = ("8. I18N WITH REFS INCONSISTENCY"
|
||||
"\n*******************************\n"
|
||||
"\n* FOR CITATION [ref3].\n"
|
||||
@ -191,7 +191,7 @@ def test_text_inconsistency_warnings(app, warning):
|
||||
@pytest.mark.test_params(shared_result='test_intl_basic')
|
||||
def test_noqa(app, warning):
|
||||
app.build()
|
||||
result = (app.outdir / 'noqa.txt').read_text()
|
||||
result = (app.outdir / 'noqa.txt').read_text(encoding='utf8')
|
||||
expect = r"""FIRST SECTION
|
||||
*************
|
||||
|
||||
@ -218,7 +218,7 @@ TO TEST BARE noqa.
|
||||
def test_text_literalblock_warnings(app, warning):
|
||||
app.build()
|
||||
# --- check warning for literal block
|
||||
result = (app.outdir / 'literalblock.txt').read_text()
|
||||
result = (app.outdir / 'literalblock.txt').read_text(encoding='utf8')
|
||||
expect = ("9. I18N WITH LITERAL BLOCK"
|
||||
"\n**************************\n"
|
||||
"\nCORRECT LITERAL BLOCK:\n"
|
||||
@ -240,7 +240,7 @@ def test_text_literalblock_warnings(app, warning):
|
||||
def test_text_definition_terms(app):
|
||||
app.build()
|
||||
# --- definition terms: regression test for #975, #2198, #2205
|
||||
result = (app.outdir / 'definition_terms.txt').read_text()
|
||||
result = (app.outdir / 'definition_terms.txt').read_text(encoding='utf8')
|
||||
expect = ("13. I18N WITH DEFINITION TERMS"
|
||||
"\n******************************\n"
|
||||
"\nSOME TERM"
|
||||
@ -260,7 +260,7 @@ def test_text_definition_terms(app):
|
||||
def test_text_glossary_term(app, warning):
|
||||
app.build()
|
||||
# --- glossary terms: regression test for #1090
|
||||
result = (app.outdir / 'glossary_terms.txt').read_text()
|
||||
result = (app.outdir / 'glossary_terms.txt').read_text(encoding='utf8')
|
||||
expect = (r"""18. I18N WITH GLOSSARY TERMS
|
||||
****************************
|
||||
|
||||
@ -295,7 +295,7 @@ VVV
|
||||
def test_text_glossary_term_inconsistencies(app, warning):
|
||||
app.build()
|
||||
# --- glossary term inconsistencies: regression test for #1090
|
||||
result = (app.outdir / 'glossary_terms_inconsistency.txt').read_text()
|
||||
result = (app.outdir / 'glossary_terms_inconsistency.txt').read_text(encoding='utf8')
|
||||
expect = ("19. I18N WITH GLOSSARY TERMS INCONSISTENCY"
|
||||
"\n******************************************\n"
|
||||
"\n1. LINK TO *SOME NEW TERM*.\n")
|
||||
@ -328,7 +328,7 @@ def test_gettext_section(app):
|
||||
def test_text_section(app):
|
||||
app.build()
|
||||
# --- section
|
||||
result = (app.outdir / 'section.txt').read_text()
|
||||
result = (app.outdir / 'section.txt').read_text(encoding='utf8')
|
||||
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'section.po')
|
||||
for expect_msg in [m for m in expect if m.id]:
|
||||
assert expect_msg.string in result
|
||||
@ -340,7 +340,7 @@ def test_text_section(app):
|
||||
def test_text_seealso(app):
|
||||
app.build()
|
||||
# --- seealso
|
||||
result = (app.outdir / 'seealso.txt').read_text()
|
||||
result = (app.outdir / 'seealso.txt').read_text(encoding='utf8')
|
||||
expect = ("12. I18N WITH SEEALSO"
|
||||
"\n*********************\n"
|
||||
"\nSee also: SHORT TEXT 1\n"
|
||||
@ -357,7 +357,7 @@ def test_text_seealso(app):
|
||||
def test_text_figure_captions(app):
|
||||
app.build()
|
||||
# --- figure captions: regression test for #940
|
||||
result = (app.outdir / 'figure.txt').read_text()
|
||||
result = (app.outdir / 'figure.txt').read_text(encoding='utf8')
|
||||
expect = ("14. I18N WITH FIGURE CAPTION"
|
||||
"\n****************************\n"
|
||||
"\n [image]MY CAPTION OF THE FIGURE\n"
|
||||
@ -401,7 +401,7 @@ def test_text_figure_captions(app):
|
||||
def test_text_rubric(app):
|
||||
app.build()
|
||||
# --- rubric: regression test for pull request #190
|
||||
result = (app.outdir / 'rubric.txt').read_text()
|
||||
result = (app.outdir / 'rubric.txt').read_text(encoding='utf8')
|
||||
expect = ("I18N WITH RUBRIC"
|
||||
"\n****************\n"
|
||||
"\n-[ RUBRIC TITLE ]-\n"
|
||||
@ -419,7 +419,7 @@ def test_text_rubric(app):
|
||||
def test_text_docfields(app):
|
||||
app.build()
|
||||
# --- docfields
|
||||
result = (app.outdir / 'docfields.txt').read_text()
|
||||
result = (app.outdir / 'docfields.txt').read_text(encoding='utf8')
|
||||
expect = ("21. I18N WITH DOCFIELDS"
|
||||
"\n***********************\n"
|
||||
"\nclass Cls1\n"
|
||||
@ -450,7 +450,7 @@ def test_text_admonitions(app):
|
||||
# --- admonitions
|
||||
# #1206: gettext did not translate admonition directive's title
|
||||
# seealso: https://docutils.sourceforge.io/docs/ref/rst/directives.html#admonitions
|
||||
result = (app.outdir / 'admonitions.txt').read_text()
|
||||
result = (app.outdir / 'admonitions.txt').read_text(encoding='utf8')
|
||||
directives = (
|
||||
"attention", "caution", "danger", "error", "hint",
|
||||
"important", "note", "tip", "warning", "admonition")
|
||||
@ -497,7 +497,7 @@ def test_gettext_table(app):
|
||||
def test_text_table(app):
|
||||
app.build()
|
||||
# --- toctree
|
||||
result = (app.outdir / 'table.txt').read_text()
|
||||
result = (app.outdir / 'table.txt').read_text(encoding='utf8')
|
||||
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'table.po')
|
||||
for expect_msg in [m for m in expect if m.id]:
|
||||
assert expect_msg.string in result
|
||||
@ -510,11 +510,11 @@ def test_text_toctree(app):
|
||||
app.build()
|
||||
# --- toctree (index.rst)
|
||||
# Note: index.rst contains contents that is not shown in text.
|
||||
result = (app.outdir / 'index.txt').read_text()
|
||||
result = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert 'CONTENTS' in result
|
||||
assert 'TABLE OF CONTENTS' in result
|
||||
# --- toctree (toctree.rst)
|
||||
result = (app.outdir / 'toctree.txt').read_text()
|
||||
result = (app.outdir / 'toctree.txt').read_text(encoding='utf8')
|
||||
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'toctree.po')
|
||||
for expect_msg in [m for m in expect if m.id]:
|
||||
assert expect_msg.string in result
|
||||
@ -538,7 +538,7 @@ def test_gettext_topic(app):
|
||||
def test_text_topic(app):
|
||||
app.build()
|
||||
# --- topic
|
||||
result = (app.outdir / 'topic.txt').read_text()
|
||||
result = (app.outdir / 'topic.txt').read_text(encoding='utf8')
|
||||
expect = read_po(app.srcdir / 'xx' / 'LC_MESSAGES' / 'topic.po')
|
||||
for expect_msg in [m for m in expect if m.id]:
|
||||
assert expect_msg.string in result
|
||||
@ -656,7 +656,7 @@ def test_gettext_dont_rebuild_mo(make_app, app_params):
|
||||
def test_html_meta(app):
|
||||
app.build()
|
||||
# --- test for meta
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
expected_expr = '<meta content="TESTDATA FOR I18N" name="description" />'
|
||||
assert expected_expr in result
|
||||
expected_expr = '<meta content="I18N, SPHINX, MARKUP" name="keywords" />'
|
||||
@ -672,7 +672,7 @@ def test_html_footnotes(app):
|
||||
app.build()
|
||||
# --- test for #955 cant-build-html-with-footnotes-when-using
|
||||
# expect no error by build
|
||||
(app.outdir / 'footnote.html').read_text()
|
||||
(app.outdir / 'footnote.html').read_text(encoding='utf8')
|
||||
|
||||
|
||||
@sphinx_intl
|
||||
@ -681,7 +681,7 @@ def test_html_footnotes(app):
|
||||
def test_html_undefined_refs(app):
|
||||
app.build()
|
||||
# --- links to undefined reference
|
||||
result = (app.outdir / 'refs_inconsistency.html').read_text()
|
||||
result = (app.outdir / 'refs_inconsistency.html').read_text(encoding='utf8')
|
||||
|
||||
expected_expr = ('<a class="reference external" '
|
||||
'href="http://www.example.com">reference</a>')
|
||||
@ -703,7 +703,7 @@ def test_html_undefined_refs(app):
|
||||
def test_html_index_entries(app):
|
||||
app.build()
|
||||
# --- index entries: regression test for #976
|
||||
result = (app.outdir / 'genindex.html').read_text()
|
||||
result = (app.outdir / 'genindex.html').read_text(encoding='utf8')
|
||||
|
||||
def wrap(tag, keyword):
|
||||
start_tag = "<%s[^>]*>" % tag
|
||||
@ -741,7 +741,7 @@ def test_html_index_entries(app):
|
||||
def test_html_versionchanges(app):
|
||||
app.build()
|
||||
# --- versionchanges
|
||||
result = (app.outdir / 'versionchange.html').read_text()
|
||||
result = (app.outdir / 'versionchange.html').read_text(encoding='utf8')
|
||||
|
||||
def get_content(result, name):
|
||||
matched = re.search(r'<div class="%s">\n*(.*?)</div>' % name,
|
||||
@ -778,7 +778,7 @@ def test_html_docfields(app):
|
||||
app.build()
|
||||
# --- docfields
|
||||
# expect no error by build
|
||||
(app.outdir / 'docfields.html').read_text()
|
||||
(app.outdir / 'docfields.html').read_text(encoding='utf8')
|
||||
|
||||
|
||||
@sphinx_intl
|
||||
@ -787,7 +787,7 @@ def test_html_docfields(app):
|
||||
def test_html_template(app):
|
||||
app.build()
|
||||
# --- gettext template
|
||||
result = (app.outdir / 'contents.html').read_text()
|
||||
result = (app.outdir / 'contents.html').read_text(encoding='utf8')
|
||||
assert "WELCOME" in result
|
||||
assert "SPHINX 2013.120" in result
|
||||
|
||||
@ -1084,7 +1084,7 @@ def test_xml_label_targets(app):
|
||||
def test_additional_targets_should_not_be_translated(app):
|
||||
app.build()
|
||||
# [literalblock.txt]
|
||||
result = (app.outdir / 'literalblock.html').read_text()
|
||||
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
||||
|
||||
# title should be translated
|
||||
expected_expr = 'CODE-BLOCKS'
|
||||
@ -1125,7 +1125,7 @@ def test_additional_targets_should_not_be_translated(app):
|
||||
|
||||
# [raw.txt]
|
||||
|
||||
result = (app.outdir / 'raw.html').read_text()
|
||||
result = (app.outdir / 'raw.html').read_text(encoding='utf8')
|
||||
|
||||
# raw block should not be translated
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
@ -1137,7 +1137,7 @@ def test_additional_targets_should_not_be_translated(app):
|
||||
|
||||
# [figure.txt]
|
||||
|
||||
result = (app.outdir / 'figure.html').read_text()
|
||||
result = (app.outdir / 'figure.html').read_text(encoding='utf8')
|
||||
|
||||
# src for image block should not be translated (alt is translated)
|
||||
expected_expr = """<img alt="I18N -> IMG" src="_images/i18n.png" />"""
|
||||
@ -1167,7 +1167,7 @@ def test_additional_targets_should_not_be_translated(app):
|
||||
def test_additional_targets_should_be_translated(app):
|
||||
app.build()
|
||||
# [literalblock.txt]
|
||||
result = (app.outdir / 'literalblock.html').read_text()
|
||||
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
||||
|
||||
# title should be translated
|
||||
expected_expr = 'CODE-BLOCKS'
|
||||
@ -1211,7 +1211,7 @@ def test_additional_targets_should_be_translated(app):
|
||||
|
||||
# [raw.txt]
|
||||
|
||||
result = (app.outdir / 'raw.html').read_text()
|
||||
result = (app.outdir / 'raw.html').read_text(encoding='utf8')
|
||||
|
||||
# raw block should be translated
|
||||
if docutils.__version_info__ < (0, 17):
|
||||
@ -1223,7 +1223,7 @@ def test_additional_targets_should_be_translated(app):
|
||||
|
||||
# [figure.txt]
|
||||
|
||||
result = (app.outdir / 'figure.html').read_text()
|
||||
result = (app.outdir / 'figure.html').read_text(encoding='utf8')
|
||||
|
||||
# alt and src for image block should be translated
|
||||
expected_expr = """<img alt="I18N -> IMG" src="_images/img.png" />"""
|
||||
@ -1355,7 +1355,7 @@ def test_gettext_allow_fuzzy_translations(app):
|
||||
pofile.write_po(f, catalog)
|
||||
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert 'FEATURES' in content
|
||||
|
||||
|
||||
@ -1374,7 +1374,7 @@ def test_gettext_disallow_fuzzy_translations(app):
|
||||
pofile.write_po(f, catalog)
|
||||
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert 'FEATURES' not in content
|
||||
|
||||
|
||||
@ -1399,7 +1399,7 @@ def test_customize_system_message(make_app, app_params, sphinx_test_tempdir):
|
||||
assert app.translator.gettext('Quick search') == 'QUICK SEARCH'
|
||||
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert 'QUICK SEARCH' in content
|
||||
finally:
|
||||
locale.translators.clear()
|
||||
|
@ -1,7 +1,9 @@
|
||||
"""Test various Sphinx-specific markup extensions."""
|
||||
|
||||
import re
|
||||
import warnings
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
from docutils import frontend, nodes, utils
|
||||
from docutils.parsers.rst import Parser as RstParser
|
||||
@ -13,7 +15,7 @@ from sphinx.environment import default_settings
|
||||
from sphinx.roles import XRefRole
|
||||
from sphinx.testing.util import Struct, assert_node
|
||||
from sphinx.transforms import SphinxSmartQuotes
|
||||
from sphinx.util import docutils, texescape
|
||||
from sphinx.util import texescape
|
||||
from sphinx.util.docutils import sphinx_domains
|
||||
from sphinx.writers.html import HTMLTranslator, HTMLWriter
|
||||
from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter
|
||||
@ -22,9 +24,13 @@ from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter
|
||||
@pytest.fixture
|
||||
def settings(app):
|
||||
texescape.init() # otherwise done by the latex builder
|
||||
optparser = frontend.OptionParser(
|
||||
components=(RstParser, HTMLWriter, LaTeXWriter),
|
||||
defaults=default_settings)
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
# DeprecationWarning: The frontend.OptionParser class will be replaced
|
||||
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
|
||||
optparser = frontend.OptionParser(
|
||||
components=(RstParser, HTMLWriter, LaTeXWriter),
|
||||
defaults=default_settings)
|
||||
settings = optparser.get_default_values()
|
||||
settings.smart_quotes = True
|
||||
settings.env = app.builder.env
|
||||
|
@ -65,7 +65,7 @@ def test_project_doc2path(app):
|
||||
assert project.doc2path('foo') == (app.srcdir / 'foo.rst')
|
||||
|
||||
# matched source_suffix is used if exists
|
||||
(app.srcdir / 'foo.txt').write_text('')
|
||||
(app.srcdir / 'foo.txt').write_text('', encoding='utf8')
|
||||
assert project.doc2path('foo') == (app.srcdir / 'foo.txt')
|
||||
|
||||
# absolute path
|
||||
|
@ -100,7 +100,7 @@ def test_quickstart_defaults(tempdir):
|
||||
conffile = tempdir / 'conf.py'
|
||||
assert conffile.isfile()
|
||||
ns = {}
|
||||
exec(conffile.read_text(), ns)
|
||||
exec(conffile.read_text(encoding='utf8'), ns)
|
||||
assert ns['extensions'] == []
|
||||
assert ns['templates_path'] == ['_templates']
|
||||
assert ns['project'] == 'Sphinx Test'
|
||||
@ -150,7 +150,7 @@ def test_quickstart_all_answers(tempdir):
|
||||
conffile = tempdir / 'source' / 'conf.py'
|
||||
assert conffile.isfile()
|
||||
ns = {}
|
||||
exec(conffile.read_text(), ns)
|
||||
exec(conffile.read_text(encoding='utf8'), ns)
|
||||
assert ns['extensions'] == [
|
||||
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo'
|
||||
]
|
||||
@ -231,7 +231,7 @@ def test_default_filename(tempdir):
|
||||
conffile = tempdir / 'conf.py'
|
||||
assert conffile.isfile()
|
||||
ns = {}
|
||||
exec(conffile.read_text(), ns)
|
||||
exec(conffile.read_text(encoding='utf8'), ns)
|
||||
|
||||
|
||||
def test_extensions(tempdir):
|
||||
@ -241,7 +241,7 @@ def test_extensions(tempdir):
|
||||
conffile = tempdir / 'conf.py'
|
||||
assert conffile.isfile()
|
||||
ns = {}
|
||||
exec(conffile.read_text(), ns)
|
||||
exec(conffile.read_text(encoding='utf8'), ns)
|
||||
assert ns['extensions'] == ['foo', 'bar', 'baz']
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Test the search index builder."""
|
||||
|
||||
import json
|
||||
import warnings
|
||||
from collections import namedtuple
|
||||
from io import BytesIO
|
||||
|
||||
@ -27,13 +28,17 @@ settings = parser = None
|
||||
|
||||
def setup_module():
|
||||
global settings, parser
|
||||
optparser = frontend.OptionParser(components=(rst.Parser,))
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
# DeprecationWarning: The frontend.OptionParser class will be replaced
|
||||
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
|
||||
optparser = frontend.OptionParser(components=(rst.Parser,))
|
||||
settings = optparser.get_default_values()
|
||||
parser = rst.Parser()
|
||||
|
||||
|
||||
def load_searchindex(path):
|
||||
searchindex = path.read_text()
|
||||
searchindex = path.read_text(encoding='utf8')
|
||||
assert searchindex.startswith('Search.setIndex(')
|
||||
assert searchindex.endswith(')')
|
||||
|
||||
@ -94,7 +99,7 @@ def test_meta_keys_are_handled_for_language_de(app, status, warning):
|
||||
@pytest.mark.sphinx(testroot='search')
|
||||
def test_stemmer_does_not_remove_short_words(app, status, warning):
|
||||
app.builder.build_all()
|
||||
searchindex = (app.outdir / 'searchindex.js').read_text()
|
||||
searchindex = (app.outdir / 'searchindex.js').read_text(encoding='utf8')
|
||||
assert 'zfs' in searchindex
|
||||
|
||||
|
||||
@ -108,7 +113,7 @@ def test_stemmer(app, status, warning):
|
||||
|
||||
@pytest.mark.sphinx(testroot='search')
|
||||
def test_term_in_heading_and_section(app, status, warning):
|
||||
searchindex = (app.outdir / 'searchindex.js').read_text()
|
||||
searchindex = (app.outdir / 'searchindex.js').read_text(encoding='utf8')
|
||||
# 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,
|
||||
# respectively text hit
|
||||
|
@ -83,10 +83,10 @@ def nonascii_srcdir(request, setup_command):
|
||||
(srcdir / mb_name / (mb_name + '.txt')).write_text(dedent("""
|
||||
multi byte file name page
|
||||
==========================
|
||||
"""))
|
||||
"""), encoding='utf8')
|
||||
|
||||
root_doc = srcdir / 'index.txt'
|
||||
root_doc.write_bytes((root_doc.read_text() + dedent("""
|
||||
root_doc.write_bytes((root_doc.read_text(encoding='utf8') + dedent("""
|
||||
.. toctree::
|
||||
|
||||
%(mb_name)s/%(mb_name)s
|
||||
@ -106,7 +106,8 @@ def test_build_sphinx_with_nonascii_path(setup_command):
|
||||
def test_build_sphinx_return_nonzero_status(setup_command):
|
||||
srcdir = (setup_command.pkgroot / 'doc')
|
||||
(srcdir / 'contents.txt').write_text(
|
||||
'http://localhost.unexistentdomain/index.html')
|
||||
'http://localhost.unexistentdomain/index.html',
|
||||
encoding='utf8')
|
||||
proc = setup_command.proc
|
||||
out, err = proc.communicate()
|
||||
print(out.decode())
|
||||
@ -117,7 +118,8 @@ def test_build_sphinx_return_nonzero_status(setup_command):
|
||||
def test_build_sphinx_warning_return_zero_status(setup_command):
|
||||
srcdir = (setup_command.pkgroot / 'doc')
|
||||
(srcdir / 'contents.txt').write_text(
|
||||
'See :ref:`unexisting-reference-label`')
|
||||
'See :ref:`unexisting-reference-label`',
|
||||
encoding='utf8')
|
||||
proc = setup_command.proc
|
||||
out, err = proc.communicate()
|
||||
print(out.decode())
|
||||
@ -129,7 +131,8 @@ def test_build_sphinx_warning_return_zero_status(setup_command):
|
||||
def test_build_sphinx_warning_is_error_return_nonzero_status(setup_command):
|
||||
srcdir = (setup_command.pkgroot / 'doc')
|
||||
(srcdir / 'contents.txt').write_text(
|
||||
'See :ref:`unexisting-reference-label`')
|
||||
'See :ref:`unexisting-reference-label`',
|
||||
encoding='utf8')
|
||||
proc = setup_command.proc
|
||||
out, err = proc.communicate()
|
||||
print(out.decode())
|
||||
|
@ -1,16 +1,15 @@
|
||||
"""Test smart quotes."""
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
from html5lib import HTMLParser
|
||||
|
||||
from sphinx.util import docutils
|
||||
|
||||
|
||||
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
|
||||
def test_basic(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<p>– “Sphinx” is a tool that makes it easy …</p>' in content
|
||||
|
||||
|
||||
@ -18,7 +17,7 @@ def test_basic(app, status, warning):
|
||||
def test_literals(app, status, warning):
|
||||
app.build()
|
||||
|
||||
with (app.outdir / 'literals.html').open() as html_file:
|
||||
with (app.outdir / 'literals.html').open(encoding='utf-8') as html_file:
|
||||
etree = HTMLParser(namespaceHTMLElements=False).parse(html_file)
|
||||
|
||||
for code_element in etree.iter('code'):
|
||||
@ -36,7 +35,7 @@ def test_literals(app, status, warning):
|
||||
def test_text_builder(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'index.txt').read_text()
|
||||
content = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
||||
assert '-- "Sphinx" is a tool that makes it easy ...' in content
|
||||
|
||||
|
||||
@ -44,7 +43,7 @@ def test_text_builder(app, status, warning):
|
||||
def test_man_builder(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'python.1').read_text()
|
||||
content = (app.outdir / 'python.1').read_text(encoding='utf8')
|
||||
if docutils.__version_info__ > (0, 18):
|
||||
assert r'\-\- \(dqSphinx\(dq is a tool that makes it easy ...' in content
|
||||
else:
|
||||
@ -55,7 +54,7 @@ def test_man_builder(app, status, warning):
|
||||
def test_latex_builder(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert '\\textendash{} “Sphinx” is a tool that makes it easy …' in content
|
||||
|
||||
|
||||
@ -64,7 +63,7 @@ def test_latex_builder(app, status, warning):
|
||||
def test_ja_html_builder(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<p>-- "Sphinx" is a tool that makes it easy ...</p>' in content
|
||||
|
||||
|
||||
@ -73,7 +72,7 @@ def test_ja_html_builder(app, status, warning):
|
||||
def test_smartquotes_disabled(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<p>-- "Sphinx" is a tool that makes it easy ...</p>' in content
|
||||
|
||||
|
||||
@ -82,7 +81,7 @@ def test_smartquotes_disabled(app, status, warning):
|
||||
def test_smartquotes_action(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<p>-- “Sphinx” is a tool that makes it easy ...</p>' in content
|
||||
|
||||
|
||||
@ -91,7 +90,7 @@ def test_smartquotes_action(app, status, warning):
|
||||
def test_smartquotes_excludes_language(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<p>– 「Sphinx」 is a tool that makes it easy …</p>' in content
|
||||
|
||||
|
||||
@ -100,5 +99,5 @@ def test_smartquotes_excludes_language(app, status, warning):
|
||||
def test_smartquotes_excludes_builders(app, status, warning):
|
||||
app.build()
|
||||
|
||||
content = (app.outdir / 'python.1').read_text()
|
||||
content = (app.outdir / 'python.1').read_text(encoding='utf8')
|
||||
assert '– “Sphinx” is a tool that makes it easy …' in content
|
||||
|
@ -12,7 +12,7 @@ def test_layout_overloading(make_app, app_params):
|
||||
setup_documenters(app)
|
||||
app.builder.build_update()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<!-- layout overloading -->' in result
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ def test_autosummary_class_template_overloading(make_app, app_params):
|
||||
setup_documenters(app)
|
||||
app.builder.build_update()
|
||||
|
||||
result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').read_text()
|
||||
result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').read_text(encoding='utf8')
|
||||
assert 'autosummary/class.rst method block overloading' in result
|
||||
assert 'foobar' not in result
|
||||
|
||||
@ -36,6 +36,6 @@ def test_autosummary_context(make_app, app_params):
|
||||
setup_documenters(app)
|
||||
app.builder.build_update()
|
||||
|
||||
result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').read_text()
|
||||
result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').read_text(encoding='utf8')
|
||||
assert 'autosummary/class.rst method block overloading' in result
|
||||
assert 'foobar' in result
|
||||
|
@ -68,16 +68,16 @@ def test_js_source(app, status, warning):
|
||||
|
||||
v = '3.5.1'
|
||||
msg = 'jquery.js version does not match to {v}'.format(v=v)
|
||||
jquery_min = (app.outdir / '_static' / 'jquery.js').read_text()
|
||||
jquery_min = (app.outdir / '_static' / 'jquery.js').read_text(encoding='utf8')
|
||||
assert 'jQuery v{v}'.format(v=v) in jquery_min, msg
|
||||
jquery_src = (app.outdir / '_static' / 'jquery-{v}.js'.format(v=v)).read_text()
|
||||
jquery_src = (app.outdir / '_static' / 'jquery-{v}.js'.format(v=v)).read_text(encoding='utf8')
|
||||
assert 'jQuery JavaScript Library v{v}'.format(v=v) in jquery_src, msg
|
||||
|
||||
v = '1.13.1'
|
||||
msg = 'underscore.js version does not match to {v}'.format(v=v)
|
||||
underscore_min = (app.outdir / '_static' / 'underscore.js').read_text()
|
||||
underscore_min = (app.outdir / '_static' / 'underscore.js').read_text(encoding='utf8')
|
||||
assert 'Underscore.js {v}'.format(v=v) in underscore_min, msg
|
||||
underscore_src = (app.outdir / '_static' / 'underscore-{v}.js'.format(v=v)).read_text()
|
||||
underscore_src = (app.outdir / '_static' / 'underscore-{v}.js'.format(v=v)).read_text(encoding='utf8')
|
||||
assert 'Underscore.js {v}'.format(v=v) in underscore_src, msg
|
||||
|
||||
|
||||
@ -100,12 +100,12 @@ def test_staticfiles(app, status, warning):
|
||||
app.build()
|
||||
assert (app.outdir / '_static' / 'staticimg.png').exists()
|
||||
assert (app.outdir / '_static' / 'statictmpl.html').exists()
|
||||
assert (app.outdir / '_static' / 'statictmpl.html').read_text() == (
|
||||
assert (app.outdir / '_static' / 'statictmpl.html').read_text(encoding='utf8') == (
|
||||
'<!-- testing static templates -->\n'
|
||||
'<html><project>Python</project></html>'
|
||||
)
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<meta name="testopt" content="optdefault" />' in result
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ def test_dark_style(app, status, warning):
|
||||
app.build()
|
||||
assert (app.outdir / '_static' / 'pygments_dark.css').exists()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<link rel="stylesheet" type="text/css" href="_static/pygments.css" />' in result
|
||||
assert ('<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" '
|
||||
'rel="stylesheet" type="text/css" '
|
||||
@ -130,7 +130,7 @@ def test_theme_sidebars(app, status, warning):
|
||||
app.build()
|
||||
|
||||
# test-theme specifies globaltoc and searchbox as default sidebars
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<h3><a href="#">Table of Contents</a></h3>' in result
|
||||
assert '<h3>Related Topics</h3>' not in result
|
||||
assert '<h3>This Page</h3>' not in result
|
||||
|
@ -33,7 +33,7 @@ def test_singlehtml_toctree(app, status, warning):
|
||||
@pytest.mark.sphinx(testroot='toctree', srcdir="numbered-toctree")
|
||||
def test_numbered_toctree(app, status, warning):
|
||||
# give argument to :numbered: option
|
||||
index = (app.srcdir / 'index.rst').read_text()
|
||||
index = (app.srcdir / 'index.rst').read_text(encoding='utf8')
|
||||
index = re.sub(':numbered:.*', ':numbered: 1', index)
|
||||
(app.srcdir / 'index.rst').write_text(index)
|
||||
(app.srcdir / 'index.rst').write_text(index, encoding='utf8')
|
||||
app.builder.build_all()
|
||||
|
@ -10,7 +10,7 @@ def test_nitpicky_warning(app, status, warning):
|
||||
assert ('index.rst:4: WARNING: py:class reference target '
|
||||
'not found: io.StringIO' in warning.getvalue())
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert ('<p><code class="xref py py-class docutils literal notranslate"><span class="pre">'
|
||||
'io.StringIO</span></code></p>' in content)
|
||||
|
||||
@ -31,7 +31,7 @@ def test_missing_reference(app, status, warning):
|
||||
app.build()
|
||||
assert warning.getvalue() == ''
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<p><span>missing-reference.StringIO</span></p>' in content
|
||||
|
||||
|
||||
@ -46,5 +46,5 @@ def test_missing_reference_conditional_pending_xref(app, status, warning):
|
||||
app.build()
|
||||
assert warning.getvalue() == ''
|
||||
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert '<span class="n"><span class="pre">Age</span></span>' in content
|
||||
|
@ -5,7 +5,7 @@ import pytest
|
||||
def test_trim_doctest_flags_html(app, status, warning):
|
||||
app.build()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert 'FOO' not in result
|
||||
assert 'BAR' in result
|
||||
assert 'BAZ' not in result
|
||||
@ -20,7 +20,7 @@ def test_trim_doctest_flags_html(app, status, warning):
|
||||
def test_trim_doctest_flags_disabled(app, status, warning):
|
||||
app.build()
|
||||
|
||||
result = (app.outdir / 'index.html').read_text()
|
||||
result = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
assert 'FOO' in result
|
||||
assert 'BAR' in result
|
||||
assert 'BAZ' in result
|
||||
@ -34,7 +34,7 @@ def test_trim_doctest_flags_disabled(app, status, warning):
|
||||
def test_trim_doctest_flags_latex(app, status, warning):
|
||||
app.build()
|
||||
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
||||
assert 'FOO' not in result
|
||||
assert 'BAR' in result
|
||||
assert 'BAZ' not in result
|
||||
|
@ -25,7 +25,7 @@ def test_copy_asset_file(tempdir):
|
||||
|
||||
copy_asset_file(src, dest)
|
||||
assert dest.exists()
|
||||
assert src.read_text() == dest.read_text()
|
||||
assert src.read_text(encoding='utf8') == dest.read_text(encoding='utf8')
|
||||
|
||||
# copy template file
|
||||
src = (tempdir / 'asset.txt_t')
|
||||
@ -35,7 +35,7 @@ def test_copy_asset_file(tempdir):
|
||||
copy_asset_file(src, dest, {'var1': 'template'}, renderer)
|
||||
assert not dest.exists()
|
||||
assert (tempdir / 'output.txt').exists()
|
||||
assert (tempdir / 'output.txt').read_text() == '# template data'
|
||||
assert (tempdir / 'output.txt').read_text(encoding='utf8') == '# template data'
|
||||
|
||||
# copy template file to subdir
|
||||
src = (tempdir / 'asset.txt_t')
|
||||
@ -45,7 +45,7 @@ def test_copy_asset_file(tempdir):
|
||||
|
||||
copy_asset_file(src, subdir1, {'var1': 'template'}, renderer)
|
||||
assert (subdir1 / 'asset.txt').exists()
|
||||
assert (subdir1 / 'asset.txt').read_text() == '# template data'
|
||||
assert (subdir1 / 'asset.txt').read_text(encoding='utf8') == '# template data'
|
||||
|
||||
# copy template file without context
|
||||
src = (tempdir / 'asset.txt_t')
|
||||
@ -55,7 +55,7 @@ def test_copy_asset_file(tempdir):
|
||||
copy_asset_file(src, subdir2)
|
||||
assert not (subdir2 / 'asset.txt').exists()
|
||||
assert (subdir2 / 'asset.txt_t').exists()
|
||||
assert (subdir2 / 'asset.txt_t').read_text() == '# {{var1}} data'
|
||||
assert (subdir2 / 'asset.txt_t').read_text(encoding='utf8') == '# {{var1}} data'
|
||||
|
||||
|
||||
def test_copy_asset(tempdir):
|
||||
@ -64,13 +64,13 @@ def test_copy_asset(tempdir):
|
||||
# prepare source files
|
||||
source = (tempdir / 'source')
|
||||
source.makedirs()
|
||||
(source / 'index.rst').write_text('index.rst')
|
||||
(source / 'foo.rst_t').write_text('{{var1}}.rst')
|
||||
(source / 'index.rst').write_text('index.rst', encoding='utf8')
|
||||
(source / 'foo.rst_t').write_text('{{var1}}.rst', encoding='utf8')
|
||||
(source / '_static').makedirs()
|
||||
(source / '_static' / 'basic.css').write_text('basic.css')
|
||||
(source / '_static' / 'basic.css').write_text('basic.css', encoding='utf8')
|
||||
(source / '_templates').makedirs()
|
||||
(source / '_templates' / 'layout.html').write_text('layout.html')
|
||||
(source / '_templates' / 'sidebar.html_t').write_text('sidebar: {{var2}}')
|
||||
(source / '_templates' / 'layout.html').write_text('layout.html', encoding='utf8')
|
||||
(source / '_templates' / 'sidebar.html_t').write_text('sidebar: {{var2}}', encoding='utf8')
|
||||
|
||||
# copy a single file
|
||||
assert not (tempdir / 'test1').exists()
|
||||
@ -83,11 +83,11 @@ def test_copy_asset(tempdir):
|
||||
copy_asset(source, destdir, context=dict(var1='bar', var2='baz'), renderer=renderer)
|
||||
assert (destdir / 'index.rst').exists()
|
||||
assert (destdir / 'foo.rst').exists()
|
||||
assert (destdir / 'foo.rst').read_text() == 'bar.rst'
|
||||
assert (destdir / 'foo.rst').read_text(encoding='utf8') == 'bar.rst'
|
||||
assert (destdir / '_static' / 'basic.css').exists()
|
||||
assert (destdir / '_templates' / 'layout.html').exists()
|
||||
assert (destdir / '_templates' / 'sidebar.html').exists()
|
||||
assert (destdir / '_templates' / 'sidebar.html').read_text() == 'sidebar: baz'
|
||||
assert (destdir / '_templates' / 'sidebar.html').read_text(encoding='utf8') == 'sidebar: baz'
|
||||
|
||||
# copy with exclusion
|
||||
def excluded(path):
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
from babel.messages.mofile import read_mo
|
||||
@ -27,12 +28,12 @@ def test_catalog_info_for_sub_domain_file_and_path():
|
||||
|
||||
|
||||
def test_catalog_outdated(tempdir):
|
||||
(tempdir / 'test.po').write_text('#')
|
||||
(tempdir / 'test.po').write_text('#', encoding='utf8')
|
||||
cat = i18n.CatalogInfo(tempdir, 'test', 'utf-8')
|
||||
assert cat.is_outdated() # if mo is not exist
|
||||
|
||||
mo_file = (tempdir / 'test.mo')
|
||||
mo_file.write_text('#')
|
||||
mo_file.write_text('#', encoding='utf8')
|
||||
assert not cat.is_outdated() # if mo is exist and newer than po
|
||||
|
||||
os.utime(mo_file, (os.stat(mo_file).st_mtime - 10,) * 2) # to be outdate
|
||||
@ -40,7 +41,7 @@ def test_catalog_outdated(tempdir):
|
||||
|
||||
|
||||
def test_catalog_write_mo(tempdir):
|
||||
(tempdir / 'test.po').write_text('#')
|
||||
(tempdir / 'test.po').write_text('#', encoding='utf8')
|
||||
cat = i18n.CatalogInfo(tempdir, 'test', 'utf-8')
|
||||
cat.write_mo('en')
|
||||
assert os.path.exists(cat.mo_path)
|
||||
@ -53,7 +54,11 @@ def test_format_date():
|
||||
|
||||
# strftime format
|
||||
format = '%B %d, %Y'
|
||||
assert i18n.format_date(format, date=date) == 'February 07, 2016'
|
||||
with warnings.catch_warnings():
|
||||
# Test format_date() with no language argument -- this form will be
|
||||
# removed in Sphinx 7 (xref RemovedInSphinx70Warning)
|
||||
warnings.simplefilter("ignore")
|
||||
assert i18n.format_date(format, date=date) == 'February 07, 2016'
|
||||
assert i18n.format_date(format, date=date, language='') == 'February 07, 2016'
|
||||
assert i18n.format_date(format, date=date, language='unknown') == 'February 07, 2016'
|
||||
assert i18n.format_date(format, date=date, language='en') == 'February 07, 2016'
|
||||
@ -62,28 +67,28 @@ def test_format_date():
|
||||
|
||||
# raw string
|
||||
format = 'Mon Mar 28 12:37:08 2016, commit 4367aef'
|
||||
assert i18n.format_date(format, date=date) == format
|
||||
assert i18n.format_date(format, date=date, language='en') == format
|
||||
|
||||
format = '%B %d, %Y, %H:%M:%S %I %p'
|
||||
datet = datetime.datetime(2016, 2, 7, 5, 11, 17, 0)
|
||||
assert i18n.format_date(format, date=datet) == 'February 07, 2016, 05:11:17 05 AM'
|
||||
assert i18n.format_date(format, date=datet, language='en') == 'February 07, 2016, 05:11:17 05 AM'
|
||||
|
||||
format = '%B %-d, %Y, %-H:%-M:%-S %-I %p'
|
||||
assert i18n.format_date(format, date=datet) == 'February 7, 2016, 5:11:17 5 AM'
|
||||
assert i18n.format_date(format, date=datet, language='en') == 'February 7, 2016, 5:11:17 5 AM'
|
||||
format = '%x'
|
||||
assert i18n.format_date(format, date=datet) == 'Feb 7, 2016'
|
||||
assert i18n.format_date(format, date=datet, language='en') == 'Feb 7, 2016'
|
||||
format = '%X'
|
||||
assert i18n.format_date(format, date=datet) == '5:11:17 AM'
|
||||
assert i18n.format_date(format, date=date) == 'Feb 7, 2016'
|
||||
assert i18n.format_date(format, date=datet, language='en') == '5:11:17 AM'
|
||||
assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
|
||||
format = '%c'
|
||||
assert i18n.format_date(format, date=datet) == 'Feb 7, 2016, 5:11:17 AM'
|
||||
assert i18n.format_date(format, date=date) == 'Feb 7, 2016'
|
||||
assert i18n.format_date(format, date=datet, language='en') == 'Feb 7, 2016, 5:11:17 AM'
|
||||
assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
|
||||
|
||||
# timezone
|
||||
format = '%Z'
|
||||
assert i18n.format_date(format, date=datet) == 'UTC'
|
||||
assert i18n.format_date(format, date=datet, language='en') == 'UTC'
|
||||
format = '%z'
|
||||
assert i18n.format_date(format, date=datet) == '+0000'
|
||||
assert i18n.format_date(format, date=datet, language='en') == '+0000'
|
||||
|
||||
|
||||
@pytest.mark.xfail(os.name != 'posix', reason="Path separators don't match on windows")
|
||||
@ -141,18 +146,18 @@ def test_get_filename_for_language(app):
|
||||
|
||||
def test_CatalogRepository(tempdir):
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#', encoding='utf8')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#', encoding='utf8')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#', encoding='utf8')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#', encoding='utf8')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / '.dotdir').makedirs()
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / '.dotdir' / 'test5.po').write_text('#')
|
||||
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / '.dotdir' / 'test5.po').write_text('#', encoding='utf8')
|
||||
(tempdir / 'loc1' / 'yy' / 'LC_MESSAGES').makedirs()
|
||||
(tempdir / 'loc1' / 'yy' / 'LC_MESSAGES' / 'test6.po').write_text('#')
|
||||
(tempdir / 'loc1' / 'yy' / 'LC_MESSAGES' / 'test6.po').write_text('#', encoding='utf8')
|
||||
(tempdir / 'loc2' / 'xx' / 'LC_MESSAGES').makedirs()
|
||||
(tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
|
||||
(tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test7.po').write_text('#')
|
||||
(tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#', encoding='utf8')
|
||||
(tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test7.po').write_text('#', encoding='utf8')
|
||||
|
||||
# for language xx
|
||||
repo = i18n.CatalogRepository(tempdir, ['loc1', 'loc2'], 'xx', 'utf-8')
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Tests uti.nodes functions."""
|
||||
import warnings
|
||||
from textwrap import dedent
|
||||
from typing import Any
|
||||
|
||||
@ -17,8 +18,12 @@ def _transform(doctree):
|
||||
|
||||
|
||||
def create_new_document():
|
||||
settings = frontend.OptionParser(
|
||||
components=(rst.Parser,)).get_default_values()
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
# DeprecationWarning: The frontend.OptionParser class will be replaced
|
||||
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
|
||||
settings = frontend.OptionParser(
|
||||
components=(rst.Parser,)).get_default_values()
|
||||
settings.id_prefix = 'id'
|
||||
document = new_document('dummy.txt', settings)
|
||||
return document
|
||||
|
@ -27,7 +27,7 @@ def bump_version(path, version_info, in_develop=True):
|
||||
if in_develop:
|
||||
version += '+'
|
||||
|
||||
with open(path, 'r+') as f:
|
||||
with open(path, 'r+', encoding='utf-8') as f:
|
||||
body = f.read()
|
||||
body = re.sub(r"(?<=__version__ = ')[^']+", version, body)
|
||||
body = re.sub(r"(?<=__released__ = ')[^']+", release, body)
|
||||
@ -88,7 +88,7 @@ class Changes:
|
||||
self.fetch_version()
|
||||
|
||||
def fetch_version(self):
|
||||
with open(self.path) as f:
|
||||
with open(self.path, encoding='utf-8') as f:
|
||||
version = f.readline().strip()
|
||||
matched = re.search(r'^Release (.*) \((.*)\)$', version)
|
||||
if matched is None:
|
||||
@ -105,7 +105,7 @@ class Changes:
|
||||
release_date = datetime.now().strftime('%b %d, %Y')
|
||||
heading = 'Release %s (released %s)' % (self.version, release_date)
|
||||
|
||||
with open(self.path, 'r+') as f:
|
||||
with open(self.path, 'r+', encoding='utf-8') as f:
|
||||
f.readline() # skip first two lines
|
||||
f.readline()
|
||||
body = f.read()
|
||||
@ -126,12 +126,12 @@ class Changes:
|
||||
version_info[4] or '')
|
||||
heading = 'Release %s (in development)' % version
|
||||
|
||||
with open(os.path.join(script_dir, 'CHANGES_template')) as f:
|
||||
with open(os.path.join(script_dir, 'CHANGES_template'), encoding='utf-8') as f:
|
||||
f.readline() # skip first two lines
|
||||
f.readline()
|
||||
tmpl = f.read()
|
||||
|
||||
with open(self.path, 'r+') as f:
|
||||
with open(self.path, 'r+', encoding='utf-8') as f:
|
||||
body = f.read()
|
||||
|
||||
f.seek(0)
|
||||
|
@ -12,7 +12,7 @@ LEADING_SPACES = re.compile(r'^(\s*)')
|
||||
|
||||
|
||||
def lint(path: str) -> int:
|
||||
with open(path) as f:
|
||||
with open(path, encoding='utf-8') as f:
|
||||
document = f.readlines()
|
||||
|
||||
errors = 0
|
||||
|
Loading…
Reference in New Issue
Block a user