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