@@ -15,18 +15,125 @@ process PyProcess {
1515}
1616
1717workflow {
18+ // Test pyFunction in a process: should return correct sum and difference
1819 PyProcess (10 , 3 )
19- .view()
20+ .view { result ->
21+ assert result == [x : 10 , y : 3 ]
22+ println " [TEST] PyProcess returned: $result "
23+ }
2024
21- Channel . of([x : 10 , y : 3 ], [x : 1 , y : 5 ])
22- .pyOperator(script : ' echo_kwargs.py' ) |
23- view()
25+ // Test pyOperator with a map input
26+ Channel . of([x : 10 , y : 3 ])
27+ .pyOperator(script : ' echo_kwargs.py' )
28+ .view { result ->
29+ assert result == [x : 10 , y : 3 ]
30+ println " [TEST] pyOperator map input returned: $result "
31+ }
2432
25- // Test all supported types and roundtrip
26- Channel . of(1 , 2 , 3 )
27- .pyOperator(script : ' echo_kwargs.py' , foo : ' bar' , bar : 123 , baz : [1 ,2 ,3 ], qux : [a : 1 , b : 2 ], path : ' /tmp/example.txt' , duration : 90 )
28- .view()
33+ // Test pyOperator with primitive input and options
34+ Channel . of(1 )
35+ .pyOperator(script : ' echo_kwargs.py' , foo : ' bar' , bar : 123 )
36+ .view { result ->
37+ assert result == [value : 1 , foo : ' bar' , bar : 123 ]
38+ println " [TEST] pyOperator primitive+opts returned: $result "
39+ }
2940
30- // Example: Launch a Python script as a standalone function (no channel input)
31- pyFunction(script : ' echo_kwargs.py' , foo : ' standalone' , bar : 42 )
41+ // Test pyFunction as a standalone function
42+ def standalone = pyFunction(script : ' echo_kwargs.py' , foo : ' standalone' , bar : 42 )
43+ assert standalone == [foo : ' standalone' , bar : 42 ]
44+ println " [TEST] pyFunction standalone returned: $standalone "
45+
46+ // Test all supported types and roundtrip, one script call at a time
47+ Channel . of(42 )
48+ .pyOperator(script : ' echo_kwargs.py' )
49+ .view { result ->
50+ assert result. value == 42
51+ println " [TEST] int roundtrip: $result "
52+ }
53+
54+ Channel . of(3.14 )
55+ .pyOperator(script : ' echo_kwargs.py' )
56+ .view { result ->
57+ assert Math . abs(result. value - 3.14 ) < 1e-6
58+ println " [TEST] float roundtrip: $result "
59+ }
60+
61+ Channel . of(' hello' )
62+ .pyOperator(script : ' echo_kwargs.py' )
63+ .view { result ->
64+ assert result. value == ' hello'
65+ println " [TEST] str roundtrip: $result "
66+ }
67+
68+ Channel . of(true )
69+ .pyOperator(script : ' echo_kwargs.py' )
70+ .view { result ->
71+ assert result. value == true
72+ println " [TEST] bool roundtrip: $result "
73+ }
74+
75+ Channel . of(null )
76+ .pyOperator(script : ' echo_kwargs.py' )
77+ .view { result ->
78+ assert result. value == null
79+ println " [TEST] null roundtrip: $result "
80+ }
81+
82+ Channel . of([1 , 2 , 3 ])
83+ .pyOperator(script : ' echo_kwargs.py' )
84+ .view { result ->
85+ assert result. value == [1 , 2 , 3 ]
86+ println " [TEST] list roundtrip: $result "
87+ }
88+
89+ Channel . of([4 , 5 , 6 ] as Set )
90+ .pyOperator(script : ' echo_kwargs.py' )
91+ .view { result ->
92+ assert (result. value as Set ) == [4 , 5 , 6 ] as Set
93+ println " [TEST] set roundtrip: $result "
94+ }
95+
96+ Channel . of([a : 1 , b : 2 ])
97+ .pyOperator(script : ' echo_kwargs.py' )
98+ .view { result ->
99+ assert result == [a : 1 , b : 2 ]
100+ println " [TEST] dict roundtrip: $result "
101+ }
102+
103+ Channel . of(' /tmp/example.txt' )
104+ .pyOperator(script : ' echo_kwargs.py' )
105+ .view { result ->
106+ assert result. value. toString() == ' /tmp/example.txt'
107+ println " [TEST] path roundtrip: $result "
108+ }
109+
110+ Channel . of(java.time.Duration . ofSeconds(90 ))
111+ .pyOperator(script : ' echo_kwargs.py' )
112+ .view { result ->
113+ assert result. value. toString() == ' PT1M30S' || result. value. seconds == 90
114+ println " [TEST] duration roundtrip: $result "
115+ }
116+
117+ Channel . of(Duration . of(90000 ))
118+ .pyOperator(script : ' echo_kwargs.py' )
119+ .view { result ->
120+ assert result. value. toString() == ' PT1M30S' || result. value. seconds == 90
121+ println " [TEST] duration roundtrip: $result "
122+ }
123+
124+ Channel . of(10241024 )
125+ .pyOperator(script : ' echo_kwargs.py' , type : ' memory' )
126+ .view { result ->
127+ // memory is returned as int, check value
128+ assert result. value == 10241024
129+ println " [TEST] memory roundtrip: $result "
130+ }
131+
132+ Channel . of([82 , 17 , 49 ])
133+ .pyOperator(script : ' echo_kwargs.py' , type : ' version' )
134+ .view { result ->
135+ // version is returned as list, check value
136+ assert result. value == [82 , 17 , 49 ]
137+ println " [TEST] version roundtrip: $result "
138+ }
32139}
0 commit comments