From bdf036d51666a79b0de40a9b06fdfe4687e59660 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 25 Nov 2022 13:11:59 +0300 Subject: [PATCH] check_consistent.py: Add check ensuring packages are not installed for unspecified platforms (#9265) --- tests/check_consistent.py | 19 +++++++++++++++++-- tests/get_packages.py | 7 +++---- tests/utils.py | 3 +++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 2b70c9e2a..1b3cca2eb 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -15,7 +15,14 @@ import yaml from packaging.requirements import Requirement from packaging.specifiers import SpecifierSet from packaging.version import Version -from utils import VERSIONS_RE, get_all_testcase_directories, get_gitignore_spec, spec_matches_path, strip_comments +from utils import ( + METADATA_MAPPING, + VERSIONS_RE, + get_all_testcase_directories, + get_gitignore_spec, + spec_matches_path, + strip_comments, +) metadata_keys = { "version", @@ -182,11 +189,19 @@ def check_metadata() -> None: for key in data.get("tool", {}).get(tool, {}): assert key in tk, f"Unrecognised {tool} key {key} for {distribution}" - specified_stubtest_platforms = set(data.get("tool", {}).get("stubtest", {}).get("platforms", [])) + tool_stubtest = data.get("tool", {}).get("stubtest", {}) + specified_stubtest_platforms = set(tool_stubtest.get("platforms", [])) assert ( specified_stubtest_platforms <= supported_stubtest_platforms ), f"Unrecognised platforms specified: {supported_stubtest_platforms - specified_stubtest_platforms}" + # Check that only specified platforms install packages: + for supported_plat in supported_stubtest_platforms: + if supported_plat not in specified_stubtest_platforms: + assert ( + METADATA_MAPPING[supported_plat] not in tool_stubtest + ), f"Installing system deps for unspecified platform {supported_plat} for {distribution}" + def get_txt_requirements() -> dict[str, SpecifierSet]: with open("requirements-tests.txt", encoding="UTF-8") as requirements_file: diff --git a/tests/get_packages.py b/tests/get_packages.py index b21f6b0fd..bae75ac0b 100755 --- a/tests/get_packages.py +++ b/tests/get_packages.py @@ -3,16 +3,15 @@ import os import sys import tomli +from utils import METADATA_MAPPING platform = sys.platform distributions = sys.argv[1:] if not distributions: distributions = os.listdir("stubs") -metadata_mapping = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} - -if platform in metadata_mapping: +if platform in METADATA_MAPPING: for distribution in distributions: with open(f"stubs/{distribution}/METADATA.toml", "rb") as file: - for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(metadata_mapping[platform], []): + for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(METADATA_MAPPING[platform], []): print(package) diff --git a/tests/utils.py b/tests/utils.py index 97e6f09a3..5c8c9aec5 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -12,6 +12,9 @@ from typing import NamedTuple import pathspec # type: ignore[import] import tomli +# Used to install system-wide packages for different OS types: +METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} + def strip_comments(text: str) -> str: return text.split("#")[0].strip()