コード例 #1
0
ファイル: test_config.py プロジェクト: yufeizhu600/donfig
def test_merge():
    a = {'x': 1, 'y': {'a': 1}}
    b = {'x': 2, 'z': 3, 'y': {'b': 2}}

    expected = {'x': 2, 'y': {'a': 1, 'b': 2}, 'z': 3}

    c = merge(a, b)
    assert c == expected
コード例 #2
0
ファイル: test_config.py プロジェクト: yufeizhu600/donfig
def test_merge_none_to_dict():
    assert merge({
        'a': None,
        'c': 0
    }, {'a': {
        'b': 1
    }}) == {
        'a': {
            'b': 1
        },
        'c': 0
    }
コード例 #3
0
ファイル: test_config.py プロジェクト: yufeizhu600/donfig
def test_collect_yaml_dir():
    a = {'x': 1, 'y': {'a': 1}}
    b = {'x': 2, 'z': 3, 'y': {'b': 2}}

    expected = {
        'x': 2,
        'y': {
            'a': 1,
            'b': 2
        },
        'z': 3,
    }

    with tmpfile() as dirname:
        os.mkdir(dirname)
        with open(os.path.join(dirname, 'a.yaml'), mode='w') as f:
            yaml.dump(a, f)
        with open(os.path.join(dirname, 'b.yaml'), mode='w') as f:
            yaml.dump(b, f)

        config = merge(*collect_yaml(paths=[dirname]))
        assert config == expected
コード例 #4
0
ファイル: test_config.py プロジェクト: yufeizhu600/donfig
def test_collect_yaml_paths():
    a = {'x': 1, 'y': {'a': 1}}
    b = {'x': 2, 'z': 3, 'y': {'b': 2}}

    expected = {
        'x': 2,
        'y': {
            'a': 1,
            'b': 2
        },
        'z': 3,
    }

    with tmpfile(extension='yaml') as fn1:
        with tmpfile(extension='yaml') as fn2:
            with open(fn1, 'w') as f:
                yaml.dump(a, f)
            with open(fn2, 'w') as f:
                yaml.dump(b, f)

            config = merge(*collect_yaml(paths=[fn1, fn2]))
            assert config == expected
コード例 #5
0
ファイル: test_config.py プロジェクト: yufeizhu600/donfig
def test_collect_yaml_permission_errors(tmpdir, kind):
    a = {'x': 1, 'y': 2}
    b = {'y': 3, 'z': 4}

    dir_path = str(tmpdir)
    a_path = os.path.join(dir_path, 'a.yaml')
    b_path = os.path.join(dir_path, 'b.yaml')

    with open(a_path, mode='w') as f:
        yaml.dump(a, f)
    with open(b_path, mode='w') as f:
        yaml.dump(b, f)

    if kind == 'directory':
        cant_read = dir_path
        expected = {}
    else:
        cant_read = a_path
        expected = b

    with no_read_permissions(cant_read):
        config = merge(*collect_yaml(paths=[dir_path]))
        assert config == expected