Address warnings in test_util_i18n.py

This commit is contained in:
Adam Turner 2022-04-18 00:17:21 +01:00
parent d951e55bc3
commit c08bffde98
4 changed files with 19 additions and 14 deletions

View File

@ -483,7 +483,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
metadata['copyright'] = html.escape(self.config.epub_copyright) metadata['copyright'] = html.escape(self.config.epub_copyright)
metadata['scheme'] = html.escape(self.config.epub_scheme) metadata['scheme'] = html.escape(self.config.epub_scheme)
metadata['id'] = html.escape(self.config.epub_identifier) metadata['id'] = html.escape(self.config.epub_identifier)
metadata['date'] = html.escape(format_date("%Y-%m-%d")) metadata['date'] = html.escape(format_date("%Y-%m-%d", language='en'))
metadata['manifest_items'] = [] metadata['manifest_items'] = []
metadata['spines'] = [] metadata['spines'] = []
metadata['guides'] = [] metadata['guides'] = []

View File

@ -88,7 +88,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
metadata['contributor'] = html.escape(self.config.epub_contributor) metadata['contributor'] = html.escape(self.config.epub_contributor)
metadata['page_progression_direction'] = PAGE_PROGRESSION_DIRECTIONS.get(writing_mode) metadata['page_progression_direction'] = PAGE_PROGRESSION_DIRECTIONS.get(writing_mode)
metadata['ibook_scroll_axis'] = IBOOK_SCROLL_AXIS.get(writing_mode) metadata['ibook_scroll_axis'] = IBOOK_SCROLL_AXIS.get(writing_mode)
metadata['date'] = html.escape(format_date("%Y-%m-%dT%H:%M:%SZ")) metadata['date'] = html.escape(format_date("%Y-%m-%dT%H:%M:%SZ", language='en'))
metadata['version'] = html.escape(self.config.version) metadata['version'] = html.escape(self.config.version)
metadata['epub_version'] = self.config.epub_version metadata['epub_version'] = self.config.epub_version
return metadata return metadata

View File

@ -405,7 +405,7 @@ def correct_copyright_year(app: "Sphinx", config: Config) -> None:
if getenv('SOURCE_DATE_EPOCH') is not None: if getenv('SOURCE_DATE_EPOCH') is not None:
for k in ('copyright', 'epub_copyright'): for k in ('copyright', 'epub_copyright'):
if k in config: if k in config:
replace = r'\g<1>%s' % format_date('%Y') replace = r'\g<1>%s' % format_date('%Y', language='en')
config[k] = copyright_year_re.sub(replace, config[k]) config[k] = copyright_year_re.sub(replace, config[k])

View File

@ -2,6 +2,7 @@
import datetime import datetime
import os import os
import warnings
import pytest import pytest
from babel.messages.mofile import read_mo from babel.messages.mofile import read_mo
@ -53,6 +54,10 @@ def test_format_date():
# strftime format # strftime format
format = '%B %d, %Y' format = '%B %d, %Y'
with warnings.catch_warnings():
# Test format_date() with no language argument -- this form will be
# removed in Sphinx 7 (xref RemovedInSphinx70Warning)
warnings.simplefilter("ignore")
assert i18n.format_date(format, date=date) == 'February 07, 2016' assert i18n.format_date(format, date=date) == 'February 07, 2016'
assert i18n.format_date(format, date=date, language='') == 'February 07, 2016' assert i18n.format_date(format, date=date, language='') == 'February 07, 2016'
assert i18n.format_date(format, date=date, language='unknown') == 'February 07, 2016' assert i18n.format_date(format, date=date, language='unknown') == 'February 07, 2016'
@ -62,28 +67,28 @@ def test_format_date():
# raw string # raw string
format = 'Mon Mar 28 12:37:08 2016, commit 4367aef' format = 'Mon Mar 28 12:37:08 2016, commit 4367aef'
assert i18n.format_date(format, date=date) == format assert i18n.format_date(format, date=date, language='en') == format
format = '%B %d, %Y, %H:%M:%S %I %p' format = '%B %d, %Y, %H:%M:%S %I %p'
datet = datetime.datetime(2016, 2, 7, 5, 11, 17, 0) datet = datetime.datetime(2016, 2, 7, 5, 11, 17, 0)
assert i18n.format_date(format, date=datet) == 'February 07, 2016, 05:11:17 05 AM' assert i18n.format_date(format, date=datet, language='en') == 'February 07, 2016, 05:11:17 05 AM'
format = '%B %-d, %Y, %-H:%-M:%-S %-I %p' format = '%B %-d, %Y, %-H:%-M:%-S %-I %p'
assert i18n.format_date(format, date=datet) == 'February 7, 2016, 5:11:17 5 AM' assert i18n.format_date(format, date=datet, language='en') == 'February 7, 2016, 5:11:17 5 AM'
format = '%x' format = '%x'
assert i18n.format_date(format, date=datet) == 'Feb 7, 2016' assert i18n.format_date(format, date=datet, language='en') == 'Feb 7, 2016'
format = '%X' format = '%X'
assert i18n.format_date(format, date=datet) == '5:11:17 AM' assert i18n.format_date(format, date=datet, language='en') == '5:11:17 AM'
assert i18n.format_date(format, date=date) == 'Feb 7, 2016' assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
format = '%c' format = '%c'
assert i18n.format_date(format, date=datet) == 'Feb 7, 2016, 5:11:17 AM' assert i18n.format_date(format, date=datet, language='en') == 'Feb 7, 2016, 5:11:17 AM'
assert i18n.format_date(format, date=date) == 'Feb 7, 2016' assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
# timezone # timezone
format = '%Z' format = '%Z'
assert i18n.format_date(format, date=datet) == 'UTC' assert i18n.format_date(format, date=datet, language='en') == 'UTC'
format = '%z' format = '%z'
assert i18n.format_date(format, date=datet) == '+0000' assert i18n.format_date(format, date=datet, language='en') == '+0000'
@pytest.mark.xfail(os.name != 'posix', reason="Path separators don't match on windows") @pytest.mark.xfail(os.name != 'posix', reason="Path separators don't match on windows")