From ce595ddf745b892a0c9beb1f866f17c6e2875cef Mon Sep 17 00:00:00 2001 From: TLouf Date: Wed, 8 Jan 2025 15:16:50 +0100 Subject: [PATCH] fmt --- sphinx/_cli/__init__.py | 2 +- sphinx/builders/__init__.py | 2 +- sphinx/builders/latex/__init__.py | 5 +- sphinx/builders/manpage.py | 7 +-- sphinx/cmd/build.py | 8 ++- sphinx/cmd/make_mode.py | 2 +- sphinx/cmd/quickstart.py | 2 +- sphinx/environment/adapters/toctree.py | 2 +- sphinx/ext/intersphinx/_load.py | 2 +- sphinx/testing/path.py | 2 +- sphinx/testing/util.py | 12 ++--- sphinx/writers/html5.py | 8 +-- sphinx/writers/latex.py | 4 +- sphinx/writers/manpage.py | 2 +- sphinx/writers/texinfo.py | 17 +++--- tests/test_builders/test_build_html.py | 7 +-- .../test_builders/test_build_html_5_output.py | 3 +- tests/test_builders/test_build_latex.py | 36 +++++-------- tests/test_builders/test_build_text.py | 22 +------- tests/test_config/test_config.py | 9 ++-- tests/test_directives/test_directive_code.py | 7 +-- tests/test_directives/test_directive_only.py | 12 ++--- tests/test_domains/test_domain_c.py | 6 +-- tests/test_domains/test_domain_cpp.py | 11 ++-- tests/test_domains/test_domain_py_pyobject.py | 5 +- tests/test_extensions/test_ext_apidoc.py | 12 ++--- tests/test_extensions/test_ext_autodoc.py | 12 ++--- tests/test_extensions/test_ext_autosummary.py | 27 +++------- tests/test_extensions/test_ext_graphviz.py | 7 +-- .../test_ext_napoleon_docstring.py | 6 +-- tests/test_intl/test_intl.py | 54 +++++++++---------- tests/test_markup/test_markup.py | 5 +- tests/test_pycode/test_pycode_parser.py | 5 +- tests/test_search.py | 6 +-- .../test_transforms_reorder_nodes.py | 9 +--- 35 files changed, 125 insertions(+), 213 deletions(-) diff --git a/sphinx/_cli/__init__.py b/sphinx/_cli/__init__.py index 3160f08373c..270d9210e33 100644 --- a/sphinx/_cli/__init__.py +++ b/sphinx/_cli/__init__.py @@ -170,7 +170,7 @@ def _format_metavar( def error(self, message: str) -> NoReturn: sys.stderr.write( __( - '{0}: error: {1}\n' "Run '{0} --help' for information" # NoQA: COM812 + "{0}: error: {1}\nRun '{0} --help' for information" # NoQA: COM812 ).format(self.prog, message) ) raise SystemExit(2) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 21b73f873a0..bf2f3f86080 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -203,7 +203,7 @@ def post_process_images(self, doctree: Node) -> None: image_uri = images.get_original_image_uri(node['uri']) if mimetypes: logger.warning( - __('a suitable image for %s builder not found: ' '%s (%s)'), + __('a suitable image for %s builder not found: %s (%s)'), self.name, mimetypes, image_uri, diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py index db7adc5b0d7..19ea60e1290 100644 --- a/sphinx/builders/latex/__init__.py +++ b/sphinx/builders/latex/__init__.py @@ -166,10 +166,7 @@ def init_document_data(self) -> None: docname = entry[0] if docname not in self.env.all_docs: logger.warning( - __( - '"latex_documents" config value references unknown ' - 'document %s' - ), + __('"latex_documents" config value references unknown document %s'), docname, ) continue diff --git a/sphinx/builders/manpage.py b/sphinx/builders/manpage.py index 2e24486d174..4535776b9cb 100644 --- a/sphinx/builders/manpage.py +++ b/sphinx/builders/manpage.py @@ -44,10 +44,7 @@ class ManualPageBuilder(Builder): def init(self) -> None: if not self.config.man_pages: logger.warning( - __( - 'no "man_pages" config value found; no manual pages ' - 'will be written' - ) + __('no "man_pages" config value found; no manual pages will be written') ) def get_outdated_docs(self) -> str | list[str]: @@ -73,7 +70,7 @@ def write_documents(self, _docnames: Set[str]) -> None: docname, name, description, authors, section = info if docname not in self.env.all_docs: logger.warning( - __('"man_pages" config value references unknown ' 'document %s'), + __('"man_pages" config value references unknown document %s'), docname, ) continue diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py index 3c3d8e4b4de..a6338efe030 100644 --- a/sphinx/cmd/build.py +++ b/sphinx/cmd/build.py @@ -217,14 +217,14 @@ def get_parser() -> argparse.ArgumentParser: '-a', action='store_true', dest='force_all', - help=__('write all files (default: only write new and ' 'changed files)'), + help=__('write all files (default: only write new and changed files)'), ) group.add_argument( '--fresh-env', '-E', action='store_true', dest='freshenv', - help=__("don't use a saved environment, always read " 'all files'), + help=__("don't use a saved environment, always read all files"), ) group = parser.add_argument_group(__('path options')) @@ -243,9 +243,7 @@ def get_parser() -> argparse.ArgumentParser: '-c', metavar='PATH', dest='confdir', - help=__( - 'directory for the configuration file (conf.py) ' '(default: SOURCE_DIR)' - ), + help=__('directory for the configuration file (conf.py) (default: SOURCE_DIR)'), ) group = parser.add_argument_group('build configuration options') diff --git a/sphinx/cmd/make_mode.py b/sphinx/cmd/make_mode.py index ac22ba99822..9165b05ec97 100644 --- a/sphinx/cmd/make_mode.py +++ b/sphinx/cmd/make_mode.py @@ -49,7 +49,7 @@ ( '', 'doctest', - 'to run all doctests embedded in the documentation ' '(if enabled)', + 'to run all doctests embedded in the documentation (if enabled)', ), ('', 'coverage', 'to run coverage check of the documentation (if enabled)'), ('', 'clean', 'to remove everything in the build directory'), diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 1176dc14b40..18d06c39f1d 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -507,7 +507,7 @@ def write_file(fpath: str, content: str, newline: str | None = None) -> None: end='', ) if d['makefile'] or d['batchfile']: - print(__('Use the Makefile to build the docs, like so:\n' ' make builder')) + print(__('Use the Makefile to build the docs, like so:\n make builder')) else: print( __( diff --git a/sphinx/environment/adapters/toctree.py b/sphinx/environment/adapters/toctree.py index edd873b5f44..3079c7dc543 100644 --- a/sphinx/environment/adapters/toctree.py +++ b/sphinx/environment/adapters/toctree.py @@ -315,7 +315,7 @@ def _toctree_entry( else: if ref in parents: logger.warning( - __('circular toctree references ' 'detected, ignoring: %s <- %s'), + __('circular toctree references detected, ignoring: %s <- %s'), ref, ' <- '.join(parents), location=ref, diff --git a/sphinx/ext/intersphinx/_load.py b/sphinx/ext/intersphinx/_load.py index 27b11673465..dde2e34e1c2 100644 --- a/sphinx/ext/intersphinx/_load.py +++ b/sphinx/ext/intersphinx/_load.py @@ -272,7 +272,7 @@ def _fetch_inventory_group( else: issues = '\n'.join(f[0] % f[1:] for f in failures) LOGGER.warning( - __('failed to reach any of the inventories ' 'with the following issues:') + __('failed to reach any of the inventories with the following issues:') + '\n' + issues ) diff --git a/sphinx/testing/path.py b/sphinx/testing/path.py index 9792dcb7479..b469588ea6d 100644 --- a/sphinx/testing/path.py +++ b/sphinx/testing/path.py @@ -13,7 +13,7 @@ from collections.abc import Callable warnings.warn( - "'sphinx.testing.path' is deprecated. " "Use 'os.path' or 'pathlib' instead.", + "'sphinx.testing.path' is deprecated. Use 'os.path' or 'pathlib' instead.", RemovedInSphinx90Warning, stacklevel=2, ) diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py index 4d221133ffb..d95ffb46bc3 100644 --- a/sphinx/testing/util.py +++ b/sphinx/testing/util.py @@ -40,9 +40,9 @@ def assert_node(node: Node, cls: Any = None, xpath: str = '', **kwargs: Any) -> assert ( isinstance(node, nodes.Element) ), f'The node{xpath} does not have any children' # fmt: skip - assert ( - len(node) == 1 - ), f'The node{xpath} has {len(node)} child nodes, not one' + assert len(node) == 1, ( + f'The node{xpath} has {len(node)} child nodes, not one' + ) assert_node(node[0], cls[1:], xpath=xpath + '[0]', **kwargs) elif isinstance(cls, tuple): assert ( @@ -71,9 +71,9 @@ def assert_node(node: Node, cls: Any = None, xpath: str = '', **kwargs: Any) -> if (key := key.replace('_', '-')) not in node: msg = f'The node{xpath} does not have {key!r} attribute: {node!r}' raise AssertionError(msg) - assert ( - node[key] == value - ), f'The node{xpath}[{key}] is not {value!r}: {node[key]!r}' + assert node[key] == value, ( + f'The node{xpath}[{key}] is not {value!r}: {node[key]!r}' + ) # keep this to restrict the API usage and to have a correct return type diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 1a3c8a41164..d54e2584649 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -336,9 +336,9 @@ def visit_reference(self, node: Element) -> None: atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True else: - assert ( - 'refid' in node - ), 'References must have "refuri" or "refid" attribute.' + assert 'refid' in node, ( + 'References must have "refuri" or "refid" attribute.' + ) atts['href'] = '#' + node['refid'] if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) # NoQA: PT018 @@ -388,7 +388,7 @@ def get_secnumber(self, node: Element) -> tuple[int, ...] | None: if isinstance(node.parent, nodes.section): if self.builder.name == 'singlehtml': docname = self.docnames[-1] - anchorname = f"{docname}/#{node.parent['ids'][0]}" + anchorname = f'{docname}/#{node.parent["ids"][0]}' if anchorname not in self.builder.secnumbers: # try first heading which has no anchor anchorname = f'{docname}/' diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index bcbfe390344..4d158a26d6e 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -2460,7 +2460,7 @@ def visit_math(self, node: Element) -> None: def visit_math_block(self, node: Element) -> None: if node.get('label'): - label = f"equation:{node['docname']}:{node['label']}" + label = f'equation:{node["docname"]}:{node["label"]}' else: label = None @@ -2477,7 +2477,7 @@ def visit_math_block(self, node: Element) -> None: raise nodes.SkipNode def visit_math_reference(self, node: Element) -> None: - label = f"equation:{node['docname']}:{node['target']}" + label = f'equation:{node["docname"]}:{node["target"]}' eqref_format = self.config.math_eqref_format if eqref_format: try: diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index 5bfc23481c0..7b7db13961f 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -117,7 +117,7 @@ def header(self) -> str: ' "%(date)s" "%(version)s" "%(manual_group)s"\n' ) if self._docinfo['subtitle']: - tmpl += '.SH NAME\n' '%(title)s \\- %(subtitle)s\n' + tmpl += '.SH NAME\n%(title)s \\- %(subtitle)s\n' return tmpl % self._docinfo def visit_start_of_file(self, node: Element) -> None: diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 997561b16fd..3b1e4367b11 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -250,9 +250,10 @@ def init_settings(self) -> None: '(%s)' % elements['filename'], self.escape_arg(self.settings.texinfo_dir_description), ) - elements['direntry'] = ( - '@dircategory %s\n' '@direntry\n' '%s' '@end direntry\n' - ) % (self.escape_id(self.settings.texinfo_dir_category), entry) + elements['direntry'] = ('@dircategory %s\n@direntry\n%s@end direntry\n') % ( + self.escape_id(self.settings.texinfo_dir_category), + entry, + ) elements['copying'] = COPYING % elements # allow the user to override them all elements.update(self.settings.texinfo_elements) @@ -448,10 +449,10 @@ def _add_detailed_menu(name: str) -> None: for subentry in entries: _add_detailed_menu(subentry) - self.body.append('\n@detailmenu\n' ' --- The Detailed Node Listing ---\n') + self.body.append('\n@detailmenu\n --- The Detailed Node Listing ---\n') for entry in entries: _add_detailed_menu(entry) - self.body.append('\n@end detailmenu\n' '@end menu\n') + self.body.append('\n@end detailmenu\n@end menu\n') def tex_image_length(self, width_str: str) -> str: match = re.match(r'(\d*\.?\d*)\s*(\S*)', width_str) @@ -1119,7 +1120,7 @@ def _visit_named_admonition(self, node: Element) -> None: def depart_admonition(self, node: Element) -> None: self.ensure_eol() - self.body.append('@end quotation\n' '@end cartouche\n') + self.body.append('@end quotation\n@end cartouche\n') visit_attention = _visit_named_admonition depart_attention = depart_admonition @@ -1236,7 +1237,7 @@ def visit_image(self, node: Element) -> None: width = self.tex_image_length(node.get('width', '')) height = self.tex_image_length(node.get('height', '')) alt = self.escape_arg(node.get('alt', '')) - filename = f"{self.elements['filename'][:-5]}-figures/{name}" # type: ignore[index] + filename = f'{self.elements["filename"][:-5]}-figures/{name}' # type: ignore[index] self.body.append(f'\n@image{{{filename},{width},{height},{alt},{ext[1:]}}}\n') def depart_image(self, node: Element) -> None: @@ -1280,7 +1281,7 @@ def visit_substitution_definition(self, node: Element) -> None: def visit_system_message(self, node: Element) -> None: self.body.append( - '\n@verbatim\n' '\n' '@end verbatim\n' % node.astext() + '\n@verbatim\n\n@end verbatim\n' % node.astext() ) raise nodes.SkipNode diff --git a/tests/test_builders/test_build_html.py b/tests/test_builders/test_build_html.py index 3f16584deb6..e311906b5be 100644 --- a/tests/test_builders/test_build_html.py +++ b/tests/test_builders/test_build_html.py @@ -301,9 +301,7 @@ def test_html_raw_directive(app): [ (".//link[@href='_static/persistent.css'][@rel='stylesheet']", '', True), ( - ".//link[@href='_static/default.css']" - "[@rel='stylesheet']" - "[@title='Default']", + ".//link[@href='_static/default.css'][@rel='stylesheet'][@title='Default']", '', True, ), @@ -339,8 +337,7 @@ def test_html_raw_directive(app): True, ), ( - ".//link[@href='_static/more_alternate2.css']" - "[@rel='alternate stylesheet']", + ".//link[@href='_static/more_alternate2.css'][@rel='alternate stylesheet']", '', True, ), diff --git a/tests/test_builders/test_build_html_5_output.py b/tests/test_builders/test_build_html_5_output.py index a0cc15aeffa..a618fae1e45 100644 --- a/tests/test_builders/test_build_html_5_output.py +++ b/tests/test_builders/test_build_html_5_output.py @@ -162,8 +162,7 @@ def checker(nodes: Iterable[Element]) -> Literal[True]: ), ( 'markup.html', - ".//a[@href='#with']" - "[@class='reference internal']/code/span[@class='pre']", + ".//a[@href='#with'][@class='reference internal']/code/span[@class='pre']", '^with$', ), ( diff --git a/tests/test_builders/test_build_latex.py b/tests/test_builders/test_build_latex.py index aa2c9d93516..562d502eb6b 100644 --- a/tests/test_builders/test_build_latex.py +++ b/tests/test_builders/test_build_latex.py @@ -389,8 +389,7 @@ def test_numref(app): print(app.status.getvalue()) print(app.warning.getvalue()) assert ( - '\\hyperref[\\detokenize{index:fig1}]' - '{Fig.\\@ \\ref{\\detokenize{index:fig1}}}' + '\\hyperref[\\detokenize{index:fig1}]{Fig.\\@ \\ref{\\detokenize{index:fig1}}}' ) in result assert ( '\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}' @@ -400,8 +399,7 @@ def test_numref(app): '{Table \\ref{\\detokenize{index:table-1}}}' ) in result assert ( - '\\hyperref[\\detokenize{baz:table22}]' - '{Table:\\ref{\\detokenize{baz:table22}}}' + '\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' ) in result assert ( '\\hyperref[\\detokenize{index:code-1}]' @@ -462,8 +460,7 @@ def test_numref_with_prefix1(app): assert '\\ref{\\detokenize{index:code-1}}' in result assert '\\ref{\\detokenize{baz:code22}}' in result assert ( - '\\hyperref[\\detokenize{index:fig1}]' - '{Figure:\\ref{\\detokenize{index:fig1}}}' + '\\hyperref[\\detokenize{index:fig1}]{Figure:\\ref{\\detokenize{index:fig1}}}' ) in result assert ( '\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}' @@ -473,8 +470,7 @@ def test_numref_with_prefix1(app): '{Tab\\_\\ref{\\detokenize{index:table-1}}}' ) in result assert ( - '\\hyperref[\\detokenize{baz:table22}]' - '{Table:\\ref{\\detokenize{baz:table22}}}' + '\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' ) in result assert ( '\\hyperref[\\detokenize{index:code-1}]' @@ -540,8 +536,7 @@ def test_numref_with_prefix2(app): '{Tab\\_\\ref{\\detokenize{index:table-1}}:}' ) in result assert ( - '\\hyperref[\\detokenize{baz:table22}]' - '{Table:\\ref{\\detokenize{baz:table22}}}' + '\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' ) in result assert ( '\\hyperref[\\detokenize{index:code-1}]{Code\\sphinxhyphen{}\\ref{\\detokenize{index:code-1}} ' @@ -552,8 +547,7 @@ def test_numref_with_prefix2(app): '{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}' ) in result assert ( - '\\hyperref[\\detokenize{foo:foo}]' - '{SECTION\\_\\ref{\\detokenize{foo:foo}}\\_}' + '\\hyperref[\\detokenize{foo:foo}]{SECTION\\_\\ref{\\detokenize{foo:foo}}\\_}' ) in result assert ( '\\hyperref[\\detokenize{bar:bar-a}]' @@ -590,8 +584,7 @@ def test_numref_with_language_ja(app): print(app.status.getvalue()) print(app.warning.getvalue()) assert ( - '\\hyperref[\\detokenize{index:fig1}]' - '{\u56f3 \\ref{\\detokenize{index:fig1}}}' + '\\hyperref[\\detokenize{index:fig1}]{\u56f3 \\ref{\\detokenize{index:fig1}}}' ) in result assert ( '\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}' @@ -601,8 +594,7 @@ def test_numref_with_language_ja(app): '{\u8868 \\ref{\\detokenize{index:table-1}}}' ) in result assert ( - '\\hyperref[\\detokenize{baz:table22}]' - '{Table:\\ref{\\detokenize{baz:table22}}}' + '\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' ) in result assert ( '\\hyperref[\\detokenize{index:code-1}]' @@ -937,8 +929,7 @@ def test_footnote(app): 'numbered\n%\n\\end{footnote}' ) in result assert ( - '\\begin{footnote}[2]\\sphinxAtStartFootnote\nauto numbered\n%\n' - '\\end{footnote}' + '\\begin{footnote}[2]\\sphinxAtStartFootnote\nauto numbered\n%\n\\end{footnote}' ) in result assert ( '\\begin{footnote}[3]\\sphinxAtStartFootnote\nnamed\n%\n\\end{footnote}' @@ -1880,8 +1871,7 @@ def test_latex_nested_enumerated_list(app): result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') assert ( - '\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n' - '\\setcounter{enumi}{4}\n' + '\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n\\setcounter{enumi}{4}\n' ) in result assert ( '\\sphinxsetlistlabels{\\alph}{enumii}{enumiii}{}{.}%\n' @@ -2201,9 +2191,9 @@ def test_duplicated_labels_before_module(app): ): tex_label_name = 'index:' + rst_label_name.replace('_', '-') tex_label_code = r'\phantomsection\label{\detokenize{%s}}' % tex_label_name - assert ( - content.count(tex_label_code) == 1 - ), f'duplicated label: {tex_label_name!r}' + assert content.count(tex_label_code) == 1, ( + f'duplicated label: {tex_label_name!r}' + ) tested_labels.add(tex_label_code) # ensure that we did not forget any label to check diff --git a/tests/test_builders/test_build_text.py b/tests/test_builders/test_build_text.py index 8007ea23157..2023f6f9a53 100644 --- a/tests/test_builders/test_build_text.py +++ b/tests/test_builders/test_build_text.py @@ -44,14 +44,7 @@ def test_lineblock(app): # regression test for #1109: need empty line after line block app.build() result = (app.outdir / 'lineblock.txt').read_text(encoding='utf8') - expect = ( - '* one\n' - '\n' - ' line-block 1\n' - ' line-block 2\n' - '\n' - 'followed paragraph.\n' - ) + expect = '* one\n\n line-block 1\n line-block 2\n\nfollowed paragraph.\n' assert result == expect @@ -265,16 +258,5 @@ def test_secnums(app): assert lines[5] == '' assert lines[6] == ' * Sub Bb' doc2 = (app.outdir / 'doc2.txt').read_text(encoding='utf8') - expect = ( - 'Section B\n' - '*********\n' - '\n' - '\n' - 'Sub Ba\n' - '======\n' - '\n' - '\n' - 'Sub Bb\n' - '======\n' - ) + expect = 'Section B\n*********\n\n\nSub Ba\n======\n\n\nSub Bb\n======\n' assert doc2 == expect diff --git a/tests/test_config/test_config.py b/tests/test_config/test_config.py index f1d6c12a0fd..1f924a152cc 100644 --- a/tests/test_config/test_config.py +++ b/tests/test_config/test_config.py @@ -463,16 +463,15 @@ def test_config_eol(logger, tmp_path): ) def test_builtin_conf(app): warnings = app.warning.getvalue() - assert ( - 'root_doc' - ) in warnings, 'override on builtin "root_doc" should raise a type warning' + assert ('root_doc') in warnings, ( + 'override on builtin "root_doc" should raise a type warning' + ) assert 'language' not in warnings, ( 'explicitly permitted override on builtin "language" should NOT raise ' 'a type warning' ) assert 'primary_domain' not in warnings, ( - 'override to None on builtin "primary_domain" should NOT raise a type ' - 'warning' + 'override to None on builtin "primary_domain" should NOT raise a type warning' ) diff --git a/tests/test_directives/test_directive_code.py b/tests/test_directives/test_directive_code.py index dacf8a3b334..0b81b65c1d8 100644 --- a/tests/test_directives/test_directive_code.py +++ b/tests/test_directives/test_directive_code.py @@ -536,12 +536,7 @@ def test_literalinclude_pydecorators(app): assert actual == expect actual = literal_include[2].text - expect = ( - '@function_decorator\n' - '@other_decorator()\n' - 'def the_function():\n' - ' pass\n' - ) + expect = '@function_decorator\n@other_decorator()\ndef the_function():\n pass\n' assert actual == expect diff --git a/tests/test_directives/test_directive_only.py b/tests/test_directives/test_directive_only.py index de9230c04da..297f304dfdb 100644 --- a/tests/test_directives/test_directive_only.py +++ b/tests/test_directives/test_directive_only.py @@ -28,9 +28,9 @@ def testsects(prefix, sects, indent=0): assert prefix == parent_num, f'Section out of place: {title!r}' for i, subsect in enumerate(sects[1]): num = subsect[0].split()[0] - assert re.match( - '[0-9]+[.0-9]*[.]', num - ), f'Unnumbered section: {subsect[0]!r}' + assert re.match('[0-9]+[.0-9]*[.]', num), ( + f'Unnumbered section: {subsect[0]!r}' + ) testsects(prefix + str(i + 1) + '.', subsect, indent + 4) app.build(filenames=[app.srcdir / 'only.rst']) @@ -41,6 +41,6 @@ def testsects(prefix, sects, indent=0): for i, s in enumerate(parts): testsects(str(i + 1) + '.', s, 4) actual_headings = '\n'.join(p[0] for p in parts) - assert ( - len(parts) == 4 - ), f'Expected 4 document level headings, got:\n{actual_headings}' + assert len(parts) == 4, ( + f'Expected 4 document level headings, got:\n{actual_headings}' + ) diff --git a/tests/test_domains/test_domain_c.py b/tests/test_domains/test_domain_c.py index 809b68c2f1d..035b68bca8a 100644 --- a/tests/test_domains/test_domain_c.py +++ b/tests/test_domains/test_domain_c.py @@ -923,11 +923,7 @@ def test_domain_c_parse_cvar(app): @pytest.mark.sphinx('html', testroot='root') def test_domain_c_parse_no_index_entry(app): - text = ( - '.. c:function:: void f()\n' - '.. c:function:: void g()\n' - ' :no-index-entry:\n' - ) + text = '.. c:function:: void f()\n.. c:function:: void g()\n :no-index-entry:\n' doctree = restructuredtext.parse(app, text) assert_node(doctree, (addnodes.index, desc, addnodes.index, desc)) assert_node( diff --git a/tests/test_domains/test_domain_cpp.py b/tests/test_domains/test_domain_cpp.py index 068fddf390e..417391e8f69 100644 --- a/tests/test_domains/test_domain_cpp.py +++ b/tests/test_domains/test_domain_cpp.py @@ -159,7 +159,7 @@ def make_id_v2(): id1 = make_id_v1() id2 = make_id_v2() - input = f"void f({type_.replace(' ', ' ')} arg)" + input = f'void f({type_.replace(" ", " ")} arg)' output = f'void f({type_} arg)' check('function', input, {1: id1, 2: id2}, output=output) @@ -167,7 +167,7 @@ def make_id_v2(): # try permutations of all components tcs = type_.split() for p in itertools.permutations(tcs): - input = f"void f({' '.join(p)} arg)" + input = f'void f({" ".join(p)} arg)' check('function', input, {1: id1, 2: id2}) @@ -1347,8 +1347,7 @@ def test_domain_cpp_ast_template_args(): # from breathe#218 check( 'function', - 'template ' - 'void allow(F *f, typename func::type tt)', + 'template void allow(F *f, typename func::type tt)', { 2: 'I0E5allowP1FN4funcI1F1BXG != 1EE4typeE', 3: 'I0E5allowP1FN4funcI1F1BXne1GL1EEE4typeE', @@ -1906,9 +1905,7 @@ def test_domain_cpp_build_intersphinx(tmp_path, app): @pytest.mark.sphinx('html', testroot='root') def test_domain_cpp_parse_no_index_entry(app): text = ( - '.. cpp:function:: void f()\n' - '.. cpp:function:: void g()\n' - ' :no-index-entry:\n' + '.. cpp:function:: void f()\n.. cpp:function:: void g()\n :no-index-entry:\n' ) doctree = restructuredtext.parse(app, text) assert_node(doctree, (addnodes.index, desc, addnodes.index, desc)) diff --git a/tests/test_domains/test_domain_py_pyobject.py b/tests/test_domains/test_domain_py_pyobject.py index 8691e0e08cc..67d91d731e4 100644 --- a/tests/test_domains/test_domain_py_pyobject.py +++ b/tests/test_domains/test_domain_py_pyobject.py @@ -165,10 +165,7 @@ def test_pydata_with_union_type_operator(app): @pytest.mark.sphinx('html', testroot='root') def test_pyobject_prefix(app): text = ( - '.. py:class:: Foo\n' - '\n' - ' .. py:method:: Foo.say\n' - ' .. py:method:: FooBar.say' + '.. py:class:: Foo\n\n .. py:method:: Foo.say\n .. py:method:: FooBar.say' ) doctree = restructuredtext.parse(app, text) assert_node( diff --git a/tests/test_extensions/test_ext_apidoc.py b/tests/test_extensions/test_ext_apidoc.py index 3886617c742..7e4edbdfce8 100644 --- a/tests/test_extensions/test_ext_apidoc.py +++ b/tests/test_extensions/test_ext_apidoc.py @@ -372,9 +372,9 @@ def test_toc_all_references_should_exist_pep420_enabled(apidoc): missing_files.append(filename) all_missing = ', '.join(missing_files) - assert ( - len(missing_files) == 0 - ), f'File(s) referenced in TOC not found: {all_missing}\nTOC:\n{toc}' + assert len(missing_files) == 0, ( + f'File(s) referenced in TOC not found: {all_missing}\nTOC:\n{toc}' + ) @pytest.mark.apidoc( @@ -403,9 +403,9 @@ def test_toc_all_references_should_exist_pep420_disabled(apidoc): missing_files.append(filename) all_missing = ', '.join(missing_files) - assert ( - len(missing_files) == 0 - ), f'File(s) referenced in TOC not found: {all_missing}\nTOC:\n{toc}' + assert len(missing_files) == 0, ( + f'File(s) referenced in TOC not found: {all_missing}\nTOC:\n{toc}' + ) def extract_toc(path): diff --git a/tests/test_extensions/test_ext_autodoc.py b/tests/test_extensions/test_ext_autodoc.py index f2fb0c8ec11..dbe0fbe1d71 100644 --- a/tests/test_extensions/test_ext_autodoc.py +++ b/tests/test_extensions/test_ext_autodoc.py @@ -1558,9 +1558,9 @@ def entry( def preamble_lookup( self, doc: str, *, indent: int = 0, **options: Any ) -> list[str]: - assert ( - doc - ), f'enumeration class {self.target!r} should have an explicit docstring' + assert doc, ( + f'enumeration class {self.target!r} should have an explicit docstring' + ) args = self._preamble_args(functional_constructor=False) return self._preamble(doc=doc, args=args, indent=indent, **options) @@ -1568,9 +1568,9 @@ def preamble_lookup( def preamble_constructor( self, doc: str, *, indent: int = 0, **options: Any ) -> list[str]: - assert ( - doc - ), f'enumeration class {self.target!r} should have an explicit docstring' + assert doc, ( + f'enumeration class {self.target!r} should have an explicit docstring' + ) args = self._preamble_args(functional_constructor=True) return self._preamble(doc=doc, args=args, indent=indent, **options) diff --git a/tests/test_extensions/test_ext_autosummary.py b/tests/test_extensions/test_ext_autosummary.py index 81b13860278..5a96afdd3e3 100644 --- a/tests/test_extensions/test_ext_autosummary.py +++ b/tests/test_extensions/test_ext_autosummary.py @@ -192,9 +192,9 @@ def handler(app, what, name, obj, options, lines): 'C.C2': 'This is a nested inner class docstring', } for key, expected in expected_values.items(): - assert ( - autosummary_items[key][2] == expected - ), f'Summary for {key} was {autosummary_items[key]!r} - expected {expected!r}' + assert autosummary_items[key][2] == expected, ( + f'Summary for {key} was {autosummary_items[key]!r} - expected {expected!r}' + ) # check an item in detail assert 'func' in autosummary_items @@ -566,11 +566,7 @@ def test_autosummary_generate(app): Foo = path.read_text(encoding='utf8') assert '.. automethod:: __init__' in Foo assert ( - ' .. autosummary::\n' - ' \n' - ' ~Foo.__init__\n' - ' ~Foo.bar\n' - ' \n' + ' .. autosummary::\n \n ~Foo.__init__\n ~Foo.bar\n \n' ) in Foo assert ( ' .. autosummary::\n' @@ -591,9 +587,7 @@ def test_autosummary_generate(app): path = app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.value.rst' Foo_value = path.read_text(encoding='utf8') assert ( - '.. currentmodule:: autosummary_dummy_module\n' - '\n' - '.. autoattribute:: Foo.value' + '.. currentmodule:: autosummary_dummy_module\n\n.. autoattribute:: Foo.value' ) in Foo_value path = app.srcdir / 'generated' / 'autosummary_dummy_module.qux.rst' @@ -820,17 +814,10 @@ def test_autosummary_module_all(app): ).read_text(encoding='utf8') assert ' .. autosummary::\n \n PublicBar\n \n' in module assert ( - ' .. autosummary::\n' - ' \n' - ' public_foo\n' - ' public_baz\n' - ' \n' + ' .. autosummary::\n \n public_foo\n public_baz\n \n' ) in module assert ( - '.. autosummary::\n' - ' :toctree:\n' - ' :recursive:\n\n' - ' extra_dummy_module\n' + '.. autosummary::\n :toctree:\n :recursive:\n\n extra_dummy_module\n' ) in module finally: sys.modules.pop('autosummary_dummy_package_all', None) diff --git a/tests/test_extensions/test_ext_graphviz.py b/tests/test_extensions/test_ext_graphviz.py index 929dcfa63a0..4be01caf023 100644 --- a/tests/test_extensions/test_ext_graphviz.py +++ b/tests/test_extensions/test_ext_graphviz.py @@ -168,12 +168,7 @@ def test_graphviz_parse_mapfile(): assert cmap.generate_clickable_map() == '' # normal graph - code = ( - 'digraph {\n' - ' foo [href="https://www.google.com/"];\n' - ' foo -> bar;\n' - '}\n' - ) + code = 'digraph {\n foo [href="https://www.google.com/"];\n foo -> bar;\n}\n' content = ( '\n' ':1: ' 'WARNING: Inline literal start-string without end-string. \\[docutils\\]\n' ) - assert re.search( - warning_expr, warnings - ), f'{warning_expr!r} did not match {warnings!r}' + assert re.search(warning_expr, warnings), ( + f'{warning_expr!r} did not match {warnings!r}' + ) @sphinx_intl @@ -196,21 +196,21 @@ def test_text_inconsistency_warnings(app): 'translated': "\\['`I18N WITH REFS INCONSISTENCY`_'\\]", } ) - assert re.search( - expected_warning_expr, warnings - ), f'{expected_warning_expr!r} did not match {warnings!r}' + assert re.search(expected_warning_expr, warnings), ( + f'{expected_warning_expr!r} did not match {warnings!r}' + ) expected_citation_ref_warning_expr = '.*/refs_inconsistency.txt:\\d+: WARNING: Citation \\[ref2\\] is not referenced.' - assert re.search( - expected_citation_ref_warning_expr, warnings - ), f'{expected_citation_ref_warning_expr!r} did not match {warnings!r}' + assert re.search(expected_citation_ref_warning_expr, warnings), ( + f'{expected_citation_ref_warning_expr!r} did not match {warnings!r}' + ) expected_citation_warning_expr = ( '.*/refs_inconsistency.txt:\\d+: WARNING: citation not found: ref3' ) - assert re.search( - expected_citation_warning_expr, warnings - ), f'{expected_citation_warning_expr!r} did not match {warnings!r}' + assert re.search(expected_citation_warning_expr, warnings), ( + f'{expected_citation_warning_expr!r} did not match {warnings!r}' + ) @sphinx_intl @@ -261,9 +261,9 @@ def test_text_literalblock_warnings(app): expected_warning_expr = ( '.*/literalblock.txt:\\d+: WARNING: Literal block expected; none found.' ) - assert re.search( - expected_warning_expr, warnings - ), f'{expected_warning_expr!r} did not match {warnings!r}' + assert re.search(expected_warning_expr, warnings), ( + f'{expected_warning_expr!r} did not match {warnings!r}' + ) @sphinx_intl @@ -347,16 +347,16 @@ def test_text_glossary_term_inconsistencies(app): " original: \\[':term:`Some term`', ':term:`Some other term`'\\]," " translated: \\[':term:`SOME NEW TERM`'\\] \\[i18n.inconsistent_references\\]\n" ) - assert re.search( - expected_warning_expr, warnings - ), f'{expected_warning_expr!r} did not match {warnings!r}' + assert re.search(expected_warning_expr, warnings), ( + f'{expected_warning_expr!r} did not match {warnings!r}' + ) expected_warning_expr = ( '.*/glossary_terms_inconsistency.txt:\\d+::1: ' "WARNING: term not in glossary: 'TERM NOT IN GLOSSARY'" ) - assert re.search( - expected_warning_expr, warnings - ), f'{expected_warning_expr!r} did not match {warnings!r}' + assert re.search(expected_warning_expr, warnings), ( + f'{expected_warning_expr!r} did not match {warnings!r}' + ) @sphinx_intl @@ -1051,9 +1051,9 @@ def wrap_nest(parenttag, childtag, keyword): wrap_nest('li', 'ul', 'SEE'), ] for expr in expected_exprs: - assert re.search( - expr, result, re.MULTILINE - ), f'{expr!r} did not match {result!r}' + assert re.search(expr, result, re.MULTILINE), ( + f'{expr!r} did not match {result!r}' + ) @sphinx_intl @@ -1185,9 +1185,9 @@ def test_xml_footnotes(app): warnings = getwarning(app.warning) warning_expr = '.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n' - assert not re.search( - warning_expr, warnings - ), f'{warning_expr!r} did match {warnings!r}' + assert not re.search(warning_expr, warnings), ( + f'{warning_expr!r} did match {warnings!r}' + ) @sphinx_intl diff --git a/tests/test_markup/test_markup.py b/tests/test_markup/test_markup.py index 1a8a074151c..b1e340a1611 100644 --- a/tests/test_markup/test_markup.py +++ b/tests/test_markup/test_markup.py @@ -403,10 +403,7 @@ def get(name): 'verify', ':kbd:`-`', '

-

', - ( - '\\sphinxAtStartPar\n' - '\\sphinxkeyboard{\\sphinxupquote{\\sphinxhyphen{}}}' - ), + ('\\sphinxAtStartPar\n\\sphinxkeyboard{\\sphinxupquote{\\sphinxhyphen{}}}'), ), ( # kbd role diff --git a/tests/test_pycode/test_pycode_parser.py b/tests/test_pycode/test_pycode_parser.py index c12ac4d9935..7883a8de3cf 100644 --- a/tests/test_pycode/test_pycode_parser.py +++ b/tests/test_pycode/test_pycode_parser.py @@ -31,10 +31,7 @@ def test_comment_picker_basic(): def test_comment_picker_location(): # multiple "before" comments source = ( - '#: comment before assignment1\n' - '#:\n' - '#: comment before assignment2\n' - 'a = 1 + 1\n' + '#: comment before assignment1\n#:\n#: comment before assignment2\na = 1 + 1\n' ) parser = Parser(source) parser.parse() diff --git a/tests/test_search.py b/tests/test_search.py index f74755b3b5b..600f66cb9f6 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -454,9 +454,9 @@ def assert_is_sorted( elif isinstance(item, list): if not is_title_tuple_type(item) and path not in lists_not_to_sort: # sort nulls last; http://stackoverflow.com/questions/19868767/ - assert item == sorted( - item, key=lambda x: (x is None, x) - ), f'{err_path} is not sorted' + assert item == sorted(item, key=lambda x: (x is None, x)), ( + f'{err_path} is not sorted' + ) for i, child in enumerate(item): assert_is_sorted(child, f'{path}[{i}]') diff --git a/tests/test_transforms/test_transforms_reorder_nodes.py b/tests/test_transforms/test_transforms_reorder_nodes.py index 5540755523a..22fdcf742cf 100644 --- a/tests/test_transforms/test_transforms_reorder_nodes.py +++ b/tests/test_transforms/test_transforms_reorder_nodes.py @@ -10,14 +10,7 @@ @pytest.mark.sphinx('html', testroot='root') def test_transforms_reorder_consecutive_target_and_index_nodes_preserve_order(app): - text = ( - '.. index:: abc\n' - '.. index:: def\n' - '.. index:: ghi\n' - '.. index:: jkl\n' - '\n' - 'text\n' - ) + text = '.. index:: abc\n.. index:: def\n.. index:: ghi\n.. index:: jkl\n\ntext\n' doctree = restructuredtext.parse(app, text) assert_node( doctree,