1
|
|
|
# pylint: disable=redefined-outer-name,unused-argument,unused-variable,singleton-comparison,expression-not-assigned |
|
|
|
|
2
|
|
|
|
3
|
|
|
import os |
4
|
|
|
import shutil |
5
|
|
|
from contextlib import suppress |
6
|
|
|
import logging |
7
|
|
|
|
8
|
|
|
import pytest |
9
|
|
|
from expecter import expect |
|
|
|
|
10
|
|
|
from freezegun import freeze_time |
|
|
|
|
11
|
|
|
|
12
|
|
|
import gitman |
13
|
|
|
from gitman import shell |
14
|
|
|
from gitman.models import Config |
15
|
|
|
from gitman.exceptions import UncommittedChanges, InvalidRepository |
16
|
|
|
|
17
|
|
|
from .utilities import strip |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tmp') |
21
|
|
|
|
22
|
|
|
CONFIG = """ |
23
|
|
|
location: deps |
24
|
|
|
sources: |
25
|
|
|
- name: gitman_1 |
26
|
|
|
link: '' |
27
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
28
|
|
|
rev: example-branch |
29
|
|
|
- name: gitman_2 |
30
|
|
|
link: '' |
31
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
32
|
|
|
rev: example-tag |
33
|
|
|
- name: gitman_3 |
34
|
|
|
link: '' |
35
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
36
|
|
|
rev: 9bf18e16b956041f0267c21baad555a23237b52e |
37
|
|
|
""".lstrip() |
38
|
|
|
|
39
|
|
|
log = logging.getLogger(__name__) |
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
@pytest.fixture |
43
|
|
|
def config(): |
|
|
|
|
44
|
|
|
log.info("Temporary directory: %s", ROOT) |
45
|
|
|
|
46
|
|
|
with suppress(FileNotFoundError, PermissionError): |
47
|
|
|
shutil.rmtree(ROOT) |
48
|
|
|
with suppress(FileExistsError): |
49
|
|
|
os.makedirs(ROOT) |
50
|
|
|
os.chdir(ROOT) |
51
|
|
|
|
52
|
|
|
os.system("touch .git") |
53
|
|
|
config = Config(root=ROOT) |
54
|
|
|
config.__mapper__.text = CONFIG |
|
|
|
|
55
|
|
|
|
56
|
|
|
log.debug("File listing: %s", os.listdir(ROOT)) |
57
|
|
|
|
58
|
|
|
return config |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
def describe_install(): |
|
|
|
|
62
|
|
|
|
63
|
|
|
def it_creates_missing_directories(config): |
|
|
|
|
64
|
|
|
shell.rm(config.location) |
65
|
|
|
|
66
|
|
|
expect(gitman.install('gitman_1', depth=1)) == True |
67
|
|
|
|
68
|
|
|
expect(os.listdir(config.location)) == ['gitman_1'] |
69
|
|
|
|
70
|
|
|
def it_should_not_modify_config(config): |
|
|
|
|
71
|
|
|
expect(gitman.install('gitman_1', depth=1)) == True |
72
|
|
|
|
73
|
|
|
expect(config.__mapper__.text) == CONFIG |
74
|
|
|
|
75
|
|
|
def it_merges_sources(config): |
|
|
|
|
76
|
|
|
config.__mapper__.text = strip(""" |
77
|
|
|
location: deps |
78
|
|
|
sources: |
79
|
|
|
- name: gitman_1 |
80
|
|
|
link: '' |
81
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
82
|
|
|
rev: example-branch |
83
|
|
|
sources_locked: |
84
|
|
|
- name: gitman_2 |
85
|
|
|
link: '' |
86
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
87
|
|
|
rev: example-branch |
88
|
|
|
- name: gitman_3 |
89
|
|
|
link: '' |
90
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
91
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
92
|
|
|
""") |
93
|
|
|
|
94
|
|
|
expect(gitman.install(depth=1)) == True |
95
|
|
|
|
96
|
|
|
expect(len(os.listdir(config.location))) == 3 |
97
|
|
|
|
98
|
|
|
def it_can_handle_missing_locked_sources(config): |
|
|
|
|
99
|
|
|
config.__mapper__.text = strip(""" |
100
|
|
|
location: deps |
101
|
|
|
sources: |
102
|
|
|
- name: gitman_1 |
103
|
|
|
link: '' |
104
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
105
|
|
|
rev: example-branch |
106
|
|
|
sources_locked: |
107
|
|
|
- name: gitman_2 |
108
|
|
|
link: '' |
109
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
110
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
111
|
|
|
""") |
112
|
|
|
|
113
|
|
|
expect(gitman.install('gitman_1', depth=1)) == True |
114
|
|
|
|
115
|
|
|
expect(os.listdir(config.location)) == ['gitman_1'] |
116
|
|
|
|
117
|
|
|
def it_detects_invalid_repositories(config): |
|
|
|
|
118
|
|
|
shell.rm(os.path.join("deps", "gitman_1", ".git")) |
119
|
|
|
shell.mkdir(os.path.join("deps", "gitman_1", ".git")) |
120
|
|
|
|
121
|
|
|
try: |
122
|
|
|
with pytest.raises(InvalidRepository): |
123
|
|
|
expect(gitman.install('gitman_1', depth=1)) == False |
124
|
|
|
|
125
|
|
|
finally: |
126
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
127
|
|
|
|
128
|
|
|
def describe_links(): |
|
|
|
|
129
|
|
|
|
130
|
|
|
@pytest.fixture |
131
|
|
|
def config_with_link(config): |
|
|
|
|
132
|
|
|
config.__mapper__.text = strip(""" |
133
|
|
|
location: deps |
134
|
|
|
sources: |
135
|
|
|
- name: gitman_1 |
136
|
|
|
link: my_link |
137
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
138
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
139
|
|
|
""") |
140
|
|
|
|
141
|
|
|
return config |
142
|
|
|
|
143
|
|
|
@pytest.mark.xfail(os.name == 'nt', reason="No symlinks on Windows") |
144
|
|
|
def it_should_create_links(config_with_link): |
|
|
|
|
145
|
|
|
expect(gitman.install(depth=1)) == True |
146
|
|
|
|
147
|
|
|
expect(os.listdir()).contains('my_link') |
148
|
|
|
|
149
|
|
|
@pytest.mark.xfail(os.name == 'nt', reason="No symlinks on Windows") |
150
|
|
|
def it_should_not_overwrite_files(config_with_link): |
|
|
|
|
151
|
|
|
os.system("touch my_link") |
152
|
|
|
|
153
|
|
|
with pytest.raises(RuntimeError): |
154
|
|
|
gitman.install(depth=1) |
155
|
|
|
|
156
|
|
|
@pytest.mark.xfail(os.name == 'nt', reason="No symlinks on Windows") |
157
|
|
|
def it_overwrites_files_with_force(config_with_link): |
|
|
|
|
158
|
|
|
os.system("touch my_link") |
159
|
|
|
|
160
|
|
|
expect(gitman.install(depth=1, force=True)) == True |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
def describe_uninstall(): |
|
|
|
|
164
|
|
|
|
165
|
|
|
def it_deletes_dependencies_when_they_exist(config): |
|
|
|
|
166
|
|
|
gitman.install('gitman_1', depth=1) |
167
|
|
|
expect(os.path.isdir(config.location)) == True |
168
|
|
|
|
169
|
|
|
expect(gitman.uninstall()) == True |
170
|
|
|
|
171
|
|
|
expect(os.path.exists(config.location)) == False |
172
|
|
|
|
173
|
|
|
def it_should_not_fail_when_no_dependnecies_exist(config): |
|
|
|
|
174
|
|
|
expect(os.path.isdir(config.location)) == False |
175
|
|
|
|
176
|
|
|
expect(gitman.uninstall()) == True |
177
|
|
|
|
178
|
|
|
def it_deletes_the_log_file(config): |
|
|
|
|
179
|
|
|
gitman.install('gitman_1', depth=1) |
180
|
|
|
gitman.list() |
181
|
|
|
expect(os.path.exists(config.log_path)) == True |
182
|
|
|
|
183
|
|
|
gitman.uninstall() |
184
|
|
|
expect(os.path.exists(config.log_path)) == False |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
def describe_update(): |
|
|
|
|
188
|
|
|
|
189
|
|
|
def it_should_not_modify_config(config): |
|
|
|
|
190
|
|
|
gitman.update('gitman_1', depth=1) |
191
|
|
|
|
192
|
|
|
expect(config.__mapper__.text) == CONFIG |
193
|
|
|
|
194
|
|
|
def it_locks_previously_locked_dependnecies(config): |
|
|
|
|
195
|
|
|
config.__mapper__.text = strip(""" |
196
|
|
|
location: deps |
197
|
|
|
sources: |
198
|
|
|
- name: gitman_1 |
199
|
|
|
link: '' |
200
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
201
|
|
|
rev: example-branch |
202
|
|
|
- name: gitman_2 |
203
|
|
|
link: '' |
204
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
205
|
|
|
rev: example-tag |
206
|
|
|
sources_locked: |
207
|
|
|
- name: gitman_2 |
208
|
|
|
link: '' |
209
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
210
|
|
|
rev: (old revision) |
211
|
|
|
""") |
212
|
|
|
|
213
|
|
|
gitman.update(depth=1) |
214
|
|
|
|
215
|
|
|
expect(config.__mapper__.text) == strip(""" |
216
|
|
|
location: deps |
217
|
|
|
sources: |
218
|
|
|
- name: gitman_1 |
219
|
|
|
link: '' |
220
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
221
|
|
|
rev: example-branch |
222
|
|
|
- name: gitman_2 |
223
|
|
|
link: '' |
224
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
225
|
|
|
rev: example-tag |
226
|
|
|
sources_locked: |
227
|
|
|
- name: gitman_2 |
228
|
|
|
link: '' |
229
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
230
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
231
|
|
|
""") |
232
|
|
|
|
233
|
|
|
def it_should_not_lock_dependnecies_when_disabled(config): |
|
|
|
|
234
|
|
|
config.__mapper__.text = strip(""" |
235
|
|
|
location: deps |
236
|
|
|
sources: |
237
|
|
|
- name: gitman_1 |
238
|
|
|
link: '' |
239
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
240
|
|
|
rev: example-branch |
241
|
|
|
- name: gitman_2 |
242
|
|
|
link: '' |
243
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
244
|
|
|
rev: example-tag |
245
|
|
|
sources_locked: |
246
|
|
|
- name: gitman_2 |
247
|
|
|
link: '' |
248
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
249
|
|
|
rev: (old revision) |
250
|
|
|
""") |
251
|
|
|
|
252
|
|
|
gitman.update(depth=1, lock=False) |
253
|
|
|
|
254
|
|
|
expect(config.__mapper__.text) == strip(""" |
255
|
|
|
location: deps |
256
|
|
|
sources: |
257
|
|
|
- name: gitman_1 |
258
|
|
|
link: '' |
259
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
260
|
|
|
rev: example-branch |
261
|
|
|
- name: gitman_2 |
262
|
|
|
link: '' |
263
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
264
|
|
|
rev: example-tag |
265
|
|
|
sources_locked: |
266
|
|
|
- name: gitman_2 |
267
|
|
|
link: '' |
268
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
269
|
|
|
rev: (old revision) |
270
|
|
|
""") |
271
|
|
|
|
272
|
|
|
def it_should_lock_all_dependencies_when_enabled(config): |
|
|
|
|
273
|
|
|
gitman.update(depth=1, lock=True) |
274
|
|
|
|
275
|
|
|
expect(config.__mapper__.text) == CONFIG + strip(""" |
276
|
|
|
sources_locked: |
277
|
|
|
- name: gitman_1 |
278
|
|
|
link: '' |
279
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
280
|
|
|
rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
281
|
|
|
- name: gitman_2 |
282
|
|
|
link: '' |
283
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
284
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
285
|
|
|
- name: gitman_3 |
286
|
|
|
link: '' |
287
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
288
|
|
|
rev: 9bf18e16b956041f0267c21baad555a23237b52e |
289
|
|
|
""") |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
def describe_list(): |
|
|
|
|
293
|
|
|
|
294
|
|
|
@freeze_time("2012-01-14 12:00:01") |
295
|
|
|
def it_updates_the_log(config): |
|
|
|
|
296
|
|
|
gitman.install() |
297
|
|
|
gitman.list() |
298
|
|
|
|
299
|
|
|
with open(config.log_path) as stream: |
300
|
|
|
contents = stream.read().replace(ROOT, "tmp").replace('\\', '/') |
301
|
|
|
expect(contents) == strip(""" |
302
|
|
|
2012-01-14 12:00:01 |
303
|
|
|
tmp/deps/gitman_1: https://github.com/jacebrowning/gitman-demo @ 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
304
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ 050290bca3f14e13fd616604202b579853e7bfb0 |
305
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ fb693447579235391a45ca170959b5583c5042d8 |
306
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5 |
307
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5 |
308
|
|
|
tmp/deps/gitman_2: https://github.com/jacebrowning/gitman-demo @ 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
309
|
|
|
tmp/deps/gitman_3: https://github.com/jacebrowning/gitman-demo @ 9bf18e16b956041f0267c21baad555a23237b52e |
310
|
|
|
""", end='\n\n') |
311
|
|
|
|
312
|
|
|
|
313
|
|
|
def describe_lock(): |
|
|
|
|
314
|
|
|
|
315
|
|
|
def it_records_all_versions_when_no_arguments(config): |
|
|
|
|
316
|
|
|
expect(gitman.update(depth=1, lock=False)) == True |
317
|
|
|
expect(gitman.lock()) == True |
318
|
|
|
|
319
|
|
|
expect(config.__mapper__.text) == CONFIG + strip(""" |
320
|
|
|
sources_locked: |
321
|
|
|
- name: gitman_1 |
322
|
|
|
link: '' |
323
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
324
|
|
|
rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
325
|
|
|
- name: gitman_2 |
326
|
|
|
link: '' |
327
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
328
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
329
|
|
|
- name: gitman_3 |
330
|
|
|
link: '' |
331
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
332
|
|
|
rev: 9bf18e16b956041f0267c21baad555a23237b52e |
333
|
|
|
""") == config.__mapper__.text |
334
|
|
|
|
335
|
|
|
def it_records_specified_dependencies(config): |
|
|
|
|
336
|
|
|
expect(gitman.update(depth=1, lock=False)) == True |
337
|
|
|
expect(gitman.lock('gitman_1', 'gitman_3')) == True |
338
|
|
|
|
339
|
|
|
expect(config.__mapper__.text) == CONFIG + strip(""" |
340
|
|
|
sources_locked: |
341
|
|
|
- name: gitman_1 |
342
|
|
|
link: '' |
343
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
344
|
|
|
rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
345
|
|
|
- name: gitman_3 |
346
|
|
|
link: '' |
347
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
348
|
|
|
rev: 9bf18e16b956041f0267c21baad555a23237b52e |
349
|
|
|
""") == config.__mapper__.text |
350
|
|
|
|
351
|
|
|
def it_should_fail_on_dirty_repositories(config): |
|
|
|
|
352
|
|
|
expect(gitman.update(depth=1, lock=False)) == True |
353
|
|
|
shell.rm(os.path.join("deps", "gitman_1", ".project")) |
354
|
|
|
|
355
|
|
|
try: |
356
|
|
|
with pytest.raises(UncommittedChanges): |
357
|
|
|
gitman.lock() |
358
|
|
|
|
359
|
|
|
expect(config.__mapper__.text).does_not_contain("<dirty>") |
360
|
|
|
|
361
|
|
|
finally: |
362
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
363
|
|
|
|
364
|
|
|
def it_should_fail_on_missing_repositories(config): |
|
|
|
|
365
|
|
|
shell.mkdir("deps") |
366
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
367
|
|
|
|
368
|
|
|
with pytest.raises(InvalidRepository): |
369
|
|
|
gitman.lock() |
370
|
|
|
|
371
|
|
|
expect(config.__mapper__.text).does_not_contain("<unknown>") |
372
|
|
|
|
373
|
|
|
def it_should_fail_on_invalid_repositories(config): |
|
|
|
|
374
|
|
|
shell.mkdir("deps") |
375
|
|
|
shell.rm(os.path.join("deps", "gitman_1", ".git")) |
376
|
|
|
shell.mkdir(os.path.join("deps", "gitman_1", ".git")) |
377
|
|
|
|
378
|
|
|
try: |
379
|
|
|
with pytest.raises(InvalidRepository): |
380
|
|
|
gitman.lock() |
381
|
|
|
|
382
|
|
|
expect(config.__mapper__.text).does_not_contain("<unknown>") |
383
|
|
|
|
384
|
|
|
finally: |
385
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
386
|
|
|
|