Skip to content

Commit d03156e

Browse files
authored
Format tests/ (#12760)
1 parent 620e434 commit d03156e

File tree

128 files changed

+19011
-10525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+19011
-10525
lines changed

tests/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020

2121
def _init_console(
22-
locale_dir: str | None = sphinx.locale._LOCALE_DIR, catalog: str = 'sphinx',
22+
locale_dir: str | None = sphinx.locale._LOCALE_DIR,
23+
catalog: str = 'sphinx',
2324
) -> tuple[gettext.NullTranslations, bool]:
2425
"""Monkeypatch ``init_console`` to skip its action.
2526
@@ -46,9 +47,9 @@ def rootdir() -> Path:
4647

4748

4849
def pytest_report_header(config: pytest.Config) -> str:
49-
header = f"libraries: Sphinx-{sphinx.__display_version__}, docutils-{docutils.__version__}"
50+
header = f'libraries: Sphinx-{sphinx.__display_version__}, docutils-{docutils.__version__}'
5051
if hasattr(config, '_tmp_path_factory'):
51-
header += f"\nbase tmp_path: {config._tmp_path_factory.getbasetemp()}"
52+
header += f'\nbase tmp_path: {config._tmp_path_factory.getbasetemp()}'
5253
return header
5354

5455

tests/roots/test-ext-autodoc/target/abstractmethods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import abstractmethod
22

33

4-
class Base():
4+
class Base:
55
def meth(self):
66
pass
77

tests/roots/test-ext-autodoc/target/callable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Callable():
1+
class Callable:
22
"""A callable object that behaves like a function."""
33

44
def __call__(self, arg1, arg2, **kwargs):

tests/roots/test-ext-autodoc/target/methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import partialmethod
22

33

4-
class Base():
4+
class Base:
55
def meth(self):
66
pass
77

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
class Class():
1+
class Class:
22
pass

tests/test_application.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test the Sphinx class."""
2+
23
from __future__ import annotations
34

45
import shutil
@@ -51,26 +52,27 @@ def test_instantiation(
5152
def test_events(app):
5253
def empty():
5354
pass
55+
5456
with pytest.raises(ExtensionError) as excinfo:
55-
app.connect("invalid", empty)
56-
assert "Unknown event name: invalid" in str(excinfo.value)
57+
app.connect('invalid', empty)
58+
assert 'Unknown event name: invalid' in str(excinfo.value)
5759

58-
app.add_event("my_event")
60+
app.add_event('my_event')
5961
with pytest.raises(ExtensionError) as excinfo:
60-
app.add_event("my_event")
62+
app.add_event('my_event')
6163
assert "Event 'my_event' already present" in str(excinfo.value)
6264

6365
def mock_callback(a_app, *args):
6466
assert a_app is app
6567
assert emit_args == args
66-
return "ret"
67-
emit_args = (1, 3, "string")
68-
listener_id = app.connect("my_event", mock_callback)
69-
assert app.emit("my_event", *emit_args) == ["ret"], "Callback not called"
68+
return 'ret'
69+
70+
emit_args = (1, 3, 'string')
71+
listener_id = app.connect('my_event', mock_callback)
72+
assert app.emit('my_event', *emit_args) == ['ret'], 'Callback not called'
7073

7174
app.disconnect(listener_id)
72-
assert app.emit("my_event", *emit_args) == [], \
73-
"Callback called when disconnected"
75+
assert app.emit('my_event', *emit_args) == [], 'Callback called when disconnected'
7476

7577

7678
def test_emit_with_nonascii_name_node(app):
@@ -121,14 +123,18 @@ def test_add_is_parallel_allowed(app):
121123
app.setup_extension('write_parallel')
122124
assert app.is_parallel_allowed('read') is False
123125
assert app.is_parallel_allowed('write') is True
124-
assert ("the write_parallel extension does not declare if it is safe "
125-
"for parallel reading, assuming it isn't - please ") in app.warning.getvalue()
126+
assert (
127+
'the write_parallel extension does not declare if it is safe '
128+
"for parallel reading, assuming it isn't - please "
129+
) in app.warning.getvalue()
126130
app.extensions.pop('write_parallel')
127131
app.warning.truncate(0) # reset warnings
128132

129133
app.setup_extension('read_serial')
130134
assert app.is_parallel_allowed('read') is False
131-
assert "the read_serial extension is not safe for parallel reading" in app.warning.getvalue()
135+
assert (
136+
'the read_serial extension is not safe for parallel reading'
137+
) in app.warning.getvalue()
132138
app.warning.truncate(0) # reset warnings
133139
assert app.is_parallel_allowed('write') is True
134140
assert app.warning.getvalue() == ''
@@ -137,26 +143,32 @@ def test_add_is_parallel_allowed(app):
137143
app.setup_extension('write_serial')
138144
assert app.is_parallel_allowed('read') is False
139145
assert app.is_parallel_allowed('write') is False
140-
assert ("the write_serial extension does not declare if it is safe "
141-
"for parallel reading, assuming it isn't - please ") in app.warning.getvalue()
146+
assert (
147+
'the write_serial extension does not declare if it is safe '
148+
"for parallel reading, assuming it isn't - please "
149+
) in app.warning.getvalue()
142150
app.extensions.pop('write_serial')
143151
app.warning.truncate(0) # reset warnings
144152

145153

146154
@pytest.mark.sphinx('dummy', testroot='root')
147155
def test_build_specific(app):
148156
app.builder.build = Mock()
149-
filenames = [app.srcdir / 'index.txt', # normal
150-
app.srcdir / 'images', # without suffix
151-
app.srcdir / 'notfound.txt', # not found
152-
app.srcdir / 'img.png', # unknown suffix
153-
'/index.txt', # external file
154-
app.srcdir / 'subdir', # directory
155-
app.srcdir / 'subdir/includes.txt', # file on subdir
156-
app.srcdir / 'subdir/../subdir/excluded.txt'] # not normalized
157+
filenames = [
158+
app.srcdir / 'index.txt', # normal
159+
app.srcdir / 'images', # without suffix
160+
app.srcdir / 'notfound.txt', # not found
161+
app.srcdir / 'img.png', # unknown suffix
162+
'/index.txt', # external file
163+
app.srcdir / 'subdir', # directory
164+
app.srcdir / 'subdir/includes.txt', # file on subdir
165+
app.srcdir / 'subdir/../subdir/excluded.txt', # not normalized
166+
] # fmt: skip
157167
app.build(False, filenames)
158168

159169
expected = ['index', 'subdir/includes', 'subdir/excluded']
160-
app.builder.build.assert_called_with(expected,
161-
method='specific',
162-
summary='3 source files given on command line')
170+
app.builder.build.assert_called_with(
171+
expected,
172+
method='specific',
173+
summary='3 source files given on command line',
174+
)

tests/test_builders/test_build.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,67 +31,76 @@ def nonascii_srcdir(request, rootdir, sphinx_test_tempdir):
3131
shutil.copytree(rootdir / 'test-root', srcdir)
3232

3333
# add a doc with a non-ASCII file name to the source dir
34-
(srcdir / (test_name + '.txt')).write_text("""
34+
(srcdir / (test_name + '.txt')).write_text(
35+
"""
3536
nonascii file name page
3637
=======================
37-
""", encoding='utf8')
38+
""",
39+
encoding='utf8',
40+
)
3841

3942
root_doc = srcdir / 'index.txt'
40-
root_doc.write_text(root_doc.read_text(encoding='utf8') + f"""
43+
root_doc.write_text(
44+
root_doc.read_text(encoding='utf8')
45+
+ f"""
4146
.. toctree::
4247
4348
{test_name}/{test_name}
44-
""", encoding='utf8')
49+
""",
50+
encoding='utf8',
51+
)
4552
return srcdir
4653

4754

4855
# note: this test skips building docs for some builders because they have independent testcase.
4956
# (html, changes, epub, latex, texinfo and manpage)
5057
@pytest.mark.parametrize(
51-
"buildername",
58+
'buildername',
5259
['dirhtml', 'singlehtml', 'text', 'xml', 'pseudoxml', 'linkcheck'],
5360
)
54-
@mock.patch('sphinx.builders.linkcheck.requests.head',
55-
side_effect=request_session_head)
61+
@mock.patch(
62+
'sphinx.builders.linkcheck.requests.head',
63+
side_effect=request_session_head,
64+
)
5665
def test_build_all(requests_head, make_app, nonascii_srcdir, buildername):
5766
app = make_app(buildername, srcdir=nonascii_srcdir)
5867
app.build()
5968

6069

6170
def test_root_doc_not_found(tmp_path, make_app):
62-
(tmp_path / 'conf.py').write_text('', encoding='utf8')
71+
(tmp_path / 'conf.py').touch()
6372
assert os.listdir(tmp_path) == ['conf.py']
6473

6574
app = make_app('dummy', srcdir=tmp_path)
6675
with pytest.raises(SphinxError):
6776
app.build(force_all=True) # no index.rst
6877

6978

70-
@pytest.mark.sphinx(buildername='text', testroot='circular')
79+
@pytest.mark.sphinx('text', testroot='circular')
7180
def test_circular_toctree(app):
7281
app.build(force_all=True)
7382
warnings = app.warning.getvalue()
7483
assert (
75-
'circular toctree references detected, ignoring: '
76-
'sub <- index <- sub') in warnings
84+
'circular toctree references detected, ignoring: sub <- index <- sub'
85+
) in warnings
7786
assert (
78-
'circular toctree references detected, ignoring: '
79-
'index <- sub <- index') in warnings
87+
'circular toctree references detected, ignoring: index <- sub <- index'
88+
) in warnings
8089

8190

82-
@pytest.mark.sphinx(buildername='text', testroot='numbered-circular')
91+
@pytest.mark.sphinx('text', testroot='numbered-circular')
8392
def test_numbered_circular_toctree(app):
8493
app.build(force_all=True)
8594
warnings = app.warning.getvalue()
8695
assert (
87-
'circular toctree references detected, ignoring: '
88-
'sub <- index <- sub') in warnings
96+
'circular toctree references detected, ignoring: sub <- index <- sub'
97+
) in warnings
8998
assert (
90-
'circular toctree references detected, ignoring: '
91-
'index <- sub <- index') in warnings
99+
'circular toctree references detected, ignoring: index <- sub <- index'
100+
) in warnings
92101

93102

94-
@pytest.mark.sphinx(buildername='dummy', testroot='images')
103+
@pytest.mark.sphinx('dummy', testroot='images')
95104
def test_image_glob(app):
96105
app.build(force_all=True)
97106

@@ -108,16 +117,20 @@ def test_image_glob(app):
108117
assert doctree[0][2][0]['uri'] == 'rimg.png'
109118

110119
assert isinstance(doctree[0][3], nodes.image)
111-
assert doctree[0][3]['candidates'] == {'application/pdf': 'img.pdf',
112-
'image/gif': 'img.gif',
113-
'image/png': 'img.png'}
120+
assert doctree[0][3]['candidates'] == {
121+
'application/pdf': 'img.pdf',
122+
'image/gif': 'img.gif',
123+
'image/png': 'img.png',
124+
}
114125
assert doctree[0][3]['uri'] == 'img.*'
115126

116127
assert isinstance(doctree[0][4], nodes.figure)
117128
assert isinstance(doctree[0][4][0], nodes.image)
118-
assert doctree[0][4][0]['candidates'] == {'application/pdf': 'img.pdf',
119-
'image/gif': 'img.gif',
120-
'image/png': 'img.png'}
129+
assert doctree[0][4][0]['candidates'] == {
130+
'application/pdf': 'img.pdf',
131+
'image/gif': 'img.gif',
132+
'image/png': 'img.png',
133+
}
121134
assert doctree[0][4][0]['uri'] == 'img.*'
122135

123136
# subdir/index.rst
@@ -128,14 +141,18 @@ def test_image_glob(app):
128141
assert doctree[0][1]['uri'] == 'subdir/rimg.png'
129142

130143
assert isinstance(doctree[0][2], nodes.image)
131-
assert doctree[0][2]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
132-
'image/svg+xml': 'subdir/svgimg.svg'}
144+
assert doctree[0][2]['candidates'] == {
145+
'application/pdf': 'subdir/svgimg.pdf',
146+
'image/svg+xml': 'subdir/svgimg.svg',
147+
}
133148
assert doctree[0][2]['uri'] == 'subdir/svgimg.*'
134149

135150
assert isinstance(doctree[0][3], nodes.figure)
136151
assert isinstance(doctree[0][3][0], nodes.image)
137-
assert doctree[0][3][0]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
138-
'image/svg+xml': 'subdir/svgimg.svg'}
152+
assert doctree[0][3][0]['candidates'] == {
153+
'application/pdf': 'subdir/svgimg.pdf',
154+
'image/svg+xml': 'subdir/svgimg.svg',
155+
}
139156
assert doctree[0][3][0]['uri'] == 'subdir/svgimg.*'
140157

141158

tests/test_builders/test_build_changes.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,23 @@ def test_build(app):
1515

1616
path_html = (
1717
'<b>Path</b>: <i>deprecated:</i> Deprecated since version 0.6:'
18-
' So, that was a bad idea it turns out.')
18+
' So, that was a bad idea it turns out.'
19+
)
1920
assert path_html in htmltext
2021

2122
malloc_html = (
2223
'<b>void *Test_Malloc(size_t n)</b>: <i>changed:</i> Changed in version 0.6:'
23-
' Can now be replaced with a different allocator.</a>')
24+
' Can now be replaced with a different allocator.</a>'
25+
)
2426
assert malloc_html in htmltext
2527

2628

2729
@pytest.mark.sphinx(
28-
'changes', testroot='changes', srcdir='changes-none',
29-
confoverrides={'version': '0.7', 'release': '0.7b1'})
30+
'changes',
31+
testroot='changes',
32+
srcdir='changes-none',
33+
confoverrides={'version': '0.7', 'release': '0.7b1'},
34+
)
3035
def test_no_changes(app):
3136
app.build()
3237

tests/test_builders/test_build_dirhtml.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sphinx.util.inventory import InventoryFile
88

99

10-
@pytest.mark.sphinx(buildername='dirhtml', testroot='builder-dirhtml')
10+
@pytest.mark.sphinx('dirhtml', testroot='builder-dirhtml')
1111
def test_dirhtml(app):
1212
app.build()
1313

@@ -31,10 +31,25 @@ def test_dirhtml(app):
3131
assert invdata['std:doc']['index'] == ('Project name not set', '', 'path/to/', '-')
3232

3333
assert 'foo/index' in invdata.get('std:doc', {})
34-
assert invdata['std:doc']['foo/index'] == ('Project name not set', '', 'path/to/foo/', '-')
34+
assert invdata['std:doc']['foo/index'] == (
35+
'Project name not set',
36+
'',
37+
'path/to/foo/',
38+
'-',
39+
)
3540

3641
assert 'index' in invdata.get('std:label', {})
37-
assert invdata['std:label']['index'] == ('Project name not set', '', 'path/to/#index', '-')
42+
assert invdata['std:label']['index'] == (
43+
'Project name not set',
44+
'',
45+
'path/to/#index',
46+
'-',
47+
)
3848

3949
assert 'foo' in invdata.get('std:label', {})
40-
assert invdata['std:label']['foo'] == ('Project name not set', '', 'path/to/foo/#foo', 'foo/index')
50+
assert invdata['std:label']['foo'] == (
51+
'Project name not set',
52+
'',
53+
'path/to/foo/#foo',
54+
'foo/index',
55+
)

0 commit comments

Comments
 (0)