Esempio n. 1
0
def check_user_defined_objects(collection, setting, obj, tree, get_list,
                               get_entry):

    # Clear cache
    clear_cache()

    paths = settings.get(setting)
    assert isinstance(paths, (list, tuple)), paths
    assert len(paths) > 0

    for i, path in enumerate(paths):

        name = "pytest-%s-%s" % (tree[1], i)

        if os.path.exists(path) and os.path.isdir(path):
            assert path in directories(), directories()

        if not os.path.exists(path):
            os.mkdir(path)

        with open(os.path.join(path, "%s.yaml" % (name, )), "w") as f:
            a = obj
            for t in tree[:-1]:
                a = a[t]
            a[tree[-1]] = i
            yaml.dump(obj, f, default_flow_style=False)

    for i in range(len(paths)):
        name = "pytest-%s-%s" % (tree[1], i)
        get_data_entry(collection, name)
        assert name in get_list()
        p = get_entry(name).data

        a = p
        for t in tree:
            a = a[t]

        assert a == i

    # TODO: Move to tear-down
    for i, path in enumerate(paths):
        name = "pytest-%s-%s" % (tree[1], i)
        os.unlink(os.path.join(path, "%s.yaml" % (name, )))
Esempio n. 2
0
def _apply_string(*, value, collection, action, default, target, options):

    # TODO: Consider `value` being a URL (yaml or json)

    data = get_data_entry(collection, value).data

    options.update_if_not_set(**data.get("plot_map", {}))

    magics = data["magics"]
    actions = list(magics.keys())
    if len(actions) != 1:
        raise ValueError(
            "%s %s: one, and only one magics action can be defined in a yaml file: %r"
            % (collection, value, actions))

    name = actions[0]
    action = lookup(name)
    kwargs = magics[name]
    return action(**kwargs)
Esempio n. 3
0
def style(name):
    return get_data_entry("styles", name)
Esempio n. 4
0
def layer(name):
    return get_data_entry("layers", name)
Esempio n. 5
0
def projection(name):
    return get_data_entry("projections", name)
Esempio n. 6
0
})


def _update_areas(old, new, prefix=""):
    for name, values in new.items():
        name = prefix + name
        assert name not in old, f"{name} already defined."
        if len(values) > 1:
            LOG.debug(
                f"Area {name} has multiple values {values}. Not supported by CliMetLab."
            )
            continue
        old[name] = values[0]


data = get_data_entry("domains", "verification").data
_update_areas(areas, data["areas"], prefix="verification.")

AREAS = {k: tuple(v) for k, v in areas.items()}
AREAS_LONG_NAMES = {
    "verification." + k: v
    for k, v in data["areas_long_names"].items()
}


def domain_to_area(name):
    if isinstance(name, (list, tuple)):
        return name
    return AREAS[name.lower()]