File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class LazyField(ty.Generic[T], metaclass=abc.ABCMeta):
30
30
31
31
def __bytes_repr__ (self , cache ):
32
32
yield type (self ).__name__ .encode () + b"("
33
- yield from bytes (hash_single (self .source , cache ))
33
+ yield b"source=" + bytes (hash_single (self ._source , cache ))
34
34
yield b"field=" + self ._field .encode ()
35
35
yield b"type=" + bytes (hash_single (self ._type , cache ))
36
36
yield b"cast_from=" + bytes (hash_single (self ._cast_from , cache ))
Original file line number Diff line number Diff line change 21
21
import random
22
22
from fileformats .generic import Directory , File
23
23
from pydra .utils .hash import hash_function
24
+ from pydra .utils .tests .utils import Concatenate
24
25
25
26
26
27
def test_hash_file (tmpdir ):
@@ -558,3 +559,14 @@ def __repr__(self):
558
559
),
559
560
):
560
561
hash_object (A ())
562
+
563
+
564
+ def test_hash_task (tmp_path ):
565
+ """
566
+ Test that the hash of a task is consistent across runs
567
+ """
568
+
569
+ concatenate1 = Concatenate ()
570
+ concatenate2 = Concatenate ()
571
+
572
+ assert hash_function (concatenate1 ) == hash_function (concatenate2 )
Original file line number Diff line number Diff line change
1
+ import typing as ty
2
+ from pathlib import Path
1
3
from fileformats .generic import File , BinaryFile
2
4
from fileformats .core .mixin import WithSeparateHeader , WithMagicNumber
3
5
from pydra .compose import shell , python
@@ -94,3 +96,38 @@ class Outputs(shell.Outputs):
94
96
)
95
97
96
98
executable = "echo"
99
+
100
+
101
+ @python .define (outputs = ["out_file" ])
102
+ def Concatenate (
103
+ in_file1 : File ,
104
+ in_file2 : File ,
105
+ out_file : ty .Optional [Path ] = None ,
106
+ duplicates : int = 1 ,
107
+ ) -> File :
108
+ """Concatenates the contents of two files and writes them to a third
109
+
110
+ Parameters
111
+ ----------
112
+ in_file1 : Path
113
+ A text file
114
+ in_file2 : Path
115
+ Another text file
116
+ out_file : Path
117
+ The path to write the output file to
118
+
119
+ Returns
120
+ -------
121
+ out_file: Path
122
+ A text file made by concatenating the two inputs
123
+ """
124
+ if out_file is None :
125
+ out_file = Path ("out_file.txt" ).absolute ()
126
+ contents = []
127
+ for _ in range (duplicates ):
128
+ for fname in (in_file1 , in_file2 ):
129
+ with open (fname ) as f :
130
+ contents .append (f .read ())
131
+ with open (out_file , "w" ) as f :
132
+ f .write ("\n " .join (contents ))
133
+ return out_file
You can’t perform that action at this time.
0 commit comments