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