コード例 #1
0
def test_no_subtree_and_entries_on_same_level():
    catalog = man_pages.load_man_page_catalog()
    for category, entries in catalog.items():
        has_entries = entries != []
        has_categories = man_pages._manpage_catalog_subtree_names(
            catalog, category) != []
        assert has_entries != has_categories, "A category must only have entries or categories, not both"
コード例 #2
0
def _get_check_catalog(only_path):
    def path_prefix_matches(p, op):
        if op and not p:
            return False
        if not op:
            return True
        return p[0] == op[0] and path_prefix_matches(p[1:], op[1:])

    def strip_manpage_entry(entry):
        return {
            k: v
            for k, v in entry.items() if k in ["name", "agents", "title"]
        }

    tree: Dict[str, Any] = {}

    for path, entries in man_pages.load_man_page_catalog().items():
        if not path_prefix_matches(path, only_path):
            continue
        subtree = tree
        for component in path[:-1]:
            subtree = subtree.setdefault(component, {})
        subtree[path[-1]] = list(map(strip_manpage_entry, entries))

    for p in only_path:
        try:
            tree = tree[p]
        except KeyError:
            pass

    return tree
コード例 #3
0
    def _get_check_catalog(self):
        def path_prefix_matches(p, op):
            if op and not p:
                return False
            elif not op:
                return True
            return p[0] == op[0] and path_prefix_matches(p[1:], op[1:])

        def strip_manpage_entry(entry):
            return dict([(k, v) for (k, v) in entry.items()
                         if k in ["name", "agents", "title"]])

        tree = {}
        if len(self._path) > 0:
            only_path = tuple(self._path)
        else:
            only_path = ()

        for path, entries in man_pages.load_man_page_catalog().items():
            if not path_prefix_matches(path, only_path):
                continue
            subtree = tree
            for component in path[:-1]:
                subtree = subtree.setdefault(component, {})
            subtree[path[-1]] = list(map(strip_manpage_entry, entries))

        for p in only_path:
            try:
                tree = tree[p]
            except KeyError:
                pass

        return tree
コード例 #4
0
ファイル: check_catalog.py プロジェクト: LinuxHaus/checkmk
def _get_check_catalog(only_path: tuple[str, ...]) -> Mapping[str, Any]:
    # Note: this is impossible to type, since the type is recursive.
    # The return type `Monster` would be something like
    # Monster = Mapping[str, Union[Sequence[_ManPageSummary], Monster]]

    def path_prefix_matches(p: tuple[str, ...]) -> bool:
        return p[:len(only_path)] == only_path

    tree: dict[str, Any] = {}

    for path, entries in man_pages.load_man_page_catalog().items():
        if not path_prefix_matches(path):
            continue
        subtree = tree
        for component in path[:-1]:
            subtree = subtree.setdefault(component, {})
        subtree[path[-1]] = [{
            "name": e.name,
            "agents": e.agents,
            "title": e.title,
        } for e in entries]

    for p in only_path:
        try:
            tree = tree[p]
        except KeyError:
            break

    return tree
コード例 #5
0
def test_load_man_page_catalog():
    catalog = man_pages.load_man_page_catalog()
    assert type(catalog) == dict

    for path, entries in catalog.items():
        assert type(path) == tuple
        assert type(entries) == list

        # TODO: Test for unknown paths?

        for entry in entries:
            assert type(entry) == dict

            # Test for non fallback man pages
            assert "Cannot parse man page" not in entry["title"]
コード例 #6
0
ファイル: test_man_pages.py プロジェクト: sri-sysad/checkmk
def test_load_man_page_catalog():
    catalog = man_pages.load_man_page_catalog()
    assert isinstance(catalog, dict)

    for path, entries in catalog.items():
        assert isinstance(path, tuple)
        assert isinstance(entries, list)

        # TODO: Test for unknown paths?

        for entry in entries:
            assert isinstance(entry, dict)

            # Test for non fallback man pages
            assert "Cannot parse man page" not in entry["title"]
コード例 #7
0
def test_no_unsorted_man_pages():
    catalog = man_pages.load_man_page_catalog()
    unsorted_page_names = [m["name"] for m in catalog.get(("unsorted", ), [])]

    assert not unsorted_page_names, "Found unsorted man pages: %s" % ", ".join(
        unsorted_page_names)
コード例 #8
0
def _get_catalog():
    return man_pages.load_man_page_catalog()
コード例 #9
0
ファイル: test_man_pages.py プロジェクト: LinuxHaus/checkmk
def get_catalog() -> man_pages.ManPageCatalog:
    return man_pages.load_man_page_catalog()