diff options
Diffstat (limited to 'tests/test_config.py')
-rw-r--r-- | tests/test_config.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 0dcf3fa3..e48079e3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -9,7 +9,7 @@ :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from six import PY3 +from six import PY2, PY3, StringIO from util import TestApp, with_app, with_tempdir, raises, raises_msg @@ -133,3 +133,41 @@ def test_config_eol(tmpdir): cfg = Config(tmpdir, 'conf.py', {}, None) cfg.init_values(lambda warning: 1/0) assert cfg.project == u'spam' + + +TYPECHECK_OVERRIDES = [ + # configuration key, override value, should warn, default type + ('master_doc', 123, True, str), + ('man_pages', 123, True, list), # lambda + ('man_pages', [], False, list), + ('epub_tocdepth', True, True, int), # child type + ('nitpicky', 3, False, bool), # parent type + ('templates_path', (), True, list), # other sequence, also raises +] +if PY2: + # Run a check for proper sibling detection in Python 2. Under py3k, the + # default types do not have any siblings. + TYPECHECK_OVERRIDES.append( + ('html_add_permalinks', 'bar', False, unicode)) + +def test_gen_check_types(): + for key, value, should, deftype in TYPECHECK_OVERRIDES: + warning = StringIO() + try: + app = TestApp(confoverrides={key: value}, warning=warning) + except: + pass + else: + app.cleanup() + + real = type(value).__name__ + msg = ("WARNING: the config value %r has type `%s'," + " defaults to `%s.'\n" % (key, real, deftype.__name__)) + def test(): + assert (msg in warning.buflist) == should, \ + "Setting %s to %r should%s raise: %s" % \ + (key, value, " not" if should else "", msg) + test.description = "test_check_type_%s_on_%s" % \ + (real, type(Config.config_values[key][0]).__name__) + + yield test |