44from pydra .compose import python , workflow , shell
55from fileformats .text import TextFile
66from pydra .utils .general import (
7- serialize_task_class ,
8- unserialize_task_class ,
7+ unstructure ,
8+ structure ,
99 get_fields ,
1010 filter_out_defaults ,
1111)
@@ -49,33 +49,33 @@ def Add(a: int, b: int | None = None, c: int | None = None) -> int:
4949 return a + (b if b is not None else c )
5050
5151
52- def test_python_serialize_task_class (tmp_path ):
52+ def test_python_unstructure (tmp_path ):
5353
5454 assert Add (a = 1 , b = 2 )(cache_root = tmp_path / "cache1" ).out_int == 3
5555
56- dct = serialize_task_class (Add )
56+ dct = unstructure (Add )
5757 assert isinstance (dct , dict )
5858 check_dict_fully_serialized (dct )
59- Reloaded = unserialize_task_class (dct )
59+ Reloaded = structure (dct )
6060 assert get_fields (Add ) == get_fields (Reloaded )
6161
6262 assert Reloaded (a = 1 , b = 2 )(cache_root = tmp_path / "cache2" ).out_int == 3
6363
6464
65- def test_shell_serialize_task_class ():
65+ def test_shell_unstructure ():
6666
6767 MyCmd = shell .define (
6868 "my-cmd <in_file> <out|out_file> --an-arg <an_arg:int=2> --a-flag<a_flag>"
6969 )
7070
71- dct = serialize_task_class (MyCmd )
71+ dct = unstructure (MyCmd )
7272 assert isinstance (dct , dict )
7373 check_dict_fully_serialized (dct )
74- Reloaded = unserialize_task_class (dct )
74+ Reloaded = structure (dct )
7575 assert get_fields (MyCmd ) == get_fields (Reloaded )
7676
7777
78- def test_workflow_serialize_task_class (tmp_path ):
78+ def test_workflow_unstructure (tmp_path ):
7979
8080 @workflow .define (outputs = ["out_file" ])
8181 def AWorkflow (in_file : TextFile , a_param : int ) -> TextFile :
@@ -84,10 +84,10 @@ def AWorkflow(in_file: TextFile, a_param: int) -> TextFile:
8484 )
8585 return concatenate .out_file
8686
87- dct = serialize_task_class (AWorkflow )
87+ dct = unstructure (AWorkflow )
8888 assert isinstance (dct , dict )
8989 check_dict_fully_serialized (dct )
90- Reloaded = unserialize_task_class (dct )
90+ Reloaded = structure (dct )
9191 assert get_fields (AWorkflow ) == get_fields (Reloaded )
9292
9393 foo_file = tmp_path / "file1.txt"
@@ -97,7 +97,7 @@ def AWorkflow(in_file: TextFile, a_param: int) -> TextFile:
9797 assert outputs .out_file .contents == "foo\n foo\n foo\n foo"
9898
9999
100- def test_serialize_task_class_with_value_serializer ():
100+ def test_unstructure_with_value_serializer ():
101101
102102 @python .define
103103 def Identity (a : int ) -> int :
@@ -121,13 +121,13 @@ def type_to_str_serializer(
121121 return value .__module__ + "." + value .__name__
122122 return value
123123
124- dct = serialize_task_class (Identity , value_serializer = type_to_str_serializer )
124+ dct = unstructure (Identity , value_serializer = type_to_str_serializer )
125125 assert isinstance (dct , dict )
126126 check_dict_fully_serialized (dct )
127127 assert dct ["inputs" ] == {"a" : {"type" : "builtins.int" , "help" : "the arg" }}
128128
129129
130- def test_serialize_task_class_with_filter ():
130+ def test_unstructure_with_filter ():
131131
132132 @python .define
133133 def Identity (a : int ) -> int :
@@ -149,7 +149,7 @@ def no_helps_filter(atr: attrs.Attribute, value: ty.Any) -> bool:
149149 return False
150150 return filter_out_defaults (atr , value )
151151
152- dct = serialize_task_class (Identity , filter = no_helps_filter )
152+ dct = unstructure (Identity , filter = no_helps_filter )
153153 assert isinstance (dct , dict )
154154 check_dict_fully_serialized (dct )
155155 assert dct ["inputs" ] == {"a" : {"type" : int }}
0 commit comments