|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import os.path |
| 4 | +import re |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from pre_commit_hooks.check_yaml import yaml |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture(scope='module') |
| 12 | +def hook_re(): |
| 13 | + here = os.path.dirname(__file__) |
| 14 | + with open(os.path.join(here, '..', '.pre-commit-hooks.yaml')) as f: |
| 15 | + hook_defs = yaml.load(f) |
| 16 | + hook, = ( |
| 17 | + hook |
| 18 | + for hook in hook_defs |
| 19 | + if hook['id'] == 'check-illegal-windows-names' |
| 20 | + ) |
| 21 | + yield re.compile(hook['files']) |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize( |
| 25 | + 's', |
| 26 | + ( |
| 27 | + pytest.param('aux.txt', id='with ext'), |
| 28 | + pytest.param('aux', id='without ext'), |
| 29 | + pytest.param('AuX.tXt', id='capitals'), |
| 30 | + pytest.param('com7.dat', id='com with digit'), |
| 31 | + ), |
| 32 | +) |
| 33 | +def test_check_illegal_windows_names_matches(hook_re, s): |
| 34 | + assert hook_re.search(s) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.parametrize( |
| 38 | + 's', |
| 39 | + ( |
| 40 | + pytest.param('README.md', id='standard file'), |
| 41 | + pytest.param('foo.aux', id='as ext'), |
| 42 | + pytest.param('com.dat', id='com without digit'), |
| 43 | + ), |
| 44 | +) |
| 45 | +def test_check_illegal_windows_names_does_not_match(hook_re, s): |
| 46 | + assert hook_re.search(s) is None |
0 commit comments