mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor: Add Config.read() as a constructor
To simplify Config.__init__() method, this separates conf.py parsing feature to Config.read() method. This allows to instantiate config object simply.
This commit is contained in:
@@ -96,14 +96,14 @@ def test_errors_warnings(logger, tempdir):
|
||||
# test the error for syntax errors in the config file
|
||||
(tempdir / 'conf.py').write_text(u'project = \n', encoding='ascii')
|
||||
with pytest.raises(ConfigError) as excinfo:
|
||||
Config(tempdir, 'conf.py', {}, None)
|
||||
Config.read(tempdir, 'conf.py', {}, None)
|
||||
assert 'conf.py' in str(excinfo.value)
|
||||
|
||||
# test the automatic conversion of 2.x only code in configs
|
||||
(tempdir / 'conf.py').write_text(
|
||||
u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
|
||||
encoding='utf-8')
|
||||
cfg = Config(tempdir, 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir, 'conf.py', {}, None)
|
||||
cfg.init_values()
|
||||
assert cfg.project == u'Jägermeister'
|
||||
assert logger.called is False
|
||||
@@ -115,7 +115,7 @@ def test_errors_warnings(logger, tempdir):
|
||||
return
|
||||
(tempdir / 'conf.py').write_text(
|
||||
u'# -*- coding: latin-1\nproject = "fooä"\n', encoding='latin-1')
|
||||
cfg = Config(tempdir, 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir, 'conf.py', {}, None)
|
||||
|
||||
assert logger.warning.called is False
|
||||
cfg.check_unicode()
|
||||
@@ -174,7 +174,7 @@ def test_config_eol(logger, tempdir):
|
||||
configfile = tempdir / 'conf.py'
|
||||
for eol in (b'\n', b'\r\n'):
|
||||
configfile.write_bytes(b'project = "spam"' + eol)
|
||||
cfg = Config(tempdir, 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir, 'conf.py', {}, None)
|
||||
cfg.init_values()
|
||||
assert cfg.project == u'spam'
|
||||
assert logger.called is False
|
||||
|
||||
Reference in New Issue
Block a user