Add annotations to several single-argument ('app') test functions

This commit is contained in:
Adam Turner committed 2025-02-16 01:40:30 +00:00
1 parent a980fbcafa
commit f1fbbfcbb7
88 files changed
+870 -496

No files matched your search

+7 -2
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from sphinx._cli.util.errors import strip_escape_sequences
@@ -13,6 +15,9 @@ from sphinx.util.display import (
status_iterator,
)
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp
def test_display_chunk() -> None:
assert display_chunk('hello') == 'hello'
@@ -23,7 +28,7 @@ def test_display_chunk() -> None:
@pytest.mark.sphinx('dummy', testroot='root')
def test_status_iterator_length_0(app):
def test_status_iterator_length_0(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
# test for status_iterator (length=0)
@@ -72,7 +77,7 @@ def test_status_iterator_verbosity_1(app, monkeypatch):
@pytest.mark.sphinx('html', testroot='root')
def test_progress_message(app):
def test_progress_message(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
+2 -1
View File
@@ -18,6 +18,7 @@ from sphinx.util.docutils import (
if TYPE_CHECKING:
from sphinx.builders import Builder
from sphinx.testing.util import SphinxTestApp
def test_register_node() -> None:
@@ -69,7 +70,7 @@ def test_SphinxFileOutput(tmp_path):
@pytest.mark.sphinx('html', testroot='root')
def test_SphinxTranslator(app):
def test_SphinxTranslator(app: SphinxTestApp) -> None:
class CustomNode(nodes.inline):
pass
+6 -2
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import re
from pathlib import Path
from typing import TYPE_CHECKING
from unittest import mock
import pytest
@@ -12,6 +13,9 @@ from sphinx._cli.util.errors import strip_escape_sequences
from sphinx.jinja2glue import BuiltinTemplateLoader
from sphinx.util.fileutil import _template_basename, copy_asset, copy_asset_file
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp
class DummyTemplateLoader(BuiltinTemplateLoader):
def __init__(self) -> None:
@@ -124,7 +128,7 @@ def test_copy_asset(tmp_path):
@pytest.mark.sphinx('html', testroot='html_assets')
def test_copy_asset_template(app):
def test_copy_asset_template(app: SphinxTestApp) -> None:
app.build(force_all=True)
expected_msg = r'^Writing evaluated template result to [^\n]*\bAPI.html$'
@@ -133,7 +137,7 @@ def test_copy_asset_template(app):
@pytest.mark.sphinx('html', testroot='util-copyasset_overwrite')
def test_copy_asset_overwrite(app):
def test_copy_asset_overwrite(app: SphinxTestApp) -> None:
app.build()
src = app.srcdir / 'myext_static' / 'custom-styles.css'
dst = app.outdir / '_static' / 'custom-styles.css'
+5 -1
View File
@@ -7,6 +7,7 @@ import os
import sys
import time
from pathlib import Path
from typing import TYPE_CHECKING
import babel
import pytest
@@ -15,6 +16,9 @@ from babel.messages.mofile import read_mo
from sphinx.errors import SphinxError
from sphinx.util import i18n
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp
def test_catalog_info_for_file_and_path() -> None:
cat = i18n.CatalogInfo('path', 'domain', 'utf-8')
@@ -121,7 +125,7 @@ def test_format_date_timezone() -> None:
@pytest.mark.sphinx('html', testroot='root')
def test_get_filename_for_language(app):
def test_get_filename_for_language(app: SphinxTestApp) -> None:
get_filename = i18n.get_image_filename_for_language
app.env.current_document.docname = 'index'
+1 -1
View File
@@ -72,7 +72,7 @@ def test_read_inventory_v2_not_having_version() -> None:
@pytest.mark.sphinx('html', testroot='root')
def test_ambiguous_definition_warning(app):
def test_ambiguous_definition_warning(app: SphinxTestApp) -> None:
InventoryFile.loads(INVENTORY_V2_AMBIGUOUS_TERMS, uri='/util')
def _multiple_defs_notice_for(entity: str) -> str:
+21 -17
View File
@@ -6,6 +6,7 @@ import codecs
import os
from contextlib import contextmanager
from pathlib import Path
from typing import TYPE_CHECKING
import pytest
from docutils import nodes
@@ -19,9 +20,12 @@ from sphinx.util.parallel import ParallelTasks
from tests.utils import TESTS_ROOT
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp
@pytest.mark.sphinx('html', testroot='root')
def test_info_and_warning(app):
def test_info_and_warning(app: SphinxTestApp) -> None:
app.verbosity = 2
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -46,7 +50,7 @@ def test_info_and_warning(app):
@pytest.mark.sphinx('html', testroot='root')
def test_Exception(app):
def test_Exception(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -55,7 +59,7 @@ def test_Exception(app):
@pytest.mark.sphinx('html', testroot='root')
def test_verbosity_filter(app):
def test_verbosity_filter(app: SphinxTestApp) -> None:
# verbosity = 0: INFO
app.verbosity = 0
logging.setup(app, app.status, app.warning)
@@ -100,7 +104,7 @@ def test_verbosity_filter(app):
@pytest.mark.sphinx('html', testroot='root')
def test_nonl_info_log(app):
def test_nonl_info_log(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -112,7 +116,7 @@ def test_nonl_info_log(app):
@pytest.mark.sphinx('html', testroot='root')
def test_once_warning_log(app):
def test_once_warning_log(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -139,7 +143,7 @@ def test_is_suppressed_warning():
@pytest.mark.sphinx('html', testroot='root')
def test_suppress_warnings(app):
def test_suppress_warnings(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -183,7 +187,7 @@ def test_suppress_warnings(app):
@pytest.mark.sphinx('html', testroot='root')
def test_info_location(app):
def test_info_location(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -196,7 +200,7 @@ def test_info_location(app):
logger.info('message3', location=None)
assert '\nmessage3' in app.status.getvalue()
node = nodes.Node()
node = nodes.Element()
node.source, node.line = ('index.txt', 10)
logger.info('message4', location=node)
assert 'index.txt:10: message4' in app.status.getvalue()
@@ -215,7 +219,7 @@ def test_info_location(app):
@pytest.mark.sphinx('html', testroot='root')
def test_warning_location(app):
def test_warning_location(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -228,7 +232,7 @@ def test_warning_location(app):
logger.warning('message3', location=None)
assert colorize('red', 'WARNING: message3') in app.warning.getvalue()
node = nodes.Node()
node = nodes.Element()
node.source, node.line = ('index.txt', 10)
logger.warning('message4', location=node)
assert 'index.txt:10: WARNING: message4' in app.warning.getvalue()
@@ -247,7 +251,7 @@ def test_warning_location(app):
@pytest.mark.sphinx('html', testroot='root')
def test_suppress_logging(app):
def test_suppress_logging(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -262,7 +266,7 @@ def test_suppress_logging(app):
@pytest.mark.sphinx('html', testroot='root')
def test_pending_warnings(app):
def test_pending_warnings(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -307,7 +311,7 @@ def test_log_no_ansi_colors(tmp_path):
@pytest.mark.sphinx('html', testroot='root')
def test_colored_logs(app):
def test_colored_logs(app: SphinxTestApp) -> None:
app.verbosity = 2
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -338,7 +342,7 @@ def test_colored_logs(app):
os.name != 'posix',
reason='Parallel mode does not work on Windows',
)
def test_logging_in_ParallelTasks(app):
def test_logging_in_ParallelTasks(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -370,7 +374,7 @@ def test_output_with_unencodable_char(app):
@pytest.mark.sphinx('html', testroot='root')
def test_prefixed_warnings(app):
def test_prefixed_warnings(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
@@ -396,7 +400,7 @@ def test_get_node_location_abspath():
relative_filename = Path('relative', 'path.txt')
absolute_filename = relative_filename.resolve()
n = nodes.Node()
n = nodes.Element()
n.source = str(relative_filename)
location = logging.get_node_location(n)
@@ -405,7 +409,7 @@ def test_get_node_location_abspath():
@pytest.mark.sphinx('html', testroot='root', confoverrides={'show_warning_types': True})
def test_show_warning_types(app):
def test_show_warning_types(app: SphinxTestApp) -> None:
logging.setup(app, app.status, app.warning)
logger = logging.getLogger(__name__)
logger.warning('message2')