예제 #1
0
def test_subconfig_invalid(config_data):
    config_data["subconfigs"]["a"]["str_field"] = 42
    lookup = Lookup(config_data)

    with pytest.raises(ConfigError,
                       match=r"subconfigs/a/str_field must be a string"):
        for name, sublookup in lookup.iterate_objects("subconfigs"):
            SubConfig(sublookup)
예제 #2
0
def test_basic(config_data):
    lookup = Lookup(config_data)
    config = Config(lookup)

    config.subconfigs = {}
    for name, sublookup in lookup.iterate_objects("subconfigs"):
        config.subconfigs[name] = SubConfig(sublookup)

    assert config.str_field == "foo"
    assert config.int_field == 42
    assert config.bool_field is False
    assert config.str_list_field == ["foo", "bar", "baz"]
    assert config.str_dict_field == {"foo": "bar", "baz": "wow"}
    assert config.timedelta_field.total_seconds() == 42
    assert config.subconfig.str_field == "baz"
    assert config.subconfigs["a"].str_field == "a"
예제 #3
0
def test_iterate_objects_none():
    lookup = Lookup({})
    result = [x for x in lookup.iterate_objects("not_there")]
    assert result == []