mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add warning
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import re
|
||||
import traceback
|
||||
import types
|
||||
import warnings
|
||||
from collections import OrderedDict
|
||||
from os import getenv, path
|
||||
from typing import (TYPE_CHECKING, Any, Callable, Dict, Generator, Iterator, List, NamedTuple,
|
||||
@@ -168,6 +169,9 @@ class Config:
|
||||
# explicitly sets language to None, by coercing it to English.
|
||||
if namespace.get("language", ...) is None:
|
||||
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 {})
|
||||
|
||||
|
||||
@@ -397,6 +397,22 @@ def test_conf_py_language_none(tempdir):
|
||||
assert cfg.language == "en"
|
||||
|
||||
|
||||
def test_conf_py_language_none_warning(tempdir):
|
||||
"""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)
|
||||
|
||||
|
||||
def test_conf_py_no_language(tempdir):
|
||||
"""Regression test for #10474."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user