@@ -301,7 +301,7 @@ def test_save_file_same_dependency_twice(self) -> None:
301
301
self .init_workspace_helper ()
302
302
assert self .workspace is not None and self .expected_structure is not None
303
303
prev_run_name = self .workspace .dbgym_this_run_path .name
304
- result_path = self .make_result_helper ()
304
+ result_path = self .make_result_helper (file_obj = ( "file" ,) )
305
305
self .init_workspace_helper ()
306
306
self .workspace .save_file (result_path )
307
307
self .workspace .save_file (result_path )
@@ -315,10 +315,64 @@ def test_save_file_same_dependency_twice(self) -> None:
315
315
verify_structure (self .scratchspace_path , self .expected_structure )
316
316
)
317
317
318
- def test_save_file_two_different_dependencies_with_same_name (self ) -> None :
319
- # TODO
320
- # TODO: also do the config version
321
- pass
318
+ def test_save_file_two_different_dependencies_with_same_filename_both_directly_inside_run (
319
+ self ,
320
+ ) -> None :
321
+ self .init_workspace_helper ()
322
+ assert self .workspace is not None and self .expected_structure is not None
323
+ prev_run_names = []
324
+ prev_run_names .append (self .workspace .dbgym_this_run_path .name )
325
+ result1_path = self .make_result_helper (file_obj = ("file" ,))
326
+ self .init_workspace_helper ()
327
+ prev_run_names .append (self .workspace .dbgym_this_run_path .name )
328
+ result2_path = self .make_result_helper (file_obj = ("file" ,))
329
+ filename = result1_path .name
330
+ assert filename == result2_path .name
331
+
332
+ self .init_workspace_helper ()
333
+ self .workspace .save_file (result1_path )
334
+ self .workspace .save_file (result2_path )
335
+ # The second save_file() should have overwritten the first one.
336
+ self .expected_structure ["dbgym_workspace" ]["task_runs" ][
337
+ self .workspace .dbgym_this_run_path .name
338
+ ][f"{ filename } .link" ] = (
339
+ "symlink" ,
340
+ f"dbgym_workspace/task_runs/{ prev_run_names [- 1 ]} /{ filename } " ,
341
+ )
342
+ self .assertTrue (
343
+ verify_structure (self .scratchspace_path , self .expected_structure )
344
+ )
345
+
346
+ def test_save_file_two_different_dependencies_with_same_filename_but_different_outermost_dirs (
347
+ self ,
348
+ ) -> None :
349
+ self .init_workspace_helper ()
350
+ assert self .workspace is not None and self .expected_structure is not None
351
+ prev_run_name = self .workspace .dbgym_this_run_path .name
352
+ result1_path = self .make_result_helper ("dir1/result.txt" , file_obj = ("file" ,))
353
+ result2_path = self .make_result_helper ("result.txt" , file_obj = ("file" ,))
354
+ filename = result1_path .name
355
+ assert filename == result2_path .name
356
+
357
+ self .init_workspace_helper ()
358
+ self .workspace .save_file (result1_path )
359
+ self .workspace .save_file (result2_path )
360
+ # The second save_file() should not overwrite the first one because the outermost dirs are different.
361
+ self .expected_structure ["dbgym_workspace" ]["task_runs" ][
362
+ self .workspace .dbgym_this_run_path .name
363
+ ][f"{ filename } .link" ] = (
364
+ "symlink" ,
365
+ f"dbgym_workspace/task_runs/{ prev_run_name } /{ filename } " ,
366
+ )
367
+ self .expected_structure ["dbgym_workspace" ]["task_runs" ][
368
+ self .workspace .dbgym_this_run_path .name
369
+ ]["dir1.link" ] = (
370
+ "symlink" ,
371
+ f"dbgym_workspace/task_runs/{ prev_run_name } /dir1" ,
372
+ )
373
+ self .assertTrue (
374
+ verify_structure (self .scratchspace_path , self .expected_structure )
375
+ )
322
376
323
377
def test_save_file_config (self ) -> None :
324
378
"""
@@ -340,12 +394,35 @@ def test_save_file_config(self) -> None:
340
394
def test_save_file_same_config_twice (self ) -> None :
341
395
self .init_workspace_helper ()
342
396
assert self .workspace is not None and self .expected_structure is not None
343
- result_path = self .make_file_helper ("external/result.txt" )
397
+ result_path = self .make_file_helper (
398
+ "external/result.txt" , file_obj = ("file" , "contents" )
399
+ )
344
400
self .workspace .save_file (result_path )
345
401
self .workspace .save_file (result_path )
346
402
self .expected_structure ["dbgym_workspace" ]["task_runs" ][
347
403
self .workspace .dbgym_this_run_path .name
348
- ][f"{ result_path .name } " ] = ("file" ,)
404
+ ][f"{ result_path .name } " ] = ("file" , "contents" )
405
+ self .assertTrue (
406
+ verify_structure (self .scratchspace_path , self .expected_structure )
407
+ )
408
+
409
+ def test_save_file_two_different_configs_with_same_filename (self ) -> None :
410
+ self .init_workspace_helper ()
411
+ assert self .workspace is not None and self .expected_structure is not None
412
+ result1_path = self .make_file_helper (
413
+ "external/result.txt" , file_obj = ("file" , "contents1" )
414
+ )
415
+ result2_path = self .make_file_helper (
416
+ "external/dir1/result.txt" , file_obj = ("file" , "contents2" )
417
+ )
418
+ filename = result1_path .name
419
+ assert filename == result2_path .name
420
+
421
+ self .workspace .save_file (result1_path )
422
+ self .workspace .save_file (result2_path )
423
+ self .expected_structure ["dbgym_workspace" ]["task_runs" ][
424
+ self .workspace .dbgym_this_run_path .name
425
+ ][f"{ filename } " ] = ("file" , "contents2" )
349
426
self .assertTrue (
350
427
verify_structure (self .scratchspace_path , self .expected_structure )
351
428
)
@@ -379,8 +456,6 @@ def test_save_file_generated_this_run_raises_error(self) -> None:
379
456
):
380
457
self .workspace .save_file (result_path )
381
458
382
- # TODO: test saving different configs/dependencies with the same name
383
-
384
459
385
460
if __name__ == "__main__" :
386
461
unittest .main ()
0 commit comments