mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
d98e70c13eff followup: only do type conversion of confoverrides if the values are strings and add a test
This commit is contained in:
parent
1356aff6d7
commit
8fdcb803cf
@ -214,8 +214,11 @@ class Config(object):
|
||||
self.overrides = overrides
|
||||
self.values = Config.config_values.copy()
|
||||
config = {}
|
||||
if "extensions" in overrides:
|
||||
config["extensions"] = overrides["extensions"]
|
||||
if 'extensions' in overrides:
|
||||
if isinstance(overrides['extensions'], (str, unicode)):
|
||||
config['extensions'] = overrides.pop('extensions').split(',')
|
||||
else:
|
||||
config['extensions'] = overrides.pop('extensions')
|
||||
if dirname is not None:
|
||||
config_file = path.join(dirname, filename)
|
||||
config['__file__'] = config_file
|
||||
@ -259,22 +262,25 @@ class Config(object):
|
||||
warn('unknown config value %r in override, ignoring' % valname)
|
||||
continue
|
||||
defvalue = self.values[valname][0]
|
||||
if isinstance(defvalue, dict):
|
||||
warn('cannot override dictionary config setting %r, '
|
||||
'ignoring (use %r to set individual elements)' %
|
||||
(valname, valname + '.key=value'))
|
||||
continue
|
||||
elif isinstance(defvalue, list):
|
||||
config[valname] = value.split(',')
|
||||
elif isinstance(defvalue, (int, long)):
|
||||
try:
|
||||
config[valname] = int(value)
|
||||
except ValueError:
|
||||
warn('invalid number %r for config value %r, ignoring'
|
||||
% (value, valname))
|
||||
elif not isinstance(defvalue, (str, unicode)):
|
||||
warn('cannot override config setting %r with unsupported type, '
|
||||
'ignoring' % valname)
|
||||
if isinstance(value, (str, unicode)):
|
||||
if isinstance(defvalue, dict):
|
||||
warn('cannot override dictionary config setting %r, '
|
||||
'ignoring (use %r to set individual elements)' %
|
||||
(valname, valname + '.key=value'))
|
||||
continue
|
||||
elif isinstance(defvalue, list):
|
||||
config[valname] = value.split(',')
|
||||
elif isinstance(defvalue, (int, long)):
|
||||
try:
|
||||
config[valname] = int(value)
|
||||
except ValueError:
|
||||
warn('invalid number %r for config value %r, ignoring'
|
||||
% (value, valname))
|
||||
elif defvalue is not None and not isinstance(defvalue, (str, unicode)):
|
||||
warn('cannot override config setting %r with unsupported type, '
|
||||
'ignoring' % valname)
|
||||
else:
|
||||
config[valname] = value
|
||||
else:
|
||||
config[valname] = value
|
||||
for name in config:
|
||||
|
@ -19,7 +19,8 @@ from sphinx.util.pycompat import b
|
||||
|
||||
|
||||
@with_app(confoverrides={'master_doc': 'master', 'nonexisting_value': 'True',
|
||||
'latex_elements.docclass': 'scrartcl'})
|
||||
'latex_elements.docclass': 'scrartcl',
|
||||
'modindex_common_prefix': 'path1,path2'})
|
||||
def test_core_config(app):
|
||||
cfg = app.config
|
||||
|
||||
@ -31,6 +32,7 @@ def test_core_config(app):
|
||||
# overrides
|
||||
assert cfg.master_doc == 'master'
|
||||
assert cfg.latex_elements['docclass'] == 'scrartcl'
|
||||
assert cfg.modindex_common_prefix == ['path1', 'path2']
|
||||
|
||||
# simple default values
|
||||
assert 'locale_dirs' not in cfg.__dict__
|
||||
@ -92,7 +94,7 @@ def test_errors_warnings(dir):
|
||||
write_file(dir / 'conf.py', u'# -*- coding: utf-8\n\n'
|
||||
u'project = u"Jägermeister"\n', 'utf-8')
|
||||
cfg = Config(dir, 'conf.py', {}, None)
|
||||
cfg.init_values()
|
||||
cfg.init_values(lambda warning: 1/0)
|
||||
assert cfg.project == u'Jägermeister'
|
||||
|
||||
# test the warning for bytestrings with non-ascii content
|
||||
@ -122,5 +124,5 @@ def test_config_eol(tmpdir):
|
||||
for eol in ('\n', '\r\n'):
|
||||
configfile.write_bytes(b('project = "spam"' + eol))
|
||||
cfg = Config(tmpdir, 'conf.py', {}, None)
|
||||
cfg.init_values()
|
||||
cfg.init_values(lambda warning: 1/0)
|
||||
assert cfg.project == u'spam'
|
||||
|
@ -81,7 +81,7 @@ def test_read_inventory_v2():
|
||||
'/util/glossary.html#term-a-term'
|
||||
|
||||
|
||||
@with_app(confoverrides={'extensions': 'sphinx.ext.intersphinx'})
|
||||
@with_app()
|
||||
@with_tempdir
|
||||
def test_missing_reference(tempdir, app):
|
||||
inv_file = tempdir / 'inventory'
|
||||
@ -157,7 +157,7 @@ def test_missing_reference(tempdir, app):
|
||||
assert contnode[0].astext() == 'py3k:unknown'
|
||||
|
||||
|
||||
@with_app(confoverrides={'extensions': 'sphinx.ext.intersphinx'})
|
||||
@with_app()
|
||||
@with_tempdir
|
||||
def test_load_mappings_warnings(tempdir, app):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user