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