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