@@ -70,7 +70,7 @@ def test_fastapi_simple_request(self):
70
70
app = fastapi .FastAPI ()
71
71
dispatch = create_dispatch_instance (app , endpoint = "http://127.0.0.1:9999/" )
72
72
73
- @dispatch .primitive_function ()
73
+ @dispatch .primitive_function
74
74
def my_function (input : Input ) -> Output :
75
75
return Output .value (
76
76
f"You told me: '{ input .input } ' ({ len (input .input )} characters)"
@@ -159,7 +159,7 @@ def proto_call(self, call: call_pb.Call) -> call_pb.CallResult:
159
159
return resp .exit .result
160
160
161
161
def test_no_input (self ):
162
- @self .dispatch .primitive_function ()
162
+ @self .dispatch .primitive_function
163
163
def my_function (input : Input ) -> Output :
164
164
return Output .value ("Hello World!" )
165
165
@@ -178,7 +178,7 @@ def test_missing_coroutine(self):
178
178
self .assertEqual (cm .exception .response .status_code , 404 )
179
179
180
180
def test_string_input (self ):
181
- @self .dispatch .primitive_function ()
181
+ @self .dispatch .primitive_function
182
182
def my_function (input : Input ) -> Output :
183
183
return Output .value (f"You sent '{ input .input } '" )
184
184
@@ -187,7 +187,7 @@ def my_function(input: Input) -> Output:
187
187
self .assertEqual (out , "You sent 'cool stuff'" )
188
188
189
189
def test_error_on_access_state_in_first_call (self ):
190
- @self .dispatch .primitive_function ()
190
+ @self .dispatch .primitive_function
191
191
def my_function (input : Input ) -> Output :
192
192
try :
193
193
print (input .coroutine_state )
@@ -206,7 +206,7 @@ def my_function(input: Input) -> Output:
206
206
)
207
207
208
208
def test_error_on_access_input_in_second_call (self ):
209
- @self .dispatch .primitive_function ()
209
+ @self .dispatch .primitive_function
210
210
def my_function (input : Input ) -> Output :
211
211
if input .is_first_call :
212
212
return Output .poll (state = 42 )
@@ -230,22 +230,22 @@ def my_function(input: Input) -> Output:
230
230
)
231
231
232
232
def test_duplicate_coro (self ):
233
- @self .dispatch .primitive_function ()
233
+ @self .dispatch .primitive_function
234
234
def my_function (input : Input ) -> Output :
235
235
return Output .value ("Do one thing" )
236
236
237
237
with self .assertRaises (ValueError ):
238
238
239
- @self .dispatch .primitive_function ()
239
+ @self .dispatch .primitive_function
240
240
def my_function (input : Input ) -> Output :
241
241
return Output .value ("Do something else" )
242
242
243
243
def test_two_simple_coroutines (self ):
244
- @self .dispatch .primitive_function ()
244
+ @self .dispatch .primitive_function
245
245
def echoroutine (input : Input ) -> Output :
246
246
return Output .value (f"Echo: '{ input .input } '" )
247
247
248
- @self .dispatch .primitive_function ()
248
+ @self .dispatch .primitive_function
249
249
def len_coroutine (input : Input ) -> Output :
250
250
return Output .value (f"Length: { len (input .input )} " )
251
251
@@ -259,7 +259,7 @@ def len_coroutine(input: Input) -> Output:
259
259
self .assertEqual (out , "Length: 10" )
260
260
261
261
def test_coroutine_with_state (self ):
262
- @self .dispatch .primitive_function ()
262
+ @self .dispatch .primitive_function
263
263
def coroutine3 (input : Input ) -> Output :
264
264
if input .is_first_call :
265
265
counter = input .input
@@ -293,11 +293,11 @@ def coroutine3(input: Input) -> Output:
293
293
self .assertEqual (out , "done" )
294
294
295
295
def test_coroutine_poll (self ):
296
- @self .dispatch .primitive_function ()
296
+ @self .dispatch .primitive_function
297
297
def coro_compute_len (input : Input ) -> Output :
298
298
return Output .value (len (input .input ))
299
299
300
- @self .dispatch .primitive_function ()
300
+ @self .dispatch .primitive_function
301
301
def coroutine_main (input : Input ) -> Output :
302
302
if input .is_first_call :
303
303
text : str = input .input
@@ -333,11 +333,11 @@ def coroutine_main(input: Input) -> Output:
333
333
self .assertEqual ("length=10 text='cool stuff'" , out )
334
334
335
335
def test_coroutine_poll_error (self ):
336
- @self .dispatch .primitive_function ()
336
+ @self .dispatch .primitive_function
337
337
def coro_compute_len (input : Input ) -> Output :
338
338
return Output .error (Error (Status .PERMANENT_ERROR , "type" , "Dead" ))
339
339
340
- @self .dispatch .primitive_function ()
340
+ @self .dispatch .primitive_function
341
341
def coroutine_main (input : Input ) -> Output :
342
342
if input .is_first_call :
343
343
text : str = input .input
@@ -372,7 +372,7 @@ def coroutine_main(input: Input) -> Output:
372
372
self .assertEqual (out , "msg=Dead type='type'" )
373
373
374
374
def test_coroutine_error (self ):
375
- @self .dispatch .primitive_function ()
375
+ @self .dispatch .primitive_function
376
376
def mycoro (input : Input ) -> Output :
377
377
return Output .error (Error (Status .PERMANENT_ERROR , "sometype" , "dead" ))
378
378
@@ -381,7 +381,7 @@ def mycoro(input: Input) -> Output:
381
381
self .assertEqual ("dead" , resp .exit .result .error .message )
382
382
383
383
def test_coroutine_expected_exception (self ):
384
- @self .dispatch .primitive_function ()
384
+ @self .dispatch .primitive_function
385
385
def mycoro (input : Input ) -> Output :
386
386
try :
387
387
1 / 0
@@ -395,7 +395,7 @@ def mycoro(input: Input) -> Output:
395
395
self .assertEqual (Status .PERMANENT_ERROR , resp .status )
396
396
397
397
def test_coroutine_unexpected_exception (self ):
398
- @self .dispatch .function ()
398
+ @self .dispatch .function
399
399
def mycoro ():
400
400
1 / 0
401
401
self .fail ("should not reach here" )
@@ -406,7 +406,7 @@ def mycoro():
406
406
self .assertEqual (Status .PERMANENT_ERROR , resp .status )
407
407
408
408
def test_specific_status (self ):
409
- @self .dispatch .primitive_function ()
409
+ @self .dispatch .primitive_function
410
410
def mycoro (input : Input ) -> Output :
411
411
return Output .error (Error (Status .THROTTLED , "foo" , "bar" ))
412
412
@@ -416,11 +416,11 @@ def mycoro(input: Input) -> Output:
416
416
self .assertEqual (Status .THROTTLED , resp .status )
417
417
418
418
def test_tailcall (self ):
419
- @self .dispatch .function ()
419
+ @self .dispatch .function
420
420
def other_coroutine (value : Any ) -> str :
421
421
return f"Hello { value } "
422
422
423
- @self .dispatch .primitive_function ()
423
+ @self .dispatch .primitive_function
424
424
def mycoro (input : Input ) -> Output :
425
425
return Output .tail_call (other_coroutine ._build_primitive_call (42 ))
426
426
@@ -429,7 +429,7 @@ def mycoro(input: Input) -> Output:
429
429
self .assertEqual (42 , any_unpickle (resp .exit .tail_call .input ))
430
430
431
431
def test_library_error_categorization (self ):
432
- @self .dispatch .function ()
432
+ @self .dispatch .function
433
433
def get (path : str ) -> httpx .Response :
434
434
http_response = self .http_client .get (path )
435
435
http_response .raise_for_status ()
@@ -445,7 +445,7 @@ def get(path: str) -> httpx.Response:
445
445
self .assertEqual (Status .NOT_FOUND , Status (resp .status ))
446
446
447
447
def test_library_output_categorization (self ):
448
- @self .dispatch .function ()
448
+ @self .dispatch .function
449
449
def get (path : str ) -> httpx .Response :
450
450
http_response = self .http_client .get (path )
451
451
http_response .status_code = 429
0 commit comments