summaryrefslogtreecommitdiffstats
path: root/tests/clientlib_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-04 03:57:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-04 03:57:49 +0000
commitd6cacb1f6ae346ce54a5116d76a7d087bb6381a5 (patch)
treefdb6f1b1b847180a234439c3f39ce5d93da8e84e /tests/clientlib_test.py
parentAdding upstream version 2.15.0. (diff)
downloadpre-commit-d6cacb1f6ae346ce54a5116d76a7d087bb6381a5.tar.xz
pre-commit-d6cacb1f6ae346ce54a5116d76a7d087bb6381a5.zip
Adding upstream version 2.16.0.upstream/2.16.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/clientlib_test.py')
-rw-r--r--tests/clientlib_test.py64
1 files changed, 45 insertions, 19 deletions
diff --git a/tests/clientlib_test.py b/tests/clientlib_test.py
index da794e6..5427b1d 100644
--- a/tests/clientlib_test.py
+++ b/tests/clientlib_test.py
@@ -247,38 +247,64 @@ def test_warn_mutable_rev_conditional():
cfgv.validate(config_obj, CONFIG_REPO_DICT)
-def test_validate_optional_sensible_regex_at_hook_level(caplog):
+@pytest.mark.parametrize(
+ ('regex', 'warning'),
+ (
+ (
+ r'dir/*.py',
+ "The 'files' field in hook 'flake8' is a regex, not a glob -- "
+ "matching '/*' probably isn't what you want here",
+ ),
+ (
+ r'dir[\/].*\.py',
+ r"pre-commit normalizes slashes in the 'files' field in hook "
+ r"'flake8' to forward slashes, so you can use / instead of [\/]",
+ ),
+ (
+ r'dir[/\\].*\.py',
+ r"pre-commit normalizes slashes in the 'files' field in hook "
+ r"'flake8' to forward slashes, so you can use / instead of [/\\]",
+ ),
+ ),
+)
+def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning):
config_obj = {
'id': 'flake8',
- 'files': 'dir/*.py',
+ 'files': regex,
}
cfgv.validate(config_obj, CONFIG_HOOK_DICT)
- assert caplog.record_tuples == [
+ assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)]
+
+
+@pytest.mark.parametrize(
+ ('regex', 'warning'),
+ (
(
- 'pre_commit',
- logging.WARNING,
- "The 'files' field in hook 'flake8' is a regex, not a glob -- "
+ r'dir/*.py',
+ "The top-level 'files' field is a regex, not a glob -- "
"matching '/*' probably isn't what you want here",
),
- ]
-
-
-def test_validate_optional_sensible_regex_at_top_level(caplog):
+ (
+ r'dir[\/].*\.py',
+ r"pre-commit normalizes the slashes in the top-level 'files' "
+ r'field to forward slashes, so you can use / instead of [\/]',
+ ),
+ (
+ r'dir[/\\].*\.py',
+ r"pre-commit normalizes the slashes in the top-level 'files' "
+ r'field to forward slashes, so you can use / instead of [/\\]',
+ ),
+ ),
+)
+def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning):
config_obj = {
- 'files': 'dir/*.py',
+ 'files': regex,
'repos': [],
}
cfgv.validate(config_obj, CONFIG_SCHEMA)
- assert caplog.record_tuples == [
- (
- 'pre_commit',
- logging.WARNING,
- "The top-level 'files' field is a regex, not a glob -- matching "
- "'/*' probably isn't what you want here",
- ),
- ]
+ assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)]
@pytest.mark.parametrize('fn', (validate_config_main, validate_manifest_main))