|
7 | 7 | from pre_commit.clientlib.validate_config import InvalidConfigError |
8 | 8 | from pre_commit.clientlib.validate_config import run |
9 | 9 | from pre_commit.clientlib.validate_config import validate_config_extra |
| 10 | +from pre_commit.jsonschema_extensions import apply_defaults |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def test_returns_0_for_valid_config(): |
@@ -78,28 +79,50 @@ def test_is_valid_according_to_schema(manifest_obj, expected): |
78 | 79 | def test_config_with_failing_regexes_fails(): |
79 | 80 | with pytest.raises(InvalidConfigError): |
80 | 81 | # Note the regex '(' is invalid (unbalanced parens) |
81 | | - validate_config_extra([{ |
82 | | - 'repo': 'foo', 'hooks': [{'id': 'hook_id', 'files': '('}] |
83 | | - }]) |
| 82 | + config = apply_defaults( |
| 83 | + [{ |
| 84 | + 'repo': 'foo', |
| 85 | + 'sha': 'foo', |
| 86 | + 'hooks': [{'id': 'hook_id', 'files': '('}], |
| 87 | + }], |
| 88 | + CONFIG_JSON_SCHEMA, |
| 89 | + ) |
| 90 | + validate_config_extra(config) |
84 | 91 |
|
85 | 92 |
|
86 | 93 | def test_config_with_ok_regexes_passes(): |
87 | | - validate_config_extra([{ |
88 | | - 'repo': 'foo', 'hooks': [{'id': 'hook_id', 'files': '\.py$'}], |
89 | | - }]) |
| 94 | + config = apply_defaults( |
| 95 | + [{ |
| 96 | + 'repo': 'foo', |
| 97 | + 'sha': 'foo', |
| 98 | + 'hooks': [{'id': 'hook_id', 'files': '\.py$'}], |
| 99 | + }], |
| 100 | + CONFIG_JSON_SCHEMA, |
| 101 | + ) |
| 102 | + validate_config_extra(config) |
90 | 103 |
|
91 | 104 |
|
92 | 105 | def test_config_with_invalid_exclude_regex_fails(): |
93 | 106 | with pytest.raises(InvalidConfigError): |
94 | | - # NOte the regex '(' is invalid (unbalanced parens) |
95 | | - validate_config_extra([{ |
96 | | - 'repo': 'foo', |
97 | | - 'hooks': [{'id': 'hook_id', 'files': '', 'exclude': '('}], |
98 | | - }]) |
| 107 | + # Note the regex '(' is invalid (unbalanced parens) |
| 108 | + config = apply_defaults( |
| 109 | + [{ |
| 110 | + 'repo': 'foo', |
| 111 | + 'sha': 'foo', |
| 112 | + 'hooks': [{'id': 'hook_id', 'files': '', 'exclude': '('}], |
| 113 | + }], |
| 114 | + CONFIG_JSON_SCHEMA, |
| 115 | + ) |
| 116 | + validate_config_extra(config) |
99 | 117 |
|
100 | 118 |
|
101 | 119 | def test_config_with_ok_exclude_regex_passes(): |
102 | | - validate_config_extra([{ |
103 | | - 'repo': 'foo', |
104 | | - 'hooks': [{'id': 'hook_id', 'files': '', 'exclude': '^vendor/'}], |
105 | | - }]) |
| 120 | + config = apply_defaults( |
| 121 | + [{ |
| 122 | + 'repo': 'foo', |
| 123 | + 'sha': 'foo', |
| 124 | + 'hooks': [{'id': 'hook_id', 'files': '', 'exclude': '^vendor/'}], |
| 125 | + }], |
| 126 | + CONFIG_JSON_SCHEMA, |
| 127 | + ) |
| 128 | + validate_config_extra(config) |
0 commit comments