示例#1
0
文件: test_config.py 项目: abg/misc
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)
示例#2
0
文件: test_config.py 项目: abg/misc
def test_read():
    from glob import glob

    path = os.path.join(os.path.dirname(__file__), "data", "*.conf")
    specs = os.path.join(os.path.dirname(__file__), "data", "*.spec")
    for name in glob(path):
        Config.read([name])
    for name in glob(specs):
        Config.read([name])
示例#3
0
文件: test_config.py 项目: abg/misc
def test_write():
    path = os.path.join(os.path.dirname(__file__), "data", "mysqldump.conf")
    cfg = Config.read([path])
    dest = tempfile.mkdtemp()
    try:
        cfg.write(os.path.join(dest, "foo.conf"))
        Config.read([os.path.join(dest, "foo.conf")])
    finally:
        shutil.rmtree(dest)
示例#4
0
文件: test_spec.py 项目: abg/misc
def test_validate_missing():
    # run validation against an object with missing
    # values that the spec should provide via default
    # values
    path = os.path.join(os.path.dirname(__file__),
                        'data',
                        'mysqldump.spec')
    cfg = Config()
    assert_false(cfg.keys())
    spec = Configspec.read([path])
    spec.validate(cfg)

    assert_equals(cfg.keys(), spec.keys())
示例#5
0
文件: test_config.py 项目: abg/misc
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())
示例#6
0
文件: test_config.py 项目: abg/misc
def test_str():
    data = dedent(
        """
    [section]
    name = value
    """
    ).lstrip()

    cfg = Config.parse(data.splitlines())
    assert_equals(str(cfg), data)
示例#7
0
文件: test_config.py 项目: abg/misc
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))