Update warning, revert my original warning patch

This commit is contained in:
Adam Turner
2022-05-28 19:17:46 +01:00
parent fb6db30c10
commit 479e48266c
2 changed files with 16 additions and 17 deletions

View File

@@ -165,18 +165,15 @@ class Config:
confdir)
namespace = eval_config_file(filename, tags)
# Note: Old sphinx projects has been configured as "langugae = None" because
# sphinx-quickstart had generated the configuration by default formerly.
# Note: Old sphinx projects have been configured as "langugae = None" because
# sphinx-quickstart previously generated this by default.
# To keep compatibility, they should be fallback to 'en' for a while
# (At least 2 years or more since v5.0 release).
# (This conversion should not be removed before 2025-01-01).
if namespace.get("language", ...) is None:
logging.warning(__("Invalid configuration found: 'language = None'. "
"Now it takes only a string. Please update your configuration. "
"Fallback to 'en' (English)."))
logger.warning(__("Invalid configuration value found: 'language = None'. "
"Update your configuration to a valid langauge code. "
"Falling back to 'en' (English)."))
namespace["language"] = "en"
warnings.warn("'None' is not a valid value for 'language', coercing to 'en'. "
"Update 'conf.py' to a valid language code to silence this "
"warning.", RuntimeWarning, stacklevel=4)
return cls(namespace, overrides or {})

View File

@@ -397,21 +397,23 @@ def test_conf_py_language_none(tempdir):
assert cfg.language == "en"
def test_conf_py_language_none_warning(tempdir):
def test_conf_py_language_none_warning(tempdir, caplog):
"""Regression test for #10474."""
# Given a conf.py file with language = None
(tempdir / 'conf.py').write_text("language = None", encoding='utf-8')
# Then a warning is raised
with pytest.warns(
RuntimeWarning,
match="'None' is not a valid value for 'language', coercing to 'en'. "
"Update 'conf.py' to a valid language code to silence this "
"warning."):
# When we load conf.py into a Config object
Config.read(tempdir, {}, None)
# Then a warning is raised
assert len(caplog.messages) == 1
assert caplog.messages[0] == (
"Invalid configuration value found: 'language = None'. "
"Update your configuration to a valid langauge code. "
"Falling back to 'en' (English).")
assert caplog.records[0].levelname == "WARNING"
def test_conf_py_no_language(tempdir):
"""Regression test for #10474."""