Skip to content

Remove mypy overrides for tests/test_directives/test_directive_code.py #13765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions tests/test_directives/test_directive_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@


@pytest.fixture(scope='module')
def testroot(rootdir):
def testroot(rootdir: Path) -> Path:
testroot_path = rootdir / 'test-directive-code'
return testroot_path


@pytest.fixture(scope='module')
def literal_inc_path(testroot):
def literal_inc_path(testroot: Path) -> Path:
return testroot / 'literal.inc'


def test_LiteralIncludeReader(literal_inc_path):
def test_LiteralIncludeReader(literal_inc_path: Path) -> None:
options = {'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
Expand All @@ -39,7 +39,7 @@ def test_LiteralIncludeReader(literal_inc_path):
assert reader.lineno_start == 1


def test_LiteralIncludeReader_lineno_start(literal_inc_path):
def test_LiteralIncludeReader_lineno_start(literal_inc_path: Path) -> None:
options = {'lineno-start': 4}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
Expand All @@ -48,37 +48,37 @@ def test_LiteralIncludeReader_lineno_start(literal_inc_path):
assert reader.lineno_start == 4


def test_LiteralIncludeReader_pyobject1(literal_inc_path):
def test_LiteralIncludeReader_pyobject1(literal_inc_path: Path) -> None:
options = {'lineno-match': True, 'pyobject': 'Foo'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == 'class Foo:\n pass\n'
assert reader.lineno_start == 5


def test_LiteralIncludeReader_pyobject2(literal_inc_path):
def test_LiteralIncludeReader_pyobject2(literal_inc_path: Path) -> None:
options = {'pyobject': 'Bar'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == 'class Bar:\n def baz():\n pass\n'
assert reader.lineno_start == 1 # no lineno-match


def test_LiteralIncludeReader_pyobject3(literal_inc_path):
def test_LiteralIncludeReader_pyobject3(literal_inc_path: Path) -> None:
options = {'pyobject': 'Bar.baz'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == ' def baz():\n pass\n'


def test_LiteralIncludeReader_pyobject_and_lines(literal_inc_path):
def test_LiteralIncludeReader_pyobject_and_lines(literal_inc_path: Path) -> None:
options = {'pyobject': 'Bar', 'lines': '2-'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == ' def baz():\n pass\n'


def test_LiteralIncludeReader_lines1(literal_inc_path):
def test_LiteralIncludeReader_lines1(literal_inc_path: Path) -> None:
options = {'lines': '1-3'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
Expand All @@ -89,7 +89,7 @@ def test_LiteralIncludeReader_lines1(literal_inc_path):
)


def test_LiteralIncludeReader_lines2(literal_inc_path):
def test_LiteralIncludeReader_lines2(literal_inc_path: Path) -> None:
options = {'lines': '1,3,5'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
Expand All @@ -100,7 +100,7 @@ def test_LiteralIncludeReader_lines2(literal_inc_path):
)


def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path):
def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path: Path) -> None:
options = {'lines': '3-5', 'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
Expand All @@ -109,7 +109,9 @@ def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path):


@pytest.mark.sphinx('html', testroot='root') # init locale for errors
def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app):
def test_LiteralIncludeReader_lines_and_lineno_match2(
literal_inc_path: Path, app: SphinxTestApp
) -> None:
options = {'lines': '0,3,5', 'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
with pytest.raises(
Expand All @@ -120,7 +122,9 @@ def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app):


@pytest.mark.sphinx('html', testroot='root') # init locale for errors
def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app):
def test_LiteralIncludeReader_lines_and_lineno_match3(
literal_inc_path: Path, app: SphinxTestApp
) -> None:
options = {'lines': '100-', 'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
with pytest.raises(
Expand All @@ -130,23 +134,23 @@ def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app):
reader.read()


def test_LiteralIncludeReader_start_at(literal_inc_path):
def test_LiteralIncludeReader_start_at(literal_inc_path: Path) -> None:
options = {'lineno-match': True, 'start-at': 'Foo', 'end-at': 'Bar'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == 'class Foo:\n pass\n\nclass Bar:\n'
assert reader.lineno_start == 5


def test_LiteralIncludeReader_start_after(literal_inc_path):
def test_LiteralIncludeReader_start_after(literal_inc_path: Path) -> None:
options = {'lineno-match': True, 'start-after': 'Foo', 'end-before': 'Bar'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == ' pass\n\n'
assert reader.lineno_start == 6


def test_LiteralIncludeReader_start_after_and_lines(literal_inc_path):
def test_LiteralIncludeReader_start_after_and_lines(literal_inc_path: Path) -> None:
options = {
'lineno-match': True,
'lines': '6-',
Expand All @@ -159,15 +163,15 @@ def test_LiteralIncludeReader_start_after_and_lines(literal_inc_path):
assert reader.lineno_start == 7


def test_LiteralIncludeReader_start_at_and_lines(literal_inc_path):
def test_LiteralIncludeReader_start_at_and_lines(literal_inc_path: Path) -> None:
options = {'lines': '2, 3, 5', 'start-at': 'foo', 'end-before': '#'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == '\nclass Foo:\n\n'
assert reader.lineno_start == 1


def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path):
def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path: Path) -> None:
options = {'start-at': 'NOTHING'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
with pytest.raises(ValueError, match='start-at pattern not found: NOTHING'):
Expand All @@ -189,14 +193,14 @@ def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path):
reader.read()


def test_LiteralIncludeReader_end_before(literal_inc_path):
def test_LiteralIncludeReader_end_before(literal_inc_path: Path) -> None:
options = {'end-before': 'nclud'} # *nclud* matches first and third lines.
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
assert content == '# Literally included file using Python highlighting\n\n'


def test_LiteralIncludeReader_prepend(literal_inc_path):
def test_LiteralIncludeReader_prepend(literal_inc_path: Path) -> None:
options = {'lines': '1', 'prepend': 'Hello', 'append': 'Sphinx'}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, _lines = reader.read()
Expand All @@ -205,7 +209,7 @@ def test_LiteralIncludeReader_prepend(literal_inc_path):
)


def test_LiteralIncludeReader_dedent(literal_inc_path):
def test_LiteralIncludeReader_dedent(literal_inc_path: Path) -> None:
# dedent: 2
options = {'lines': '9-11', 'dedent': 2}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -231,7 +235,9 @@ def test_LiteralIncludeReader_dedent(literal_inc_path):
assert content == 'def baz():\n pass\n\n'


def test_LiteralIncludeReader_dedent_and_append_and_prepend(literal_inc_path):
def test_LiteralIncludeReader_dedent_and_append_and_prepend(
literal_inc_path: Path,
) -> None:
# dedent: 2
options = {
'lines': '9-11',
Expand Down
Loading