From b20b0772b77d901d81ef4fce09a6b65b4b0fbdec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Tue, 25 Mar 2025 20:33:17 -0600 Subject: [PATCH 1/2] Test expected positive `types` and `types_or` matches --- pyproject.toml | 1 + tests/acceptance/test_hook_file_matches.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 85ba2a611..deb45caa5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ dev = [ "pytest<9", 'click-type-test==1.1.0;python_version>="3.10"', "coverage<8", + "identify>=2.6.9", "pytest-xdist<4", "responses==0.25.6", ] diff --git a/tests/acceptance/test_hook_file_matches.py b/tests/acceptance/test_hook_file_matches.py index b48f6dfca..83030c27c 100644 --- a/tests/acceptance/test_hook_file_matches.py +++ b/tests/acceptance/test_hook_file_matches.py @@ -3,6 +3,7 @@ import pathlib import re +from identify.identify import tags_from_filename import pytest import ruamel.yaml @@ -29,6 +30,22 @@ def check_pattern_match( pytest.fail(f"'{pattern}' matched '{value}' (expected no match)") +def check_types_match( + types: list[str], + types_or: list[str], + path: str, +) -> None: + __tracebackhide__ = True + + tags = tags_from_filename(path) + + if types and not tags.issuperset(types): + pytest.fail(f"types={types} did not match '{path}' (expected match)") + + if types_or and not tags.intersection(types_or): + pytest.fail(f"types_or={types_or} did not match '{path}' (expected match)") + + def get_hook_config(hookid): config_file = HERE.parent.parent / ".pre-commit-hooks.yaml" with open(config_file) as fp: @@ -182,6 +199,7 @@ def get_hook_config(hookid): def test_hook_matches_known_good_paths(hookid, filepath): config = get_hook_config(hookid) check_pattern_match(config["files"], filepath) + check_types_match(config.get("types", []), config.get("types_or", []), filepath) @pytest.mark.parametrize( From 641cfbf0d192a4e4f78f681a0301885fc2680afa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Mar 2025 02:34:10 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/acceptance/test_hook_file_matches.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/test_hook_file_matches.py b/tests/acceptance/test_hook_file_matches.py index 83030c27c..918ed315b 100644 --- a/tests/acceptance/test_hook_file_matches.py +++ b/tests/acceptance/test_hook_file_matches.py @@ -3,9 +3,9 @@ import pathlib import re -from identify.identify import tags_from_filename import pytest import ruamel.yaml +from identify.identify import tags_from_filename yaml = ruamel.yaml.YAML(typ="safe")