1- from pydra .engine .result import Result , Runtime
1+ from pathlib import Path
2+ from fileformats .text import TextFile
3+ from pydra .compose import python
4+ from pydra .engine .result import Result , Runtime , copyfile_workflow
5+
6+
7+ @python .define (outputs = ["d" , "e" , "f" ])
8+ def MockTask (
9+ a : TextFile , b : TextFile , c : TextFile
10+ ) -> tuple [TextFile , TextFile , TextFile ]:
11+ return a , b , c
212
313
414def test_runtime ():
@@ -8,9 +18,30 @@ def test_runtime():
818 assert hasattr (runtime , "cpu_peak_percent" )
919
1020
11- def test_result (tmp_path ):
21+ def test_result (tmp_path : Path ):
1222 result = Result (cache_dir = tmp_path )
1323 assert hasattr (result , "runtime" )
1424 assert hasattr (result , "outputs" )
1525 assert hasattr (result , "errored" )
1626 assert getattr (result , "errored" ) is False
27+
28+
29+ def test_copyfile_workflow_conflicting_filenames (tmp_path : Path ) -> None :
30+ """Copy outputs to the workflow output directory with conflicting filenames.
31+ The filenames should be disambiguated to avoid clashes"""
32+ file1 = TextFile .sample (stem = "out" )
33+ file2 = TextFile .sample (stem = "out" )
34+ file3 = TextFile .sample (stem = "out" )
35+
36+ workflow_dir = tmp_path / "output"
37+ mock = MockTask (a = file1 , b = file2 , c = file3 )
38+ outputs = mock ()
39+ workflow_dir .mkdir ()
40+
41+ copyfile_workflow (workflow_dir , outputs )
42+
43+ assert sorted (p .stem for p in workflow_dir .iterdir ()) == [
44+ "out" ,
45+ "out (1)" ,
46+ "out (2)" ,
47+ ]
0 commit comments