Beispiel #1
0
def test_meld():
    input1 = dedent(
        """
    [section1]
    key1 = value1
    key2 = value2
    """
    )
    input2 = dedent(
        """
    [section1]
    key1 = XXX
    key3 = value3

    [section2]
    key1 = value1
    """
    )
    expected = {
        "section1": {"key1": "XXX", "key2": "value2", "key3": "value3"},  # cfg2 overwrites  # cfg2 contributes
        "section2": {"key1": "value1"},  # cfg2 contributes
    }
    cfg1 = Config.parse(input1.splitlines())
    cfg2 = Config.parse(input2.splitlines())
    cfg1.merge(cfg2)
    assert_equals(cfg1, expected)
Beispiel #2
0
def test_write_fileobj():
    input1 = dedent(
        """
    [section1]
    key1 = value1
    key2 = value2
    """
    )
    output = StringIO()
    cfg = Config.parse(input1.splitlines())
    cfg.write(output)
    print output.getvalue()
    Config.parse(output.getvalue().splitlines())
Beispiel #3
0
def test_str():
    data = dedent(
        """
    [section]
    name = value
    """
    ).lstrip()

    cfg = Config.parse(data.splitlines())
    assert_equals(str(cfg), data)
Beispiel #4
0
def test_basic():
    data = dedent(
        """
    [section]
    name = value
    """
    ).splitlines()

    cfg = Config.parse(data)
    assert_equals(len(cfg), 1)
    assert_equals(cfg["section"], {"name": "value"})
    assert_equals(cfg["section"]["name"], "value")
    assert_true(isinstance(cfg, dict))