Пример #1
0
def _load_yaml_files():
    global YAML_FILES
    if YAML_FILES is not None:
        return YAML_FILES

    YAML_FILES = defaultdict(dict)
    for owner, directory in directories(owner=True):
        for root, _, files in os.walk(directory):
            for file in [f for f in files if f.endswith(".yaml")]:
                if file in IGNORE:
                    continue
                path = os.path.join(root, file)
                try:
                    with open(path) as f:
                        data = yaml.load(f.read(), Loader=yaml.SafeLoader)
                        name, _ = os.path.splitext(os.path.basename(path))
                        kind = _guess(data, path)
                        collection = YAML_FILES[kind]
                        e = Entry(name, kind, directory, path, data, owner)
                        if name is collection:
                            collection[name].append(e)
                        else:
                            collection[name] = e

                except Exception as e:
                    warnings.warn(
                        f"Cannot process YAML file {path} {owner} ({e})")
                    raise

    return YAML_FILES
Пример #2
0
def _load_yaml_files():
    global YAML_FILES
    if YAML_FILES is not None:
        return YAML_FILES

    YAML_FILES = defaultdict(dict)
    for directory in directories():
        for root, _, files in os.walk(directory):
            for file in [f for f in files if f.endswith(".yaml")]:
                if file in IGNORE:
                    continue
                path = os.path.join(root, file)
                try:
                    with open(path) as f:
                        data = yaml.load(f.read(), Loader=yaml.SafeLoader)
                        name, _ = os.path.splitext(os.path.basename(path))
                        kind = _guess(data, path)
                        collection = YAML_FILES[kind]
                        if name in collection and path != collection[name].path:
                            LOG.warning(
                                "Duplicate entry for %s %s (using %s, ignoring %s)",
                                kind,
                                name,
                                collection[name].path,
                                path,
                            )
                        else:
                            collection[name] = Entry(name, kind, path, data)

                except Exception:
                    LOG.error("Cannot process YAML file %s", path, exc_info=True)
                    raise

    return YAML_FILES
Пример #3
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, )))