mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-25 22:50:22 -05:00
Remove some entries from the mypy whitelist (#14182)
This commit is contained in:
1 parent
9257a4f1bb
commit
b9650d5d26
12 files changed
+376
-249
No files matched your search
@@ -34,7 +34,7 @@ def test_catalog_info_for_sub_domain_file_and_path() -> None:
|
||||
assert cat.mo_path == Path('path', 'sub', 'domain.mo')
|
||||
|
||||
|
||||
def test_catalog_outdated(tmp_path):
|
||||
def test_catalog_outdated(tmp_path: Path) -> None:
|
||||
(tmp_path / 'test.po').write_text('#', encoding='utf8')
|
||||
cat = i18n.CatalogInfo(tmp_path, 'test', 'utf-8')
|
||||
assert cat.is_outdated() # if mo is not exist
|
||||
@@ -48,7 +48,7 @@ def test_catalog_outdated(tmp_path):
|
||||
assert cat.is_outdated() # if mo is exist and older than po
|
||||
|
||||
|
||||
def test_catalog_write_mo(tmp_path):
|
||||
def test_catalog_write_mo(tmp_path: Path) -> None:
|
||||
(tmp_path / 'test.po').write_text('#', encoding='utf8')
|
||||
cat = i18n.CatalogInfo(tmp_path, 'test', 'utf-8')
|
||||
cat.write_mo('en')
|
||||
@@ -58,8 +58,8 @@ def test_catalog_write_mo(tmp_path):
|
||||
assert read_mo(f) is not None
|
||||
|
||||
|
||||
def test_format_date():
|
||||
date = datetime.date(2016, 2, 7)
|
||||
def test_format_date() -> None:
|
||||
date = datetime.datetime(2016, 2, 7, 5, 11, 17, 0) # NoQA: DTZ001
|
||||
|
||||
# strftime format
|
||||
format = '%B %d, %Y'
|
||||
@@ -75,28 +75,25 @@ def test_format_date():
|
||||
assert i18n.format_date(format, date=date, language='en') == format
|
||||
|
||||
format = '%B %d, %Y, %H:%M:%S %I %p'
|
||||
datet = datetime.datetime(2016, 2, 7, 5, 11, 17, 0) # NoQA: DTZ001
|
||||
formatted = i18n.format_date(format, date=datet, language='en')
|
||||
formatted = i18n.format_date(format, date=date, language='en')
|
||||
assert formatted == 'February 07, 2016, 05:11:17 05 AM'
|
||||
|
||||
format = '%B %-d, %Y, %-H:%-M:%-S %-I %p'
|
||||
formatted = i18n.format_date(format, date=datet, language='en')
|
||||
formatted = i18n.format_date(format, date=date, language='en')
|
||||
assert formatted == 'February 7, 2016, 5:11:17 5 AM'
|
||||
format = '%x'
|
||||
assert i18n.format_date(format, date=datet, language='en') == 'Feb 7, 2016'
|
||||
assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
|
||||
format = '%X'
|
||||
assert i18n.format_date(format, date=datet, language='en') == '5:11:17\u202fAM'
|
||||
assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
|
||||
assert i18n.format_date(format, date=date, language='en') == '5:11:17\u202fAM'
|
||||
format = '%c'
|
||||
formatted = i18n.format_date(format, date=datet, language='en')
|
||||
formatted = i18n.format_date(format, date=date, language='en')
|
||||
assert formatted == 'Feb 7, 2016, 5:11:17\u202fAM'
|
||||
assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
|
||||
|
||||
# timezone
|
||||
format = '%Z'
|
||||
assert i18n.format_date(format, date=datet, language='en') == 'UTC'
|
||||
assert i18n.format_date(format, date=date, language='en') == 'UTC'
|
||||
format = '%z'
|
||||
assert i18n.format_date(format, date=datet, language='en') == '+0000'
|
||||
assert i18n.format_date(format, date=date, language='en') == '+0000'
|
||||
|
||||
|
||||
def test_format_date_timezone() -> None:
|
||||
@@ -163,7 +160,7 @@ def test_get_filename_for_language(app: SphinxTestApp) -> None:
|
||||
assert get_filename('foo.png', app.env) == '/subdir/en/foo.png'
|
||||
|
||||
|
||||
def test_CatalogRepository(tmp_path):
|
||||
def test_CatalogRepository(tmp_path: Path) -> None:
|
||||
for po_file in (
|
||||
(tmp_path / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po'),
|
||||
(tmp_path / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po'),
|
||||
|
||||
@@ -999,7 +999,7 @@ def test_getdoc_inherited_decorated_method():
|
||||
|
||||
def test_is_builtin_class_method() -> None:
|
||||
class MyInt(int):
|
||||
def my_method(self):
|
||||
def my_method(self) -> None:
|
||||
pass
|
||||
|
||||
assert inspect.is_builtin_class_method(MyInt, 'to_bytes')
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import codecs
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
@@ -21,6 +20,9 @@ from sphinx.util.parallel import ParallelTasks
|
||||
from tests.utils import TEST_ROOTS_DIR
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import io
|
||||
from collections.abc import Iterator
|
||||
|
||||
from sphinx.testing.util import SphinxTestApp
|
||||
|
||||
|
||||
@@ -124,16 +126,16 @@ def test_once_warning_log(app: SphinxTestApp) -> None:
|
||||
assert 'WARNING: message: 1\nWARNING: message: 2\n' in warnings
|
||||
|
||||
|
||||
def test_is_suppressed_warning():
|
||||
def test_is_suppressed_warning() -> None:
|
||||
suppress_warnings = ['ref', 'files.*', 'rest.duplicated_labels']
|
||||
|
||||
assert is_suppressed_warning(None, None, suppress_warnings) is False
|
||||
assert is_suppressed_warning('ref', None, suppress_warnings) is True
|
||||
assert is_suppressed_warning(None, None, suppress_warnings) is False # type: ignore[arg-type]
|
||||
assert is_suppressed_warning('ref', None, suppress_warnings) is True # type: ignore[arg-type]
|
||||
assert is_suppressed_warning('ref', 'numref', suppress_warnings) is True
|
||||
assert is_suppressed_warning('ref', 'option', suppress_warnings) is True
|
||||
assert is_suppressed_warning('files', 'image', suppress_warnings) is True
|
||||
assert is_suppressed_warning('files', 'stylesheet', suppress_warnings) is True
|
||||
assert is_suppressed_warning('rest', None, suppress_warnings) is False
|
||||
assert is_suppressed_warning('rest', None, suppress_warnings) is False # type: ignore[arg-type]
|
||||
assert is_suppressed_warning('rest', 'syntax', suppress_warnings) is False
|
||||
assert is_suppressed_warning('rest', 'duplicated_labels', suppress_warnings) is True
|
||||
|
||||
@@ -281,7 +283,7 @@ def test_pending_warnings(app: SphinxTestApp) -> None:
|
||||
|
||||
|
||||
@contextmanager
|
||||
def force_colors():
|
||||
def force_colors() -> Iterator[None]:
|
||||
forcecolor = os.environ.get('FORCE_COLOR', None)
|
||||
|
||||
try:
|
||||
@@ -294,7 +296,7 @@ def force_colors():
|
||||
os.environ['FORCE_COLOR'] = forcecolor
|
||||
|
||||
|
||||
def test_log_no_ansi_colors(tmp_path):
|
||||
def test_log_no_ansi_colors(tmp_path: Path) -> None:
|
||||
with force_colors():
|
||||
wfile = tmp_path / 'warnings.txt'
|
||||
srcdir = TEST_ROOTS_DIR / 'test-nitpicky-warnings'
|
||||
@@ -341,7 +343,7 @@ def test_logging_in_ParallelTasks(app: SphinxTestApp) -> None:
|
||||
logging.setup(app, app.status, app.warning)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def child_process():
|
||||
def child_process() -> None:
|
||||
logger.info('message1')
|
||||
logger.warning('message2', location='index')
|
||||
|
||||
@@ -353,12 +355,15 @@ def test_logging_in_ParallelTasks(app: SphinxTestApp) -> None:
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='root')
|
||||
def test_output_with_unencodable_char(app):
|
||||
class StreamWriter(codecs.StreamWriter):
|
||||
def write(self, object):
|
||||
def test_output_with_unencodable_char(app: SphinxTestApp) -> None:
|
||||
class StreamWriter:
|
||||
def __init__(self, stream: io.StringIO) -> None:
|
||||
self.stream = stream
|
||||
|
||||
def write(self, object: str) -> None:
|
||||
self.stream.write(object.encode('cp1252').decode('cp1252'))
|
||||
|
||||
logging.setup(app, StreamWriter(app.status), app.warning, verbosity=0)
|
||||
logging.setup(app, StreamWriter(app.status), app.warning, verbosity=0) # type: ignore[arg-type]
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# info with UnicodeEncodeError
|
||||
@@ -388,7 +393,7 @@ def test_prefixed_warnings(app: SphinxTestApp) -> None:
|
||||
assert 'WARNING: message5' in app.warning.getvalue()
|
||||
|
||||
|
||||
def test_get_node_location_abspath():
|
||||
def test_get_node_location_abspath() -> None:
|
||||
# Ensure that node locations are reported as an absolute path,
|
||||
# even if the source attribute is a relative path.
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ def test_make_id_sequential(app):
|
||||
('hello <world> <sphinx>', (True, 'hello <world>', 'sphinx')),
|
||||
],
|
||||
)
|
||||
def test_split_explicit_target(title, expected):
|
||||
def test_split_explicit_target(title: str, expected: tuple[bool, str, str]) -> None:
|
||||
assert split_explicit_title(title) == expected
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user