Skip to content

Commit 7689a14

Browse files
authored
Merge pull request #544 from edgarrmondragon/test-good-types-types_or
Test expected positive `types` and `types_or` matches
2 parents b6230f5 + 641cfbf commit 7689a14

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dev = [
3737
"pytest<9",
3838
'click-type-test==1.1.0;python_version>="3.10"',
3939
"coverage<8",
40+
"identify>=2.6.9",
4041
"pytest-xdist<4",
4142
"responses==0.25.6",
4243
]

tests/acceptance/test_hook_file_matches.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77
import ruamel.yaml
8+
from identify.identify import tags_from_filename
89

910
yaml = ruamel.yaml.YAML(typ="safe")
1011

@@ -29,6 +30,22 @@ def check_pattern_match(
2930
pytest.fail(f"'{pattern}' matched '{value}' (expected no match)")
3031

3132

33+
def check_types_match(
34+
types: list[str],
35+
types_or: list[str],
36+
path: str,
37+
) -> None:
38+
__tracebackhide__ = True
39+
40+
tags = tags_from_filename(path)
41+
42+
if types and not tags.issuperset(types):
43+
pytest.fail(f"types={types} did not match '{path}' (expected match)")
44+
45+
if types_or and not tags.intersection(types_or):
46+
pytest.fail(f"types_or={types_or} did not match '{path}' (expected match)")
47+
48+
3249
def get_hook_config(hookid):
3350
config_file = HERE.parent.parent / ".pre-commit-hooks.yaml"
3451
with open(config_file) as fp:
@@ -182,6 +199,7 @@ def get_hook_config(hookid):
182199
def test_hook_matches_known_good_paths(hookid, filepath):
183200
config = get_hook_config(hookid)
184201
check_pattern_match(config["files"], filepath)
202+
check_types_match(config.get("types", []), config.get("types_or", []), filepath)
185203

186204

187205
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)