4
4
from pydra .compose import python , workflow , shell
5
5
from fileformats .text import TextFile
6
6
from pydra .utils .general import (
7
- serialize_task_class ,
8
- unserialize_task_class ,
7
+ unstructure ,
8
+ structure ,
9
9
get_fields ,
10
10
filter_out_defaults ,
11
11
)
@@ -49,33 +49,33 @@ def Add(a: int, b: int | None = None, c: int | None = None) -> int:
49
49
return a + (b if b is not None else c )
50
50
51
51
52
- def test_python_serialize_task_class (tmp_path ):
52
+ def test_python_unstructure (tmp_path ):
53
53
54
54
assert Add (a = 1 , b = 2 )(cache_root = tmp_path / "cache1" ).out_int == 3
55
55
56
- dct = serialize_task_class (Add )
56
+ dct = unstructure (Add )
57
57
assert isinstance (dct , dict )
58
58
check_dict_fully_serialized (dct )
59
- Reloaded = unserialize_task_class (dct )
59
+ Reloaded = structure (dct )
60
60
assert get_fields (Add ) == get_fields (Reloaded )
61
61
62
62
assert Reloaded (a = 1 , b = 2 )(cache_root = tmp_path / "cache2" ).out_int == 3
63
63
64
64
65
- def test_shell_serialize_task_class ():
65
+ def test_shell_unstructure ():
66
66
67
67
MyCmd = shell .define (
68
68
"my-cmd <in_file> <out|out_file> --an-arg <an_arg:int=2> --a-flag<a_flag>"
69
69
)
70
70
71
- dct = serialize_task_class (MyCmd )
71
+ dct = unstructure (MyCmd )
72
72
assert isinstance (dct , dict )
73
73
check_dict_fully_serialized (dct )
74
- Reloaded = unserialize_task_class (dct )
74
+ Reloaded = structure (dct )
75
75
assert get_fields (MyCmd ) == get_fields (Reloaded )
76
76
77
77
78
- def test_workflow_serialize_task_class (tmp_path ):
78
+ def test_workflow_unstructure (tmp_path ):
79
79
80
80
@workflow .define (outputs = ["out_file" ])
81
81
def AWorkflow (in_file : TextFile , a_param : int ) -> TextFile :
@@ -84,10 +84,10 @@ def AWorkflow(in_file: TextFile, a_param: int) -> TextFile:
84
84
)
85
85
return concatenate .out_file
86
86
87
- dct = serialize_task_class (AWorkflow )
87
+ dct = unstructure (AWorkflow )
88
88
assert isinstance (dct , dict )
89
89
check_dict_fully_serialized (dct )
90
- Reloaded = unserialize_task_class (dct )
90
+ Reloaded = structure (dct )
91
91
assert get_fields (AWorkflow ) == get_fields (Reloaded )
92
92
93
93
foo_file = tmp_path / "file1.txt"
@@ -97,7 +97,7 @@ def AWorkflow(in_file: TextFile, a_param: int) -> TextFile:
97
97
assert outputs .out_file .contents == "foo\n foo\n foo\n foo"
98
98
99
99
100
- def test_serialize_task_class_with_value_serializer ():
100
+ def test_unstructure_with_value_serializer ():
101
101
102
102
@python .define
103
103
def Identity (a : int ) -> int :
@@ -121,13 +121,13 @@ def type_to_str_serializer(
121
121
return value .__module__ + "." + value .__name__
122
122
return value
123
123
124
- dct = serialize_task_class (Identity , value_serializer = type_to_str_serializer )
124
+ dct = unstructure (Identity , value_serializer = type_to_str_serializer )
125
125
assert isinstance (dct , dict )
126
126
check_dict_fully_serialized (dct )
127
127
assert dct ["inputs" ] == {"a" : {"type" : "builtins.int" , "help" : "the arg" }}
128
128
129
129
130
- def test_serialize_task_class_with_filter ():
130
+ def test_unstructure_with_filter ():
131
131
132
132
@python .define
133
133
def Identity (a : int ) -> int :
@@ -149,7 +149,7 @@ def no_helps_filter(atr: attrs.Attribute, value: ty.Any) -> bool:
149
149
return False
150
150
return filter_out_defaults (atr , value )
151
151
152
- dct = serialize_task_class (Identity , filter = no_helps_filter )
152
+ dct = unstructure (Identity , filter = no_helps_filter )
153
153
assert isinstance (dct , dict )
154
154
check_dict_fully_serialized (dct )
155
155
assert dct ["inputs" ] == {"a" : {"type" : int }}
0 commit comments