-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsync_pre_commit_deps_test.py
More file actions
240 lines (226 loc) · 7.71 KB
/
sync_pre_commit_deps_test.py
File metadata and controls
240 lines (226 loc) · 7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
from __future__ import annotations
import pytest
from sync_pre_commit_deps import main
@pytest.mark.parametrize(
('s',),
(
pytest.param(
'repos:\n'
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - id: black\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
' - black==23.3.0\n',
id='already correct version',
),
pytest.param(
'repos:\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
' - black==23.3.0\n',
id='no hook to get the version from',
),
pytest.param(
'repos:\n'
'- repo: https://github.com/PyCQA/flake8\n'
' rev: 6.0.0\n'
' hooks:\n'
' - id: flake8\n'
' additional_dependencies:\n'
' - flake-bugbear==3.1.0\n',
id='dep not supported',
),
pytest.param(
'repos:\n'
'- repo: local\n'
' hooks:\n'
' - id: mypy\n'
'- repo: https://github.com/nbQA-dev/nbQA\n'
' rev: 1.9.1\n'
' hooks:\n'
' - id: nbqa-mypy\n'
' additional_dependencies:\n'
' - mypy==0.123\n',
id='local hook shadows supported lib',
),
pytest.param(
'repos:\n'
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - name: \N{SNOWMAN} black\n'
' id: black\n',
id='unicode no-op',
),
),
)
def test_main_noop(tmpdir, s):
cfg = tmpdir.join('.pre-commit-config.yaml')
cfg.write_binary(s.encode())
assert not main((str(cfg),))
with open(cfg, encoding='utf-8') as f:
assert f.read() == s
def test_main_writes_all(tmpdir):
cfg = tmpdir.join('.pre-commit-config.yaml')
cfg.write(
'repos:\n'
# should not be touched
'- repo: https://github.com/asottile/pyupgrade\n'
' rev: v3.8.0\n'
' hooks:\n'
' - id: pyupgrade\n'
# gives the `black` version
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - id: black\n'
# gives the `flake8` version
'- repo: https://github.com/PyCQA/flake8\n'
' rev: 6.0.0\n'
' hooks:\n'
' - id: flake8\n'
# gives the `mypy` version
'- repo: https://github.com/pre-commit/mirrors-mypy\n'
' rev: v1.13.0\n'
' hooks:\n'
' - id: mypy\n'
# all repos below should have their additional_dependencies rewritten
'- repo: https://github.com/asottile/yesqa\n'
' rev: v1.5.0\n'
' hooks:\n'
' - id: yesqa\n'
' additional_dependencies:\n'
' - flake8==5.0.0\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
' - black==22.12.0\n'
'- repo: https://github.com/nbQA-dev/nbQA\n'
' rev: 1.9.1\n'
' hooks:\n'
' - id: nbqa-mypy\n'
' additional_dependencies:\n'
' - mypy==0.910\n'
'- repo: https://github.com/example/example\n'
' rev: v1.0.0\n'
' hooks:\n'
' - id: example\n'
' additional_dependencies:\n'
' - black==22.12.0\n'
' - flake8==5.0.0\n'
' - mypy==0.123\n',
)
assert main((str(cfg),))
assert cfg.read() == (
'repos:\n'
'- repo: https://github.com/asottile/pyupgrade\n'
' rev: v3.8.0\n'
' hooks:\n'
' - id: pyupgrade\n'
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - id: black\n'
'- repo: https://github.com/PyCQA/flake8\n'
' rev: 6.0.0\n'
' hooks:\n'
' - id: flake8\n'
'- repo: https://github.com/pre-commit/mirrors-mypy\n'
' rev: v1.13.0\n'
' hooks:\n'
' - id: mypy\n'
'- repo: https://github.com/asottile/yesqa\n'
' rev: v1.5.0\n'
' hooks:\n'
' - id: yesqa\n'
' additional_dependencies:\n'
' - flake8==6.0.0\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
' - black==23.3.0\n'
'- repo: https://github.com/nbQA-dev/nbQA\n'
' rev: 1.9.1\n'
' hooks:\n'
' - id: nbqa-mypy\n'
' additional_dependencies:\n'
' - mypy==1.13.0\n'
'- repo: https://github.com/example/example\n'
' rev: v1.0.0\n'
' hooks:\n'
' - id: example\n'
' additional_dependencies:\n'
' - black==23.3.0\n'
' - flake8==6.0.0\n'
' - mypy==1.13.0\n'
)
def test_main_no_dep_on_one_and_writes_other(tmpdir):
cfg = tmpdir.join('.pre-commit-config.yaml')
cfg.write(
'repos:\n'
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - id: black\n'
'- repo: https://github.com/asottile/yesqa\n'
' rev: v1.5.0\n'
' hooks:\n'
' - id: yesqa\n'
' additional_dependencies:\n'
# should not be rewritten because target versions can't be found
' - flake8==5.0.0\n'
' - mypy==0.910\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
# should be rewritten
' - black==22.12.0\n'
'- repo: https://github.com/nbQA-dev/nbQA\n'
' rev: 1.9.1\n'
' hooks:\n'
' - id: nbqa-mypy\n'
' additional_dependencies:\n'
# should not be rewritten because target version can't be found
' - mypy==0.123',
)
assert main((str(cfg),))
assert cfg.read() == (
'repos:\n'
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - id: black\n'
'- repo: https://github.com/asottile/yesqa\n'
' rev: v1.5.0\n'
' hooks:\n'
' - id: yesqa\n'
' additional_dependencies:\n'
' - flake8==5.0.0\n'
' - mypy==0.910\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
' - black==23.3.0\n'
'- repo: https://github.com/nbQA-dev/nbQA\n'
' rev: 1.9.1\n'
' hooks:\n'
' - id: nbqa-mypy\n'
' additional_dependencies:\n'
' - mypy==0.123\n'
)