summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py2
-rw-r--r--tests/roots/test-ext-autodoc/target/overload.py12
-rw-r--r--tests/roots/test-ext-autodoc/target/typehints.py4
-rw-r--r--tests/roots/test-ext-autosummary-filename-map/autosummary_dummy_module.py2
-rw-r--r--tests/roots/test-ext-viewcode/conf.py2
-rw-r--r--tests/roots/test-ext-viewcode/spam/mod1.py4
-rw-r--r--tests/roots/test-ext-viewcode/spam/mod2.py2
-rw-r--r--tests/test_build_html.py2
-rw-r--r--tests/test_build_latex.py4
-rw-r--r--tests/test_domain_cpp.py14
-rw-r--r--tests/test_ext_autodoc_configs.py24
-rw-r--r--tests/test_ext_autosummary.py2
-rw-r--r--tests/test_ext_napoleon_docstring.py50
-rw-r--r--tests/test_ext_viewcode.py6
-rw-r--r--tests/test_intl.py4
15 files changed, 64 insertions, 70 deletions
diff --git a/tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py b/tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py
index 9d42b3872..df30ab62c 100644
--- a/tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py
+++ b/tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py
@@ -7,4 +7,4 @@ if TYPE_CHECKING:
class Foo:
- attr1: "StringIO"
+ attr1: StringIO
diff --git a/tests/roots/test-ext-autodoc/target/overload.py b/tests/roots/test-ext-autodoc/target/overload.py
index 902f00915..4bcb6ea3c 100644
--- a/tests/roots/test-ext-autodoc/target/overload.py
+++ b/tests/roots/test-ext-autodoc/target/overload.py
@@ -9,7 +9,7 @@ def sum(x: int, y: int = 0) -> int:
@overload
-def sum(x: "float", y: "float" = 0.0) -> "float":
+def sum(x: float, y: float = 0.0) -> float:
...
@@ -31,7 +31,7 @@ class Math:
...
@overload
- def sum(self, x: "float", y: "float" = 0.0) -> "float":
+ def sum(self, x: float, y: float = 0.0) -> float:
...
@overload
@@ -47,11 +47,11 @@ class Foo:
"""docstring"""
@overload
- def __new__(cls, x: int, y: int) -> "Foo":
+ def __new__(cls, x: int, y: int) -> Foo:
...
@overload
- def __new__(cls, x: "str", y: "str") -> "Foo":
+ def __new__(cls, x: str, y: str) -> Foo:
...
def __new__(cls, x, y):
@@ -66,7 +66,7 @@ class Bar:
...
@overload
- def __init__(cls, x: "str", y: "str") -> "None":
+ def __init__(cls, x: str, y: str) -> None:
...
def __init__(cls, x, y):
@@ -79,7 +79,7 @@ class Meta(type):
...
@overload
- def __call__(cls, x: "str", y: "str") -> "Any":
+ def __call__(cls, x: str, y: str) -> Any:
...
def __call__(cls, x, y):
diff --git a/tests/roots/test-ext-autodoc/target/typehints.py b/tests/roots/test-ext-autodoc/target/typehints.py
index de2f6d2a8..90715945f 100644
--- a/tests/roots/test-ext-autodoc/target/typehints.py
+++ b/tests/roots/test-ext-autodoc/target/typehints.py
@@ -56,12 +56,12 @@ class Math:
return pathlib.PurePosixPath("/a/b/c")
-def tuple_args(x: Tuple[int, Union[int, str]]) -> Tuple[int, int]:
+def tuple_args(x: tuple[int, int | str]) -> tuple[int, int]:
pass
class NewAnnotation:
- def __new__(cls, i: int) -> 'NewAnnotation':
+ def __new__(cls, i: int) -> NewAnnotation:
pass
diff --git a/tests/roots/test-ext-autosummary-filename-map/autosummary_dummy_module.py b/tests/roots/test-ext-autosummary-filename-map/autosummary_dummy_module.py
index 9fb1256e6..b88e33520 100644
--- a/tests/roots/test-ext-autosummary-filename-map/autosummary_dummy_module.py
+++ b/tests/roots/test-ext-autosummary-filename-map/autosummary_dummy_module.py
@@ -19,5 +19,5 @@ class Foo:
pass
-def bar(x: Union[int, str], y: int = 1) -> None:
+def bar(x: int | str, y: int = 1) -> None:
pass
diff --git a/tests/roots/test-ext-viewcode/conf.py b/tests/roots/test-ext-viewcode/conf.py
index bee063988..5e07214fd 100644
--- a/tests/roots/test-ext-viewcode/conf.py
+++ b/tests/roots/test-ext-viewcode/conf.py
@@ -19,6 +19,6 @@ if 'test_linkcode' in tags:
elif domain == "js":
return "http://foobar/js/" + info['fullname']
elif domain in ("c", "cpp"):
- return "http://foobar/%s/%s" % (domain, "".join(info['names']))
+ return f"http://foobar/{domain}/{''.join(info['names'])}"
else:
raise AssertionError()
diff --git a/tests/roots/test-ext-viewcode/spam/mod1.py b/tests/roots/test-ext-viewcode/spam/mod1.py
index 22cc1a0de..a078328c2 100644
--- a/tests/roots/test-ext-viewcode/spam/mod1.py
+++ b/tests/roots/test-ext-viewcode/spam/mod1.py
@@ -16,13 +16,13 @@ def func1(a, b):
@decorator
-class Class1(object):
+class Class1:
"""
this is Class1
"""
-class Class3(object):
+class Class3:
"""
this is Class3
"""
diff --git a/tests/roots/test-ext-viewcode/spam/mod2.py b/tests/roots/test-ext-viewcode/spam/mod2.py
index 92d196177..72cb08978 100644
--- a/tests/roots/test-ext-viewcode/spam/mod2.py
+++ b/tests/roots/test-ext-viewcode/spam/mod2.py
@@ -16,7 +16,7 @@ def func2(a, b):
@decorator
-class Class2(object):
+class Class2:
"""
this is Class2
"""
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index d985aad76..5b27a4796 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -70,7 +70,7 @@ def tail_check(check):
for node in nodes:
if node.tail and rex.search(node.tail):
return True
- raise AssertionError('%r not found in tail of any nodes %s' % (check, nodes))
+ raise AssertionError(f'{check!r} not found in tail of any nodes {nodes}')
return checker
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py
index 96ba87243..a59e8525c 100644
--- a/tests/test_build_latex.py
+++ b/tests/test_build_latex.py
@@ -61,8 +61,8 @@ def compile_latex_document(app, filename='python.tex'):
except CalledProcessError as exc:
print(exc.stdout.decode('utf8'))
print(exc.stderr.decode('utf8'))
- raise AssertionError('%s exited with return code %s' % (app.config.latex_engine,
- exc.returncode))
+ raise AssertionError(f'{app.config.latex_engine} exited with '
+ f'return code {exc.returncode}')
def skip_if_requested(testfunc):
diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py
index 8593c41f6..34d808a82 100644
--- a/tests/test_domain_cpp.py
+++ b/tests/test_domain_cpp.py
@@ -1199,7 +1199,7 @@ def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, war
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
res = re.search(pattern, text)
if not res:
- print("Pattern\n\t%s\nnot found in %s" % (pattern, file))
+ print(f"Pattern\n\t{pattern}\nnot found in {file}")
raise AssertionError()
rolePatterns = [
('', 'Sphinx'),
@@ -1240,7 +1240,7 @@ def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, wa
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
res = re.search(pattern, text)
if not res:
- print("Pattern\n\t%s\nnot found in %s" % (pattern, file))
+ print(f"Pattern\n\t{pattern}\nnot found in {file}")
raise AssertionError()
rolePatterns = [
('', 'Sphinx'),
@@ -1281,16 +1281,16 @@ def test_domain_cpp_build_xref_consistency(app, status, warning):
output = (app.outdir / test).read_text(encoding='utf8')
def classes(role, tag):
- pattern = (r'{role}-role:.*?'
- r'<(?P<tag>{tag}) .*?class=["\'](?P<classes>.*?)["\'].*?>'
+ pattern = (fr'{role}-role:.*?'
+ fr'<(?P<tag>{tag}) .*?class=["\'](?P<classes>.*?)["\'].*?>'
r'.*'
- r'</(?P=tag)>').format(role=role, tag=tag)
+ r'</(?P=tag)>')
result = re.search(pattern, output)
- expect = '''\
+ expect = f'''\
Pattern for role `{role}` with tag `{tag}`
\t{pattern}
not found in `{test}`
-'''.format(role=role, tag=tag, pattern=pattern, test=test)
+'''
assert result, expect
return set(result.group('classes').split())
diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py
index 4f0d06bb4..7ce8ed3d6 100644
--- a/tests/test_ext_autodoc_configs.py
+++ b/tests/test_ext_autodoc_configs.py
@@ -779,8 +779,7 @@ def test_autodoc_typehints_signature(app):
' :module: target.typehints',
'',
'',
- '.. py:function:: tuple_args(x: ~typing.Tuple[int, ~typing.Union[int, str]]) '
- '-> ~typing.Tuple[int, int]',
+ '.. py:function:: tuple_args(x: tuple[int, int | str]) -> tuple[int, int]',
' :module: target.typehints',
'',
]
@@ -965,10 +964,10 @@ def test_autodoc_typehints_description(app):
assert ('target.typehints.tuple_args(x)\n'
'\n'
' Parameters:\n'
- ' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) --\n'
+ ' **x** (*tuple**[**int**, **int** | **str**]*) --\n'
'\n'
' Return type:\n'
- ' *Tuple*[int, int]\n'
+ ' tuple[int, int]\n'
in context)
# Overloads still get displayed in the signature
@@ -1015,13 +1014,13 @@ def test_autodoc_typehints_description_no_undoc(app):
'target.typehints.tuple_args(x)\n'
'\n'
' Parameters:\n'
- ' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) -- arg\n'
+ ' **x** (*tuple**[**int**, **int** | **str**]*) -- arg\n'
'\n'
' Returns:\n'
' another tuple\n'
'\n'
' Return type:\n'
- ' *Tuple*[int, int]\n'
+ ' tuple[int, int]\n'
in context)
@@ -1072,13 +1071,13 @@ def test_autodoc_typehints_description_no_undoc_doc_rtype(app):
'target.typehints.tuple_args(x)\n'
'\n'
' Parameters:\n'
- ' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) -- arg\n'
+ ' **x** (*tuple**[**int**, **int** | **str**]*) -- arg\n'
'\n'
' Returns:\n'
' another tuple\n'
'\n'
' Return type:\n'
- ' *Tuple*[int, int]\n'
+ ' tuple[int, int]\n'
'\n'
'target.typehints.Math.nothing(self)\n'
'\n'
@@ -1221,13 +1220,13 @@ def test_autodoc_typehints_both(app):
' Return type:\n'
' int\n'
in context)
- assert ('target.typehints.tuple_args(x: Tuple[int, Union[int, str]]) -> Tuple[int, int]\n'
+ assert ('target.typehints.tuple_args(x: tuple[int, int | str]) -> tuple[int, int]\n'
'\n'
' Parameters:\n'
- ' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) --\n'
+ ' **x** (*tuple**[**int**, **int** | **str**]*) --\n'
'\n'
' Return type:\n'
- ' *Tuple*[int, int]\n'
+ ' tuple[int, int]\n'
in context)
# Overloads still get displayed in the signature
@@ -1527,8 +1526,7 @@ def test_autodoc_typehints_format_fully_qualified(app):
' :module: target.typehints',
'',
'',
- '.. py:function:: tuple_args(x: typing.Tuple[int, typing.Union[int, str]]) '
- '-> typing.Tuple[int, int]',
+ '.. py:function:: tuple_args(x: tuple[int, int | str]) -> tuple[int, int]',
' :module: target.typehints',
'',
]
diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py
index 1b2c4d7a8..286a55b42 100644
--- a/tests/test_ext_autosummary.py
+++ b/tests/test_ext_autosummary.py
@@ -62,7 +62,7 @@ def test_mangle_signature():
if '::' in x]
for inp, outp in TEST:
res = mangle_signature(inp).strip().replace("\u00a0", " ")
- assert res == outp, ("'%s' -> '%s' != '%s'" % (inp, res, outp))
+ assert res == outp, (f"'{inp}' -> '{res}' != '{outp}'")
def test_extract_summary(capsys):
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py
index 2919fa171..ee79cb92c 100644
--- a/tests/test_ext_napoleon_docstring.py
+++ b/tests/test_ext_napoleon_docstring.py
@@ -410,25 +410,24 @@ class GoogleDocstringTest(BaseDocstringTest):
config = Config()
for section, admonition in admonition_map.items():
# Multiline
- actual = str(GoogleDocstring(("{}:\n"
- " this is the first line\n"
- "\n"
- " and this is the second line\n"
- ).format(section), config))
- expect = (".. {}::\n"
+ actual = str(GoogleDocstring(f"{section}:\n"
+ " this is the first line\n"
+ "\n"
+ " and this is the second line\n",
+ config))
+ expect = (f".. {admonition}::\n"
"\n"
" this is the first line\n"
" \n"
" and this is the second line\n"
- ).format(admonition)
+ )
self.assertEqual(expect, actual)
# Single line
- actual = str(GoogleDocstring(("{}:\n"
- " this is a single line\n"
- ).format(section), config))
- expect = (".. {}:: this is a single line\n"
- ).format(admonition)
+ actual = str(GoogleDocstring(f"{section}:\n"
+ " this is a single line\n",
+ config))
+ expect = f".. {admonition}:: this is a single line\n"
self.assertEqual(expect, actual)
def test_docstrings(self):
@@ -1472,27 +1471,26 @@ class NumpyDocstringTest(BaseDocstringTest):
config = Config()
for section, admonition in admonition_map.items():
# Multiline
- actual = str(NumpyDocstring(("{}\n"
- "{}\n"
- " this is the first line\n"
- "\n"
- " and this is the second line\n"
- ).format(section, '-' * len(section)), config))
- expect = (".. {}::\n"
+ actual = str(NumpyDocstring(f"{section}\n"
+ f"{'-' * len(section)}\n"
+ " this is the first line\n"
+ "\n"
+ " and this is the second line\n",
+ config))
+ expect = (f".. {admonition}::\n"
"\n"
" this is the first line\n"
" \n"
" and this is the second line\n"
- ).format(admonition)
+ )
self.assertEqual(expect, actual)
# Single line
- actual = str(NumpyDocstring(("{}\n"
- "{}\n"
- " this is a single line\n"
- ).format(section, '-' * len(section)), config))
- expect = (".. {}:: this is a single line\n"
- ).format(admonition)
+ actual = str(NumpyDocstring(f"{section}\n"
+ f"{'-' * len(section)}\n"
+ f" this is a single line\n",
+ config))
+ expect = f".. {admonition}:: this is a single line\n"
self.assertEqual(expect, actual)
def test_docstrings(self):
diff --git a/tests/test_ext_viewcode.py b/tests/test_ext_viewcode.py
index 6d443d1c6..ff53e5d37 100644
--- a/tests/test_ext_viewcode.py
+++ b/tests/test_ext_viewcode.py
@@ -36,8 +36,7 @@ def test_viewcode(app, status, warning):
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
'href="../../index.html#spam.Class1">[docs]</a>'
'<span>@decorator</span>\n'
- '<span>class</span> <span>Class1</span>'
- '<span>(</span><span>object</span><span>):</span>\n'
+ '<span>class</span> <span>Class1</span><span>:</span>\n'
'<span> </span><span>&quot;&quot;&quot;</span>\n'
'<span> this is Class1</span>\n'
'<span> &quot;&quot;&quot;</span></div>\n') in result
@@ -45,8 +44,7 @@ def test_viewcode(app, status, warning):
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
'href="../../index.html#spam.Class1">[docs]</a>'
'<span>@decorator</span>\n'
- '<span>class</span> <span>Class1</span>'
- '<span>(</span><span>object</span><span>):</span>\n'
+ '<span>class</span> <span>Class1</span><span>:</span>\n'
' <span>&quot;&quot;&quot;</span>\n'
'<span> this is Class1</span>\n'
'<span> &quot;&quot;&quot;</span></div>\n') in result
diff --git a/tests/test_intl.py b/tests/test_intl.py
index 07dfe8be3..3b04b293c 100644
--- a/tests/test_intl.py
+++ b/tests/test_intl.py
@@ -705,12 +705,12 @@ def test_html_index_entries(app):
def wrap(tag, keyword):
start_tag = "<%s[^>]*>" % tag
end_tag = "</%s>" % tag
- return r"%s\s*%s\s*%s" % (start_tag, keyword, end_tag)
+ return fr"{start_tag}\s*{keyword}\s*{end_tag}"
def wrap_nest(parenttag, childtag, keyword):
start_tag1 = "<%s[^>]*>" % parenttag
start_tag2 = "<%s[^>]*>" % childtag
- return r"%s\s*%s\s*%s" % (start_tag1, keyword, start_tag2)
+ return fr"{start_tag1}\s*{keyword}\s*{start_tag2}"
expected_exprs = [
wrap('a', 'NEWSLETTER'),
wrap('a', 'MAILING LIST'),