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