Пример #1
0
def test_iterate_flattened_separately():
    d = {'a1': 1,
         'b2': {'foo': 'bar'},
         'c1': 'f',
         'd1': [1, 2, 3],
         'e2': {}}
    res = list(iterate_flattened_separately(d))
    assert res == [('a1', 1), ('c1', 'f'), ('d1', [1, 2, 3]), ('e2', {}),
                   ('b2', PATHCHANGE), ('b2.foo', 'bar')]
Пример #2
0
def test_iterate_flattened_separately():
    d = {'a1': 1,
         'b2': {'bar': 'foo', 'foo': 'bar'},
         'c1': 'f',
         'd1': [1, 2, 3],
         'e2': {}}
    res = list(iterate_flattened_separately(d, ['foo', 'bar']))
    assert res == [('a1', 1), ('c1', 'f'), ('d1', [1, 2, 3]), ('e2', {}),
                   ('b2', PATHCHANGE), ('b2.foo', 'bar'), ('b2.bar', 'foo')]
Пример #3
0
def iterate_marked(cfg, config_mods):
    for path, value in iterate_flattened_separately(cfg):
        if value is PATHCHANGE:
            yield path, PathEntry(
                key=path.rpartition('.')[2],
                added=path in config_mods.added,
                modified=path in config_mods.modified,
                typechanged=config_mods.typechanged.get(path))
        else:
            yield path, ConfigEntry(
                key=path.rpartition('.')[2],
                value=value,
                added=path in config_mods.added,
                modified=path in config_mods.modified,
                typechanged=config_mods.typechanged.get(path))
Пример #4
0
def iterate_marked(cfg, config_mods):
    for path, value in iterate_flattened_separately(cfg):
        if value is PATHCHANGE:
            yield path, PathEntry(
                key=path.rpartition('.')[2],
                added=path in config_mods.added,
                modified=path in config_mods.modified,
                typechanged=config_mods.typechanged.get(path))
        else:
            yield path, ConfigEntry(
                key=path.rpartition('.')[2],
                value=value,
                added=path in config_mods.added,
                modified=path in config_mods.modified,
                typechanged=config_mods.typechanged.get(path))
Пример #5
0
def test_iterate_flattened_separately():
    d = {
        "a1": 1,
        "b2": {"bar": "foo", "foo": "bar"},
        "c1": "f",
        "d1": [1, 2, 3],
        "e2": {},
    }
    res = list(iterate_flattened_separately(d, ["foo", "bar"]))
    assert res == [
        ("a1", 1),
        ("c1", "f"),
        ("d1", [1, 2, 3]),
        ("e2", {}),
        ("b2", PATHCHANGE),
        ("b2.foo", "bar"),
        ("b2.bar", "foo"),
    ]