예제 #1
0
파일: test_config.py 프로젝트: Basis/sphinx
def test_errors_warnings(dir):
    # 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)

    # test the automatic conversion of 2.x only code in configs
    (dir / 'conf.py').write_text(
        u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
        encoding='utf-8')
    cfg = Config(dir, 'conf.py', {}, None)
    cfg.init_values(lambda warning: 1/0)
    assert cfg.project == u'Jägermeister'

    # test the warning for bytestrings with non-ascii content
    # bytestrings with non-ascii content are a syntax error in python3 so we
    # skip the test there
    if PY3:
        return
    (dir / 'conf.py').write_text(
        u'# -*- coding: latin-1\nproject = "fooä"\n', encoding='latin-1')
    cfg = Config(dir, 'conf.py', {}, None)
    warned = [False]
    def warn(msg):
        warned[0] = True
    cfg.check_unicode(warn)
    assert warned[0]
예제 #2
0
def test_errors_warnings(dir):
    # 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)

    # test the automatic conversion of 2.x only code in configs
    (dir / 'conf.py').write_text(
        u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
        encoding='utf-8')
    cfg = Config(dir, 'conf.py', {}, None)
    cfg.init_values(lambda warning: 1 / 0)
    assert cfg.project == u'Jägermeister'

    # test the warning for bytestrings with non-ascii content
    # bytestrings with non-ascii content are a syntax error in python3 so we
    # skip the test there
    if PY3:
        return
    (dir / 'conf.py').write_text(u'# -*- coding: latin-1\nproject = "fooä"\n',
                                 encoding='latin-1')
    cfg = Config(dir, 'conf.py', {}, None)
    warned = [False]

    def warn(msg):
        warned[0] = True

    cfg.check_unicode(warn)
    assert warned[0]
예제 #3
0
def test_errors_warnings(dir):
    # test the error for syntax errors in the config file
    write_file(dir / "conf.py", u"project = \n", "ascii")
    raises_msg(ConfigError, "conf.py", Config, dir, "conf.py", {}, None)

    # test the automatic conversion of 2.x only code in configs
    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()
    assert cfg.project == u"Jägermeister"

    # test the warning for bytestrings with non-ascii content
    # bytestrings with non-ascii content are a syntax error in python3 so we
    # skip the test there
    if sys.version_info >= (3, 0):
        return
    write_file(dir / "conf.py", u'# -*- coding: latin-1\nproject = "fooä"\n', "latin-1")
    cfg = Config(dir, "conf.py", {}, None)
    warned = [False]

    def warn(msg):
        warned[0] = True

    cfg.check_unicode(warn)
    assert warned[0]
예제 #4
0
def test_extension_values(app):
    cfg = app.config

    # default value
    assert cfg.value_from_ext == []
    # non-default value
    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)
예제 #5
0
def test_extension_values(app, status, warning):
    cfg = app.config

    # default value
    assert cfg.value_from_ext == []
    # non-default value
    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)
예제 #6
0
파일: test_config.py 프로젝트: Basis/sphinx
def test_extension_values(app, status, warning):
    cfg = app.config

    # default value
    assert cfg.value_from_ext == []
    # non-default value
    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)
예제 #7
0
def test_domain_override(app, status, warning):
    class A(Domain):
        name = 'foo'

    class B(A):
        name = 'foo'

    class C(Domain):
        name = 'foo'

    # No domain know named foo.
    raises_msg(ExtensionError, 'domain foo not yet registered',
               app.override_domain, A)
    assert app.add_domain(A) is None
    assert app.override_domain(B) is None
    raises_msg(ExtensionError, 'new domain not a subclass of registered '
               'foo domain', app.override_domain, C)
예제 #8
0
def test_domain_override(app, status, warning):
    class A(Domain):
        name = 'foo'

    class B(A):
        name = 'foo'

    class C(Domain):
        name = 'foo'

    # No domain know named foo.
    raises_msg(ExtensionError, 'domain foo not yet registered',
               app.override_domain, A)
    assert app.add_domain(A) is None
    assert app.override_domain(B) is None
    raises_msg(ExtensionError, 'new domain not a subclass of registered '
               'foo domain', app.override_domain, C)
예제 #9
0
def test_domain_override():
    class A(Domain):
        name = 'foo'
    class B(A):
        name = 'foo'
    class C(Domain):
        name = 'foo'
    status, warnings = StringIO(), StringIO()
    app = TestApp(status=status, warning=warnings)
    try:
        # No domain know named foo.
        raises_msg(ExtensionError, 'domain foo not yet registered',
                   app.override_domain, A)
        assert app.add_domain(A) is None
        assert app.override_domain(B) is None
        raises_msg(ExtensionError, 'new domain not a subclass of registered '
                   'foo domain', app.override_domain, C)
    finally:
        app.cleanup()
예제 #10
0
def test_events(app):
    def empty():
        pass

    raises_msg(ExtensionError, "Unknown event name: invalid", app.connect, "invalid", empty)

    app.add_event("my_event")
    raises_msg(ExtensionError, "Event 'my_event' already present", app.add_event, "my_event")

    def mock_callback(a_app, *args):
        assert a_app is app
        assert emit_args == args
        return "ret"

    emit_args = (1, 3, "string")
    listener_id = app.connect("my_event", mock_callback)
    assert app.emit("my_event", *emit_args) == ["ret"], "Callback not called"

    app.disconnect(listener_id)
    assert app.emit("my_event", *emit_args) == [], "Callback called when disconnected"
예제 #11
0
def test_events(app):
    def empty(): pass
    raises_msg(ExtensionError, "Unknown event name: invalid",
               app.connect, "invalid", empty)


    app.add_event("my_event")
    raises_msg(ExtensionError, "Event 'my_event' already present",
               app.add_event, "my_event")

    def mock_callback(a_app, *args):
        assert a_app is app
        assert emit_args == args
        return "ret"
    emit_args = (1, 3, "string")
    listener_id = app.connect("my_event", mock_callback)
    assert app.emit("my_event", *emit_args) == ["ret"], "Callback not called"

    app.disconnect(listener_id)
    assert app.emit("my_event", *emit_args) == [], \
        "Callback called when disconnected"
예제 #12
0
def test_errors_if_setup_is_not_callable(dir):
    # 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)
예제 #13
0
파일: test_config.py 프로젝트: Basis/sphinx
def test_errors_if_setup_is_not_callable(dir):
    # 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)