# Path: meta_package_manager/labels.py
# MANAGER_LABELS = {}
# 
# MANAGER_PREFIX = "📦 manager: "
# 
# PLATFORM_LABELS = {}
# 
# PLATFORM_PREFIX = "🖥 platform: "
# 
# Path: meta_package_manager/pool.py
# ALL_MANAGER_IDS = tuple(sorted(pool()))
# 
# @cached(LRI(max_size=1))
# def pool():
#     """Search for package manager definitions locally and store them into an
#     internal register.
# 
#     Is considered valid package manager, definitions classes which:
#         1 - are located in the `managers` subfolder, and
#         2 - are sub-classes of PackageManager, and
#         3 - are not virtual (i.e. have a non null `cli_names` property).
#     """
#     register = {}
# 
#     for py_file in Path(__file__).parent.joinpath(MANAGER_SUBFOLDER).glob("*.py"):
#         logger.debug(f"Search manager definitions in {py_file}")
#         module = import_module(
#             f".{MANAGER_SUBFOLDER}.{py_file.stem}", package=__package__
#         )
# 
#         for _, klass in inspect.getmembers(module, inspect.isclass):
#             if issubclass(klass, PackageManager) and not klass.virtual:
#                 logger.debug(f"Found {klass!r}")
#                 manager = klass()
#                 register[manager.id] = manager
#             else:
#                 logger.debug(f"{klass!r} is not a valid manager definition")
# 
#     return register


import json
import re
import tomli
from collections import Counter
from pathlib import Path
from boltons.iterutils import flatten
from click_extra.platform import OS_DEFINITIONS, os_label
from click_extra.tests.conftest import unless_linux
from yaml import Loader, load
from ..labels import MANAGER_LABELS, MANAGER_PREFIX, PLATFORM_LABELS, PLATFORM_PREFIX
from ..pool import ALL_MANAGER_IDS, pool

These tests are mainly there to remind us keep extra stuff in sync on new
platform or manager addition.
"""

PROJECT_ROOT = Path(__file__).parent.parent.parent


def test_project_metadata():
    # Fetch general information about the project from pyproject.toml.
    toml_path = Path(__file__).parent.joinpath("../../pyproject.toml").resolve()
    toml_config = tomli.loads(toml_path.read_text())
    # Check all managers are referenced in Python package keywords.
    assert set(ALL_MANAGER_IDS).issubset(toml_config["tool"]["poetry"]["keywords"])


def test_changelog():
    content = PROJECT_ROOT.joinpath("changelog.md").read_text()

    assert content.startswith("# Changelog\n")

    entry_pattern = re.compile(r"^\* \[(?P<category>[a-z,]+)\] (?P<entry>.+)")
    for line in content.splitlines():
        if line.startswith("*"):
            match = entry_pattern.match(line)
            assert match
            entry = match.groupdict()
            assert entry["category"]
            assert set(entry["category"].split(",")).issubset(
                flatten(

# Path: meta_package_manager/labels.py
# MANAGER_LABELS = {}
# 
# MANAGER_PREFIX = "📦 manager: "
# 
# PLATFORM_LABELS = {}
# 
# PLATFORM_PREFIX = "🖥 platform: "
# 
# Path: meta_package_manager/pool.py
# ALL_MANAGER_IDS = tuple(sorted(pool()))
# 
# @cached(LRI(max_size=1))
# def pool():
#     """Search for package manager definitions locally and store them into an
#     internal register.
# 
#     Is considered valid package manager, definitions classes which:
#         1 - are located in the `managers` subfolder, and
#         2 - are sub-classes of PackageManager, and
#         3 - are not virtual (i.e. have a non null `cli_names` property).
#     """
#     register = {}
# 
#     for py_file in Path(__file__).parent.joinpath(MANAGER_SUBFOLDER).glob("*.py"):
#         logger.debug(f"Search manager definitions in {py_file}")
#         module = import_module(
#             f".{MANAGER_SUBFOLDER}.{py_file.stem}", package=__package__
#         )
# 
#         for _, klass in inspect.getmembers(module, inspect.isclass):
#             if issubclass(klass, PackageManager) and not klass.virtual:
#                 logger.debug(f"Found {klass!r}")
#                 manager = klass()
#                 register[manager.id] = manager
#             else:
#                 logger.debug(f"{klass!r} is not a valid manager definition")
# 
#     return register


# Path: meta_package_manager/tests/test_docs.py
import json
import re
import tomli
from collections import Counter
from pathlib import Path
from boltons.iterutils import flatten
from click_extra.platform import OS_DEFINITIONS, os_label
from click_extra.tests.conftest import unless_linux
from yaml import Loader, load
from ..labels import MANAGER_LABELS, MANAGER_PREFIX, PLATFORM_LABELS, PLATFORM_PREFIX
from ..pool import ALL_MANAGER_IDS, pool


These tests are mainly there to remind us keep extra stuff in sync on new
platform or manager addition.
"""

PROJECT_ROOT = Path(__file__).parent.parent.parent


def test_project_metadata():
    # Fetch general information about the project from pyproject.toml.
    toml_path = Path(__file__).parent.joinpath("../../pyproject.toml").resolve()
    toml_config = tomli.loads(toml_path.read_text())
    # Check all managers are referenced in Python package keywords.
    assert set(ALL_MANAGER_IDS).issubset(toml_config["tool"]["poetry"]["keywords"])


def test_changelog():
    content = PROJECT_ROOT.joinpath("changelog.md").read_text()

    assert content.startswith("# Changelog\n")

    entry_pattern = re.compile(r"^\* \[(?P<category>[a-z,]+)\] (?P<entry>.+)")
    for line in content.splitlines():
        if line.startswith("*"):
            match = entry_pattern.match(line)
            assert match
            entry = match.groupdict()
            assert entry["category"]
            assert set(entry["category"].split(",")).issubset(
                flatten(

                    (ALL_MANAGER_IDS, OS_DEFINITIONS.keys(), "mpm", "bitbar", "xbar")