@@ -40,15 +40,15 @@ def test_alt_source(runner, paths, tracked, encrypt, exclude, yadm_alt):
40
40
source_file_content = link_path + "##default"
41
41
source_file = basepath .join (source_file_content )
42
42
link_file = paths .work .join (link_path )
43
+ if link_path == utils .ALT_DIR :
44
+ source_file = source_file .join (utils .CONTAINED )
45
+ link_file = link_file .join (utils .CONTAINED )
43
46
if tracked or (encrypt and not exclude ):
44
47
assert link_file .islink ()
45
48
target = py .path .local (os .path .realpath (link_file ))
46
- if target .isfile ():
47
- assert link_file .read () == source_file_content
48
- assert str (source_file ) in linked
49
- else :
50
- assert link_file .join (utils .CONTAINED ).read () == source_file_content
51
- assert str (source_file ) in linked
49
+ assert target .isfile ()
50
+ assert link_file .read () == source_file_content
51
+ assert str (source_file ) in linked
52
52
else :
53
53
assert not link_file .exists ()
54
54
assert str (source_file ) not in linked
@@ -73,6 +73,9 @@ def test_relative_link(runner, paths, yadm_alt):
73
73
source_file_content = link_path + "##default"
74
74
source_file = basepath .join (source_file_content )
75
75
link_file = paths .work .join (link_path )
76
+ if link_path == utils .ALT_DIR :
77
+ source_file = source_file .join (utils .CONTAINED )
78
+ link_file = link_file .join (utils .CONTAINED )
76
79
link = link_file .readlink ()
77
80
relpath = os .path .relpath (source_file , start = os .path .dirname (link_file ))
78
81
assert link == relpath
@@ -128,15 +131,17 @@ def test_alt_conditions(runner, paths, tst_arch, tst_sys, tst_distro, tst_distro
128
131
linked = utils .parse_alt_output (run .out )
129
132
130
133
for link_path in TEST_PATHS :
131
- source_file = link_path + suffix
132
- assert paths .work .join (link_path ).islink ()
133
- target = py .path .local (os .path .realpath (paths .work .join (link_path )))
134
- if target .isfile ():
135
- assert paths .work .join (link_path ).read () == source_file
136
- assert str (paths .work .join (source_file )) in linked
137
- else :
138
- assert paths .work .join (link_path ).join (utils .CONTAINED ).read () == source_file
139
- assert str (paths .work .join (source_file )) in linked
134
+ source_file_content = link_path + suffix
135
+ source_file = paths .work .join (source_file_content )
136
+ link_file = paths .work .join (link_path )
137
+ if link_path == utils .ALT_DIR :
138
+ source_file = source_file .join (utils .CONTAINED )
139
+ link_file = link_file .join (utils .CONTAINED )
140
+ assert link_file .islink ()
141
+ target = py .path .local (os .path .realpath (link_file ))
142
+ assert target .isfile ()
143
+ assert link_file .read () == source_file_content
144
+ assert str (source_file ) in linked
140
145
141
146
142
147
@pytest .mark .usefixtures ("ds1_copy" )
@@ -156,18 +161,23 @@ def test_alt_templates(runner, paths, kind, label):
156
161
suffix = f"##{ label } .{ kind } "
157
162
if kind is None :
158
163
suffix = f"##{ label } "
164
+
159
165
utils .create_alt_files (paths , suffix )
160
166
run = runner ([paths .pgm , "-Y" , yadm_dir , "--yadm-data" , yadm_data , "alt" ])
161
167
assert run .success
162
168
assert run .err == ""
163
169
created = utils .parse_alt_output (run .out , linked = False )
164
170
165
171
for created_path in TEST_PATHS :
166
- if created_path != utils .ALT_DIR :
167
- source_file = created_path + suffix
168
- assert paths .work .join (created_path ).isfile ()
169
- assert paths .work .join (created_path ).read ().strip () == source_file
170
- assert str (paths .work .join (source_file )) in created
172
+ source_file_content = created_path + suffix
173
+ source_file = paths .work .join (source_file_content )
174
+ created_file = paths .work .join (created_path )
175
+ if created_path == utils .ALT_DIR :
176
+ source_file = source_file .join (utils .CONTAINED )
177
+ created_file = created_file .join (utils .CONTAINED )
178
+ assert created_file .isfile ()
179
+ assert created_file .read ().strip () == source_file_content
180
+ assert str (source_file ) in created
171
181
172
182
173
183
@pytest .mark .usefixtures ("ds1_copy" )
@@ -201,20 +211,22 @@ def test_auto_alt(runner, yadm_cmd, paths, autoalt):
201
211
linked = utils .parse_alt_output (run .out )
202
212
203
213
for link_path in TEST_PATHS :
204
- source_file = link_path + "##default"
214
+ source_file_content = link_path + "##default"
215
+ source_file = paths .work .join (source_file_content )
216
+ link_file = paths .work .join (link_path )
217
+ if link_path == utils .ALT_DIR :
218
+ source_file = source_file .join (utils .CONTAINED )
219
+ link_file = link_file .join (utils .CONTAINED )
220
+
205
221
if autoalt == "false" :
206
- assert not paths . work . join ( link_path ) .exists ()
222
+ assert not link_file .exists ()
207
223
else :
208
- assert paths .work .join (link_path ).islink ()
209
- target = py .path .local (os .path .realpath (paths .work .join (link_path )))
210
- if target .isfile ():
211
- assert paths .work .join (link_path ).read () == source_file
212
- # no linking output when run via auto-alt
213
- assert str (paths .work .join (source_file )) not in linked
214
- else :
215
- assert paths .work .join (link_path ).join (utils .CONTAINED ).read () == source_file
216
- # no linking output when run via auto-alt
217
- assert str (paths .work .join (source_file )) not in linked
224
+ assert link_file .islink ()
225
+ target = py .path .local (os .path .realpath (link_file ))
226
+ assert target .isfile ()
227
+ assert link_file .read () == source_file_content
228
+ # no linking output when run via auto-alt
229
+ assert str (source_file ) not in linked
218
230
219
231
220
232
@pytest .mark .usefixtures ("ds1_copy" )
@@ -236,6 +248,8 @@ def test_alt_exclude(runner, yadm_cmd, paths, autoexclude):
236
248
status = run .out .split ("\0 " )
237
249
238
250
for link_path in TEST_PATHS :
251
+ if link_path == utils .ALT_DIR :
252
+ link_path = f"{ link_path } /{ utils .CONTAINED } "
239
253
flags = "??" if autoexclude == "false" else "!!"
240
254
assert f"{ flags } { link_path } " in status
241
255
@@ -262,16 +276,18 @@ def test_stale_link_removal(runner, yadm_cmd, paths):
262
276
linked = utils .parse_alt_output (run .out )
263
277
264
278
# assert the proper linking has occurred
265
- for stale_path in TEST_PATHS :
266
- source_file = stale_path + "##class." + tst_class
267
- assert paths .work .join (stale_path ).islink ()
268
- target = py .path .local (os .path .realpath (paths .work .join (stale_path )))
269
- if target .isfile ():
270
- assert paths .work .join (stale_path ).read () == source_file
271
- assert str (paths .work .join (source_file )) in linked
272
- else :
273
- assert paths .work .join (stale_path ).join (utils .CONTAINED ).read () == source_file
274
- assert str (paths .work .join (source_file )) in linked
279
+ for link_path in TEST_PATHS :
280
+ source_file_content = link_path + f"##class.{ tst_class } "
281
+ source_file = paths .work .join (source_file_content )
282
+ link_file = paths .work .join (link_path )
283
+ if link_path == utils .ALT_DIR :
284
+ source_file = source_file .join (utils .CONTAINED )
285
+ link_file = link_file .join (utils .CONTAINED )
286
+ assert link_file .islink ()
287
+ target = py .path .local (os .path .realpath (link_file ))
288
+ assert target .isfile ()
289
+ assert link_file .read () == source_file_content
290
+ assert str (source_file ) in linked
275
291
276
292
# change the class so there are no valid alternates
277
293
utils .set_local (paths , "class" , "changedclass" )
@@ -284,9 +300,53 @@ def test_stale_link_removal(runner, yadm_cmd, paths):
284
300
285
301
# assert the linking is removed
286
302
for stale_path in TEST_PATHS :
287
- source_file = stale_path + "##class." + tst_class
288
- assert not paths .work .join (stale_path ).exists ()
289
- assert str (paths .work .join (source_file )) not in linked
303
+ source_file_content = stale_path + f"##class.{ tst_class } "
304
+ source_file = paths .work .join (source_file_content )
305
+ stale_file = paths .work .join (stale_path )
306
+ if stale_path == utils .ALT_DIR :
307
+ source_file = source_file .join (utils .CONTAINED )
308
+ stale_file = stale_file .join (utils .CONTAINED )
309
+ assert not stale_file .exists ()
310
+ assert str (source_file ) not in linked
311
+
312
+
313
+ @pytest .mark .usefixtures ("ds1_copy" )
314
+ def test_legacy_dir_link_removal (runner , yadm_cmd , paths ):
315
+ """Legacy link to alternative dir is removed
316
+
317
+ This test ensures that a legacy dir alternative (i.e. symlink to the dir
318
+ itself) is converted to indiividual links.
319
+ """
320
+
321
+ utils .create_alt_files (paths , "##default" )
322
+
323
+ # Create legacy link
324
+ link_dir = paths .work .join (utils .ALT_DIR )
325
+ link_dir .mksymlinkto (link_dir .basename + "##default" )
326
+ assert link_dir .islink ()
327
+
328
+ # run alt to trigger linking
329
+ run = runner (yadm_cmd ("alt" ))
330
+ assert run .success
331
+ assert run .err == ""
332
+ linked = utils .parse_alt_output (run .out )
333
+
334
+ # assert legacy link is removed
335
+ assert not link_dir .islink ()
336
+
337
+ # assert the proper linking has occurred
338
+ for link_path in TEST_PATHS :
339
+ source_file_content = link_path + "##default"
340
+ source_file = paths .work .join (source_file_content )
341
+ link_file = paths .work .join (link_path )
342
+ if link_path == utils .ALT_DIR :
343
+ source_file = source_file .join (utils .CONTAINED )
344
+ link_file = link_file .join (utils .CONTAINED )
345
+ assert link_file .islink ()
346
+ target = py .path .local (os .path .realpath (link_file ))
347
+ assert target .isfile ()
348
+ assert link_file .read () == source_file_content
349
+ assert str (source_file ) in linked
290
350
291
351
292
352
@pytest .mark .usefixtures ("ds1_repo_copy" )
0 commit comments