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