Ejemplo n.º 1
0
def test_false(tmpdir, config, value):
    data = """
[foo]
boolean = %s
""" % value
    conf = str(tmpdir.join("conf"))
    with open(conf, "w") as f:
        f.write(data)
    configloader.load(config, [conf])
    assert config.foo.boolean is False
Ejemplo n.º 2
0
def test_empty(tmpdir, config):
    conf = str(tmpdir.join("conf"))
    with open(conf, "w"):
        pass
    configloader.load(config, [conf])
    assert config.foo.string == "old"
    assert config.foo.string_nonascii == "\u05d0"
    assert config.foo.string_null == "\u0000"
    assert config.foo.integer == 1
    assert config.foo.real == 4.0
    assert config.foo.boolean is False
    assert config.bar.string == "old"
Ejemplo n.º 3
0
def test_unicode(tmpdir, config):
    data = """
[foo]
string_nonascii = \u05d0
string_null = \u0000
"""
    conf = str(tmpdir.join("conf"))
    with open(conf, "wb") as f:
        f.write(data.encode("utf-8"))
    configloader.load(config, [conf])
    assert config.foo.string_nonascii == "\u05d0"
    assert config.foo.string_null == "\u0000"
Ejemplo n.º 4
0
def test_some(tmpdir, config):
    data = """
[foo]
string = new
boolean = true
"""
    conf = str(tmpdir.join("conf"))
    with open(conf, "w") as f:
        f.write(data)
    configloader.load(config, [conf])
    assert config.foo.string == "new"
    assert config.foo.integer == 1
    assert config.foo.real == 4.0
    assert config.foo.boolean is True
    assert config.bar.string == "old"
Ejemplo n.º 5
0
def test_ignore_unknown_option(tmpdir, config):
    data = """
[foo]
string = new
unknown = 3
"""
    conf = str(tmpdir.join("conf"))
    with open(conf, "w") as f:
        f.write(data)
    configloader.load(config, [conf])
    assert config.foo.string == "new"
    assert config.foo.integer == 1
    assert config.foo.real == 4.0
    assert config.foo.boolean is False
    assert config.bar.string == "old"
    assert not hasattr(config.foo, "unknown")
Ejemplo n.º 6
0
def test_unsupported_default_value(tmpdir):
    class config:
        class section:
            value = b"bytes"

    data = """
[section]
value = bar
"""
    conf = str(tmpdir.join("conf"))
    with open(conf, "w") as f:
        f.write(data)

    with pytest.raises(ValueError) as e:
        configloader.load(config, [conf])

    error = str(e.value)
    assert "section.value" in error
    assert str(type(config.section.value)) in error
Ejemplo n.º 7
0
def test_full(tmpdir, config):
    data = """
[foo]
string = new
integer = 2
real = 4.1
boolean = true

[bar]
string = new
"""
    conf = str(tmpdir.join("conf"))
    with open(conf, "w") as f:
        f.write(data)
    configloader.load(config, [conf])
    assert config.foo.string == "new"
    assert config.foo.integer == 2
    assert config.foo.real == 4.1
    assert config.foo.boolean is True
    assert config.bar.string == "new"