summaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_config.py')
-rw-r--r--tests/test_config.py85
1 files changed, 47 insertions, 38 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index a076636d6..379b59dfc 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -10,19 +10,22 @@
:license: BSD, see LICENSE for details.
"""
from six import PY3, iteritems
+import pytest
import mock
-from util import TestApp, with_app, gen_with_app, with_tempdir, \
- raises, raises_msg, assert_in, assert_not_in
+from util import TestApp, gen_with_app, \
+ assert_in, assert_not_in
import sphinx
from sphinx.config import Config
from sphinx.errors import ExtensionError, ConfigError, VersionRequirementError
-@with_app(confoverrides={'master_doc': 'master', 'nonexisting_value': 'True',
- 'latex_elements.docclass': 'scrartcl',
- 'modindex_common_prefix': 'path1,path2'})
+@pytest.mark.sphinx(confoverrides={
+ 'master_doc': 'master',
+ 'nonexisting_value': 'True',
+ 'latex_elements.docclass': 'scrartcl',
+ 'modindex_common_prefix': 'path1,path2'})
def test_core_config(app, status, warning):
cfg = app.config
@@ -55,11 +58,14 @@ def test_core_config(app, status, warning):
assert 'nonexisting_value' not in cfg
# invalid values
- raises(AttributeError, getattr, cfg, '_value')
- raises(AttributeError, getattr, cfg, 'nonexisting_value')
+ with pytest.raises(AttributeError):
+ getattr(cfg, '_value')
+ with pytest.raises(AttributeError):
+ getattr(cfg, 'nonexisting_value')
# non-value attributes are deleted from the namespace
- raises(AttributeError, getattr, cfg, 'sys')
+ with pytest.raises(AttributeError):
+ getattr(cfg, 'sys')
# setting attributes
cfg.project = 'Foo'
@@ -70,7 +76,7 @@ def test_core_config(app, status, warning):
assert cfg['project'] == cfg.project == 'Sphinx Tests'
-@with_app()
+@pytest.mark.sphinx()
def test_extension_values(app, status, warning):
cfg = app.config
@@ -80,24 +86,27 @@ def test_extension_values(app, status, warning):
assert cfg.value_from_conf_py == 84
# no duplicate values allowed
- raises_msg(ExtensionError, 'already present', app.add_config_value,
- 'html_title', 'x', True)
- raises_msg(ExtensionError, 'already present', app.add_config_value,
- 'value_from_ext', 'x', True)
+ with pytest.raises(ExtensionError) as excinfo:
+ app.add_config_value('html_title', 'x', True)
+ assert 'already present' in str(excinfo.value)
+ with pytest.raises(ExtensionError) as excinfo:
+ app.add_config_value('value_from_ext', 'x', True)
+ assert 'already present' in str(excinfo.value)
-@with_tempdir
@mock.patch("sphinx.config.logger")
-def test_errors_warnings(dir, logger):
+def test_errors_warnings(logger, tempdir):
# test the error for syntax errors in the config file
- (dir / 'conf.py').write_text(u'project = \n', encoding='ascii')
- raises_msg(ConfigError, 'conf.py', Config, dir, 'conf.py', {}, None)
+ (tempdir / 'conf.py').write_text(u'project = \n', encoding='ascii')
+ with pytest.raises(ConfigError) as excinfo:
+ Config(tempdir, 'conf.py', {}, None)
+ assert 'conf.py' in str(excinfo.value)
# test the automatic conversion of 2.x only code in configs
- (dir / 'conf.py').write_text(
+ (tempdir / 'conf.py').write_text(
u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
encoding='utf-8')
- cfg = Config(dir, 'conf.py', {}, None)
+ cfg = Config(tempdir, 'conf.py', {}, None)
cfg.init_values()
assert cfg.project == u'Jägermeister'
assert logger.called is False
@@ -107,20 +116,21 @@ def test_errors_warnings(dir, logger):
# skip the test there
if PY3:
return
- (dir / 'conf.py').write_text(
+ (tempdir / 'conf.py').write_text(
u'# -*- coding: latin-1\nproject = "fooä"\n', encoding='latin-1')
- cfg = Config(dir, 'conf.py', {}, None)
+ cfg = Config(tempdir, 'conf.py', {}, None)
assert logger.warning.called is False
cfg.check_unicode()
assert logger.warning.called is True
-@with_tempdir
-def test_errors_if_setup_is_not_callable(dir):
+def test_errors_if_setup_is_not_callable(tempdir):
# test the error to call setup() in the config file
- (dir / 'conf.py').write_text(u'setup = 1')
- raises_msg(ConfigError, 'callable', TestApp, srcdir=dir)
+ (tempdir / 'conf.py').write_text(u'setup = 1')
+ with pytest.raises(ConfigError) as excinfo:
+ TestApp(srcdir=tempdir)
+ assert 'callable' in str(excinfo.value)
@mock.patch.object(sphinx, '__display_version__', '1.3.4')
@@ -130,40 +140,39 @@ def test_needs_sphinx():
app.cleanup()
app = TestApp(confoverrides={'needs_sphinx': '1.3.4'}) # OK: equals
app.cleanup()
- raises(VersionRequirementError, TestApp,
- confoverrides={'needs_sphinx': '1.3.5'}) # NG: greater
+ with pytest.raises(VersionRequirementError):
+ TestApp(confoverrides={'needs_sphinx': '1.3.5'}) # NG: greater
# minor version
app = TestApp(confoverrides={'needs_sphinx': '1.2'}) # OK: less
app.cleanup()
app = TestApp(confoverrides={'needs_sphinx': '1.3'}) # OK: equals
app.cleanup()
- raises(VersionRequirementError, TestApp,
- confoverrides={'needs_sphinx': '1.4'}) # NG: greater
+ with pytest.raises(VersionRequirementError):
+ TestApp(confoverrides={'needs_sphinx': '1.4'}) # NG: greater
# major version
app = TestApp(confoverrides={'needs_sphinx': '0'}) # OK: less
app.cleanup()
app = TestApp(confoverrides={'needs_sphinx': '1'}) # OK: equals
app.cleanup()
- raises(VersionRequirementError, TestApp,
- confoverrides={'needs_sphinx': '2'}) # NG: greater
+ with pytest.raises(VersionRequirementError):
+ TestApp(confoverrides={'needs_sphinx': '2'}) # NG: greater
-@with_tempdir
@mock.patch("sphinx.config.logger")
-def test_config_eol(tmpdir, logger):
+def test_config_eol(logger, tempdir):
# test config file's eol patterns: LF, CRLF
- configfile = tmpdir / 'conf.py'
+ configfile = tempdir / 'conf.py'
for eol in (b'\n', b'\r\n'):
configfile.write_bytes(b'project = "spam"' + eol)
- cfg = Config(tmpdir, 'conf.py', {}, None)
+ cfg = Config(tempdir, 'conf.py', {}, None)
cfg.init_values()
assert cfg.project == u'spam'
assert logger.called is False
-@with_app(confoverrides={'master_doc': 123,
+@pytest.mark.sphinx(confoverrides={'master_doc': 123,
'language': 'foo',
'primary_domain': None})
def test_builtin_conf(app, status, warning):
@@ -209,13 +218,13 @@ def test_gen_check_types(app, status, warning):
)
-@with_app(testroot='config')
+@pytest.mark.sphinx(testroot='config')
def test_check_enum(app, status, warning):
assert "The config value `value17` has to be a one of ('default', 'one', 'two'), " \
not in warning.getvalue()
-@with_app(testroot='config', confoverrides={'value17': 'invalid'})
+@pytest.mark.sphinx(testroot='config', confoverrides={'value17': 'invalid'})
def test_check_enum_failed(app, status, warning):
assert "The config value `value17` has to be a one of ('default', 'one', 'two'), " \
"but `invalid` is given." in warning.getvalue()