Skip to content

Commit 93ca46a

Browse files
committed
Remove mypy overrides for tests.test_quickstart
1 parent a15c149 commit 93ca46a

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ disallow_untyped_defs = false
295295
[[tool.mypy.overrides]]
296296
module = [
297297
# tests/
298-
"tests.test_quickstart",
299298
"tests.test_search",
300299
# tests/test_builders
301300
"tests.test_builders.test_build_latex",

tests/test_quickstart.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import time
66
from io import StringIO
7-
from typing import TYPE_CHECKING
7+
from typing import TYPE_CHECKING, Protocol
88

99
import pytest
1010

@@ -13,20 +13,26 @@
1313
from sphinx.testing.util import SphinxTestApp
1414

1515
if TYPE_CHECKING:
16-
from collections.abc import Callable
1716
from pathlib import Path
1817
from typing import Any
1918

2019
warnfile = StringIO()
2120

2221

23-
def setup_module():
22+
def setup_module() -> None:
2423
disable_colour()
2524

2625

26+
class _MockTermInput(Protocol):
27+
"""Protocol for mocking term_input in quickstart."""
28+
29+
def __call__(self, prompt: str) -> str:
30+
"""Mock input function that returns a string based on the prompt."""
31+
32+
2733
def mock_input(
2834
answers: dict[str, str], needanswer: bool = False
29-
) -> Callable[[str], str]:
35+
) -> _MockTermInput:
3036
called = set()
3137

3238
def input_(prompt: str) -> str:
@@ -45,10 +51,16 @@ def input_(prompt: str) -> str:
4551
return input_
4652

4753

48-
real_input: Callable[[str], str] = input
54+
def _real_input_but_allow_named_args_in_hint(*args: str, **kwargs: str) -> str:
55+
"""A wrapper for the real input function to allow named arguments in the type hint."""
56+
assert not kwargs, 'Named arguments are not allowed in input()'
57+
return input(*args)
58+
4959

60+
real_input: _MockTermInput = _real_input_but_allow_named_args_in_hint
5061

51-
def teardown_module():
62+
63+
def teardown_module() -> None:
5264
qs.term_input = real_input
5365
enable_colour()
5466

@@ -61,7 +73,7 @@ def test_do_prompt() -> None:
6173
'Q5': 'no',
6274
'Q6': 'foo',
6375
}
64-
qs.term_input = mock_input(answers) # type: ignore[assignment]
76+
qs.term_input = mock_input(answers)
6577

6678
assert qs.do_prompt('Q1', default='v1') == 'v1'
6779
assert qs.do_prompt('Q3', default='v3_default') == 'v3'
@@ -79,7 +91,7 @@ def test_do_prompt_inputstrip() -> None:
7991
'Q3': 'N',
8092
'Q4': 'N ',
8193
}
82-
qs.term_input = mock_input(answers) # type: ignore[assignment]
94+
qs.term_input = mock_input(answers)
8395

8496
assert qs.do_prompt('Q1') == 'Y'
8597
assert qs.do_prompt('Q2') == 'Yes'
@@ -91,12 +103,12 @@ def test_do_prompt_with_nonascii() -> None:
91103
answers = {
92104
'Q1': '\u30c9\u30a4\u30c4',
93105
}
94-
qs.term_input = mock_input(answers) # type: ignore[assignment]
106+
qs.term_input = mock_input(answers)
95107
result = qs.do_prompt('Q1', default='\u65e5\u672c')
96108
assert result == '\u30c9\u30a4\u30c4'
97109

98110

99-
def test_quickstart_defaults(tmp_path):
111+
def test_quickstart_defaults(tmp_path: Path) -> None:
100112
answers = {
101113
'Root path': str(tmp_path),
102114
'Project name': 'Sphinx Test',
@@ -127,7 +139,7 @@ def test_quickstart_defaults(tmp_path):
127139
assert (tmp_path / 'make.bat').is_file()
128140

129141

130-
def test_quickstart_all_answers(tmp_path):
142+
def test_quickstart_all_answers(tmp_path: Path) -> None:
131143
answers = {
132144
'Root path': str(tmp_path),
133145
'Separate source and build': 'y',
@@ -185,7 +197,7 @@ def test_quickstart_all_answers(tmp_path):
185197
assert (tmp_path / 'source' / 'contents.txt').is_file()
186198

187199

188-
def test_generated_files_eol(tmp_path):
200+
def test_generated_files_eol(tmp_path: Path) -> None:
189201
answers = {
190202
'Root path': str(tmp_path),
191203
'Project name': 'Sphinx Test',
@@ -205,7 +217,7 @@ def assert_eol(filename: Path, eol: str) -> None:
205217
assert_eol(tmp_path / 'Makefile', '\n')
206218

207219

208-
def test_quickstart_and_build(tmp_path):
220+
def test_quickstart_and_build(tmp_path: Path) -> None:
209221
answers = {
210222
'Root path': str(tmp_path),
211223
'Project name': 'Fullwidth characters: \u30c9\u30a4\u30c4',
@@ -224,7 +236,7 @@ def test_quickstart_and_build(tmp_path):
224236
assert not warnings
225237

226238

227-
def test_default_filename(tmp_path):
239+
def test_default_filename(tmp_path: Path) -> None:
228240
answers = {
229241
'Root path': str(tmp_path),
230242
'Project name': '\u30c9\u30a4\u30c4', # Fullwidth characters only
@@ -242,7 +254,7 @@ def test_default_filename(tmp_path):
242254
exec(conffile.read_text(encoding='utf8'), ns) # NoQA: S102
243255

244256

245-
def test_extensions(tmp_path):
257+
def test_extensions(tmp_path: Path) -> None:
246258
qs.main([
247259
'-q',
248260
'-p',
@@ -261,7 +273,7 @@ def test_extensions(tmp_path):
261273
assert ns['extensions'] == ['foo', 'bar', 'baz']
262274

263275

264-
def test_exits_when_existing_confpy(monkeypatch):
276+
def test_exits_when_existing_confpy(monkeypatch: pytest.MonkeyPatch) -> None:
265277
# The code detects existing conf.py with path.is_file()
266278
# so we mock it as True with pytest's monkeypatch
267279
monkeypatch.setattr('os.path.isfile', lambda path: True)

0 commit comments

Comments
 (0)