Skip to content

Commit a8bfb02

Browse files
committed
fmt
1 parent 9b12680 commit a8bfb02

6 files changed

Lines changed: 126 additions & 31 deletions

File tree

src/aws_durable_execution_sdk_python_testing/checkpoint/processors/chained_invoke.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,19 @@ def _process_succeed(
109109

110110
return Operation(
111111
operation_id=update.operation_id,
112-
parent_id=update.parent_id if update.parent_id else (current_op.parent_id if current_op else None),
113-
name=update.name if update.name else (current_op.name if current_op else None),
112+
parent_id=update.parent_id
113+
if update.parent_id
114+
else (current_op.parent_id if current_op else None),
115+
name=update.name
116+
if update.name
117+
else (current_op.name if current_op else None),
114118
start_timestamp=start_time,
115119
end_timestamp=end_time,
116120
operation_type=OperationType.CHAINED_INVOKE,
117121
status=OperationStatus.SUCCEEDED,
118-
sub_type=update.sub_type if update.sub_type else (current_op.sub_type if current_op else None),
122+
sub_type=update.sub_type
123+
if update.sub_type
124+
else (current_op.sub_type if current_op else None),
119125
chained_invoke_details=chained_invoke_details,
120126
)
121127

@@ -136,12 +142,18 @@ def _process_fail(
136142

137143
return Operation(
138144
operation_id=update.operation_id,
139-
parent_id=update.parent_id if update.parent_id else (current_op.parent_id if current_op else None),
140-
name=update.name if update.name else (current_op.name if current_op else None),
145+
parent_id=update.parent_id
146+
if update.parent_id
147+
else (current_op.parent_id if current_op else None),
148+
name=update.name
149+
if update.name
150+
else (current_op.name if current_op else None),
141151
start_timestamp=start_time,
142152
end_timestamp=end_time,
143153
operation_type=OperationType.CHAINED_INVOKE,
144154
status=OperationStatus.FAILED,
145-
sub_type=update.sub_type if update.sub_type else (current_op.sub_type if current_op else None),
155+
sub_type=update.sub_type
156+
if update.sub_type
157+
else (current_op.sub_type if current_op else None),
146158
chained_invoke_details=chained_invoke_details,
147159
)

tests/checkpoint/processors/chained_invoke_test.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,30 @@ def notify_chained_invoke_started(
4646
"operation_id,function_name,payload,execution_arn",
4747
[
4848
# Basic case with payload
49-
("op-1", "child-function", '{"key": "value"}', "arn:aws:lambda:us-east-1:123456789012:execution:test"),
49+
(
50+
"op-1",
51+
"child-function",
52+
'{"key": "value"}',
53+
"arn:aws:lambda:us-east-1:123456789012:execution:test",
54+
),
5055
# No payload
51-
("op-2", "handler-fn", None, "arn:aws:lambda:us-west-2:987654321098:execution:parent"),
56+
(
57+
"op-2",
58+
"handler-fn",
59+
None,
60+
"arn:aws:lambda:us-west-2:987654321098:execution:parent",
61+
),
5262
# Empty payload
5363
("op-3", "my-function", "", "test-arn"),
5464
# Complex payload
5565
("op-complex", "complex-fn", '{"nested": {"array": [1, 2, 3]}}', "complex-arn"),
5666
# Long function name
57-
("op-long", "very-long-function-name-with-many-characters", '{"data": 123}', "long-arn"),
67+
(
68+
"op-long",
69+
"very-long-function-name-with-many-characters",
70+
'{"data": 123}',
71+
"long-arn",
72+
),
5873
],
5974
)
6075
def test_property_start_creates_pending_operation(
@@ -109,7 +124,11 @@ def test_property_start_creates_pending_operation(
109124
"operation_id,result_payload,execution_arn",
110125
[
111126
# Basic case with result
112-
("op-1", '{"result": "success"}', "arn:aws:lambda:us-east-1:123456789012:execution:test"),
127+
(
128+
"op-1",
129+
'{"result": "success"}',
130+
"arn:aws:lambda:us-east-1:123456789012:execution:test",
131+
),
113132
# No result
114133
("op-2", None, "arn:aws:lambda:us-west-2:987654321098:execution:parent"),
115134
# Empty result
@@ -163,9 +182,19 @@ def test_property_succeed_updates_to_succeeded(
163182
"operation_id,error_type,error_message,execution_arn",
164183
[
165184
# Basic error
166-
("op-1", "RuntimeError", "Something went wrong", "arn:aws:lambda:us-east-1:123456789012:execution:test"),
185+
(
186+
"op-1",
187+
"RuntimeError",
188+
"Something went wrong",
189+
"arn:aws:lambda:us-east-1:123456789012:execution:test",
190+
),
167191
# Timeout error
168-
("op-2", "TimeoutError", "Function timed out", "arn:aws:lambda:us-west-2:987654321098:execution:parent"),
192+
(
193+
"op-2",
194+
"TimeoutError",
195+
"Function timed out",
196+
"arn:aws:lambda:us-west-2:987654321098:execution:parent",
197+
),
169198
# Resource not found
170199
("op-3", "ResourceNotFoundException", "Handler not found", "test-arn"),
171200
# Generic error

tests/e2e/chained_invoke_test.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def test_handler_registration_and_retrieval(self):
4747
4848
_Requirements: 1.1, 1.4, 2.1_
4949
"""
50+
5051
def dummy_handler(event, context):
5152
return {"status": "ok"}
5253

@@ -70,6 +71,7 @@ def test_multiple_handler_registration(self):
7071
7172
_Requirements: 1.4_
7273
"""
74+
7375
def dummy_handler(event, context):
7476
return {"status": "ok"}
7577

@@ -94,20 +96,27 @@ def test_handler_registration_validation(self):
9496
9597
_Requirements: 1.2, 1.3_
9698
"""
99+
97100
def dummy_handler(event, context):
98101
return {"status": "ok"}
99102

100103
with DurableFunctionTestRunner(handler=dummy_handler) as runner:
101104
# Empty function name should raise
102-
with pytest.raises(InvalidParameterValueException, match="function_name is required"):
105+
with pytest.raises(
106+
InvalidParameterValueException, match="function_name is required"
107+
):
103108
runner.register_handler("", lambda p: p)
104109

105110
# None function name should raise
106-
with pytest.raises(InvalidParameterValueException, match="function_name is required"):
111+
with pytest.raises(
112+
InvalidParameterValueException, match="function_name is required"
113+
):
107114
runner.register_handler(None, lambda p: p)
108115

109116
# None handler should raise
110-
with pytest.raises(InvalidParameterValueException, match="handler is required"):
117+
with pytest.raises(
118+
InvalidParameterValueException, match="handler is required"
119+
):
111120
runner.register_handler("test-fn", None)
112121

113122

@@ -188,6 +197,7 @@ def child_handler(payload: str | None) -> str | None:
188197

189198
# Wait for handler to be invoked (scheduler runs async)
190199
import time
200+
191201
time.sleep(0.1)
192202

193203
# Verify handler was called with correct payload
@@ -236,7 +246,9 @@ def mock_process_checkpoint(**kwargs):
236246
checkpoint_calls.append(kwargs)
237247
# Don't actually process to avoid side effects
238248

239-
test_components["checkpoint_processor"].process_checkpoint = mock_process_checkpoint
249+
test_components[
250+
"checkpoint_processor"
251+
].process_checkpoint = mock_process_checkpoint
240252

241253
# Create mock execution
242254
execution_arn = "test-arn"
@@ -260,6 +272,7 @@ def mock_process_checkpoint(**kwargs):
260272

261273
# Wait for handler to complete
262274
import time
275+
263276
time.sleep(0.1)
264277

265278
# Verify checkpoint was called with SUCCEED action
@@ -289,7 +302,9 @@ def failing_handler(payload: str | None) -> str | None:
289302
def mock_process_checkpoint(**kwargs):
290303
checkpoint_calls.append(kwargs)
291304

292-
test_components["checkpoint_processor"].process_checkpoint = mock_process_checkpoint
305+
test_components[
306+
"checkpoint_processor"
307+
].process_checkpoint = mock_process_checkpoint
293308

294309
# Create mock execution
295310
execution_arn = "test-arn"
@@ -313,6 +328,7 @@ def mock_process_checkpoint(**kwargs):
313328

314329
# Wait for handler to complete
315330
import time
331+
316332
time.sleep(0.1)
317333

318334
# Verify checkpoint was called with FAIL action
@@ -373,15 +389,18 @@ def test_non_durable_function_result_serialization(self):
373389
374390
_Requirements: 8.2_
375391
"""
392+
376393
def child_handler(payload: str | None) -> str | None:
377394
# Handler returns serialized JSON string
378-
return json.dumps({
379-
"string": "value",
380-
"number": 123,
381-
"boolean": True,
382-
"array": [1, 2, 3],
383-
"nested": {"key": "value"},
384-
})
395+
return json.dumps(
396+
{
397+
"string": "value",
398+
"number": 123,
399+
"boolean": True,
400+
"array": [1, 2, 3],
401+
"nested": {"key": "value"},
402+
}
403+
)
385404

386405
def dummy_handler(event, context):
387406
return {"status": "ok"}
@@ -406,6 +425,7 @@ def test_non_durable_function_exception_capture(self):
406425
407426
_Requirements: 8.3_
408427
"""
428+
409429
def failing_child(payload: str | None) -> str | None:
410430
raise RuntimeError("Child function failed")
411431

tests/executor_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,6 +2901,7 @@ def test_property_successful_handler_result_capture(result_payload: str | None):
29012901
29022902
**Validates: Requirements 2.3, 9.3**
29032903
"""
2904+
29042905
# Arrange
29052906
def test_handler(p: str | None) -> str | None:
29062907
return result_payload
@@ -2963,6 +2964,7 @@ def test_property_failed_handler_error_capture(error_message: str):
29632964
29642965
**Validates: Requirements 2.4, 9.4**
29652966
"""
2967+
29662968
# Arrange
29672969
def failing_handler(p: str | None) -> str | None:
29682970
raise ValueError(error_message)

tests/observer_test.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,35 @@ def test_execution_notifier_all_notification_methods():
374374
"num_observers,execution_arn,operation_id,function_name,payload",
375375
[
376376
# Single observer with payload
377-
(1, "arn:aws:lambda:us-east-1:123456789012:function:test", "op-1", "child-fn", '{"key": "value"}'),
377+
(
378+
1,
379+
"arn:aws:lambda:us-east-1:123456789012:function:test",
380+
"op-1",
381+
"child-fn",
382+
'{"key": "value"}',
383+
),
378384
# Multiple observers with payload
379-
(3, "arn:aws:lambda:us-west-2:987654321098:function:parent", "op-abc", "handler-fn", '{"data": 123}'),
385+
(
386+
3,
387+
"arn:aws:lambda:us-west-2:987654321098:function:parent",
388+
"op-abc",
389+
"handler-fn",
390+
'{"data": 123}',
391+
),
380392
# Single observer with None payload
381393
(1, "test-arn", "operation-id", "my-function", None),
382394
# Multiple observers with None payload
383395
(5, "exec-arn-123", "op-xyz", "lambda-handler", None),
384396
# Edge case: empty string payload
385397
(2, "arn:test", "op-empty", "fn-name", ""),
386398
# Edge case: complex payload
387-
(4, "complex-arn", "op-complex", "complex-fn", '{"nested": {"array": [1, 2, 3]}}'),
399+
(
400+
4,
401+
"complex-arn",
402+
"op-complex",
403+
"complex-fn",
404+
'{"nested": {"array": [1, 2, 3]}}',
405+
),
388406
],
389407
)
390408
def test_property_observer_notification_broadcast(

tests/runner_test.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,7 @@ def test_property_handler_registration_preserves_all_handlers(handler_pairs):
22092209
22102210
**Validates: Requirements 1.1, 1.4**
22112211
"""
2212+
22122213
# Create a minimal handler for the test runner
22132214
def dummy_handler(event, context):
22142215
return {"status": "ok"}
@@ -2228,26 +2229,33 @@ def dummy_handler(event, context):
22282229

22292230
def test_register_handler_empty_function_name_raises():
22302231
"""Test that registering with empty function_name raises InvalidParameterValueException."""
2232+
22312233
def dummy_handler(event, context):
22322234
return {"status": "ok"}
22332235

22342236
with DurableFunctionTestRunner(dummy_handler) as runner:
2235-
with pytest.raises(InvalidParameterValueException, match="function_name is required"):
2237+
with pytest.raises(
2238+
InvalidParameterValueException, match="function_name is required"
2239+
):
22362240
runner.register_handler("", lambda x: x)
22372241

22382242

22392243
def test_register_handler_none_function_name_raises():
22402244
"""Test that registering with None function_name raises InvalidParameterValueException."""
2245+
22412246
def dummy_handler(event, context):
22422247
return {"status": "ok"}
22432248

22442249
with DurableFunctionTestRunner(dummy_handler) as runner:
2245-
with pytest.raises(InvalidParameterValueException, match="function_name is required"):
2250+
with pytest.raises(
2251+
InvalidParameterValueException, match="function_name is required"
2252+
):
22462253
runner.register_handler(None, lambda x: x)
22472254

22482255

22492256
def test_register_handler_none_handler_raises():
22502257
"""Test that registering with None handler raises InvalidParameterValueException."""
2258+
22512259
def dummy_handler(event, context):
22522260
return {"status": "ok"}
22532261

@@ -2258,6 +2266,7 @@ def dummy_handler(event, context):
22582266

22592267
def test_get_handler_not_found_returns_none():
22602268
"""Test that get_handler returns None for unregistered function names."""
2269+
22612270
def dummy_handler(event, context):
22622271
return {"status": "ok"}
22632272

@@ -2268,6 +2277,7 @@ def dummy_handler(event, context):
22682277

22692278
def test_register_handler_overwrites_existing():
22702279
"""Test that registering a handler with an existing name overwrites it."""
2280+
22712281
def dummy_handler(event, context):
22722282
return {"status": "ok"}
22732283

@@ -2384,9 +2394,13 @@ def test_cloud_runner_register_lambda_validation():
23842394
)
23852395

23862396
# Empty function_name should raise
2387-
with pytest.raises(InvalidParameterValueException, match="function_name is required"):
2397+
with pytest.raises(
2398+
InvalidParameterValueException, match="function_name is required"
2399+
):
23882400
runner.register_lambda("")
23892401

23902402
# None function_name should raise
2391-
with pytest.raises(InvalidParameterValueException, match="function_name is required"):
2403+
with pytest.raises(
2404+
InvalidParameterValueException, match="function_name is required"
2405+
):
23922406
runner.register_lambda(None)

0 commit comments

Comments
 (0)