Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
18 changes: 18 additions & 0 deletions tests/acceptance/test_hook_file_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
import ruamel.yaml
from identify.identify import tags_from_filename

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

Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
Loading