Source code for meta_package_manager.tests.test_docs
# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.## This program is Free Software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.from__future__importannotationsimportjsonimportreimportsysfromcollectionsimportCounterfrompathlibimportPathfromboltons.iterutilsimportflattenfromyamlimportLoader,loadifsys.version_info>=(3,11):importtomllibelse:importtomliastomllib# type: ignore[import-not-found]frommeta_package_manager.labelsimportMANAGER_PREFIX,PLATFORM_PREFIXfrommeta_package_manager.platformsimportPLATFORM_GROUPS,encoding_argsfrommeta_package_manager.poolimportpool""" Test all non-code artifacts depending on manager definitions.Covers: * Documentation (sphinx, readme, etc.) * CI/CD scripts * GitHub project configThese tests are mainly there to remind us keep extra stuff in sync on newplatform or manager addition."""PROJECT_ROOT=Path(__file__).parent.parent.parent
[docs]deftest_project_metadata():# Fetch general information about the project from pyproject.toml.toml_path=PROJECT_ROOT.joinpath("pyproject.toml").resolve()toml_config=tomllib.loads(toml_path.read_text(**encoding_args))# Check all managers are referenced in Python package keywords.assertset(pool.all_manager_ids).issubset(toml_config["tool"]["poetry"]["keywords"])
[docs]deftest_new_package_manager_issue_template():"""Check all platforms groups are referenced in the issue template."""content=PROJECT_ROOT.joinpath(".github/ISSUE_TEMPLATE/new-package-manager.yaml",).read_text(**encoding_args)assertcontenttemplate_platforms=load(content,Loader=Loader)["body"][3]["attributes"]["options"]reference_labels=[]forgroupinPLATFORM_GROUPS:label=f"{group.icon}{group.name}"iflen(group)>1:label+=f" ({', '.join(p.nameforpingroup.platforms)})"reference_labels.append({"label":label})asserttemplate_platforms==reference_labels
[docs]deftest_labeller_rules():# Extract list of extra labels.content=PROJECT_ROOT.joinpath(".github/labels-extra.json").read_text(**encoding_args,)assertcontentextra_labels=[lbl["name"]forlblinjson.loads(content)]assertextra_labels# Canonical labels are uniques.assertlen(extra_labels)==len(set(extra_labels))canonical_labels=set(extra_labels)assertcanonical_labels# Extract and categorize labels.canonical_managers={lblforlblincanonical_labelsiflbl.startswith(MANAGER_PREFIX)and"mpm"notinlbl}assertcanonical_managerscanonical_platforms={lblforlblincanonical_labelsiflbl.startswith(PLATFORM_PREFIX)}assertcanonical_platforms# Extract rules from json blurb serialized into YAML.content=PROJECT_ROOT.joinpath(".github/workflows/labeller-content-based.yaml",).read_text(**encoding_args)assert"kdeldycke/workflows/.github/workflows/labeller-file-based.yaml"incontentextra_rules=load(content,Loader=Loader)["jobs"]["labeller"]["with"]["extra-rules"]rules=load(extra_rules,Loader=Loader)assertrules# Each keyword match one rule only.rules_keywords=Counter(flatten(rules.values()))assertrules_keywordsassertmax(rules_keywords.values())==1# Check that all canonical labels are referenced in rules.assert(canonical_labels-{"π¦ manager: mpm"}).issubset(rules.keys())