@@ -277,15 +277,21 @@ def __init__(self, message):
277
277
xray_fault = json .loads (args [2 ])
278
278
self .assertEqual (xray_fault ["working_directory" ], self .working_directory )
279
279
self .assertEqual (len (xray_fault ["exceptions" ]), 1 )
280
- self .assertEqual (xray_fault ["exceptions" ][0 ]["message" ], expected_response ["errorMessage" ])
281
- self .assertEqual (xray_fault ["exceptions" ][0 ]["type" ], expected_response ["errorType" ])
280
+ self .assertEqual (
281
+ xray_fault ["exceptions" ][0 ]["message" ], expected_response ["errorMessage" ]
282
+ )
283
+ self .assertEqual (
284
+ xray_fault ["exceptions" ][0 ]["type" ], expected_response ["errorType" ]
285
+ )
282
286
self .assertEqual (len (xray_fault ["exceptions" ][0 ]["stack" ]), 1 )
283
287
self .assertEqual (
284
288
xray_fault ["exceptions" ][0 ]["stack" ][0 ]["label" ], "raise_exception_handler"
285
289
)
286
290
self .assertIsInstance (xray_fault ["exceptions" ][0 ]["stack" ][0 ]["line" ], int )
287
291
self .assertTrue (
288
- xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (os .path .relpath (__file__ ))
292
+ xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (
293
+ os .path .relpath (__file__ )
294
+ )
289
295
)
290
296
self .assertEqual (len (xray_fault ["paths" ]), 1 )
291
297
self .assertTrue (xray_fault ["paths" ][0 ].endswith (os .path .relpath (__file__ )))
@@ -323,15 +329,21 @@ def __init__(self, message):
323
329
xray_fault = json .loads (args [2 ])
324
330
self .assertEqual (xray_fault ["working_directory" ], self .working_directory )
325
331
self .assertEqual (len (xray_fault ["exceptions" ]), 1 )
326
- self .assertEqual (xray_fault ["exceptions" ][0 ]["message" ], expected_response ["errorMessage" ])
327
- self .assertEqual (xray_fault ["exceptions" ][0 ]["type" ], expected_response ["errorType" ])
332
+ self .assertEqual (
333
+ xray_fault ["exceptions" ][0 ]["message" ], expected_response ["errorMessage" ]
334
+ )
335
+ self .assertEqual (
336
+ xray_fault ["exceptions" ][0 ]["type" ], expected_response ["errorType" ]
337
+ )
328
338
self .assertEqual (len (xray_fault ["exceptions" ][0 ]["stack" ]), 1 )
329
339
self .assertEqual (
330
340
xray_fault ["exceptions" ][0 ]["stack" ][0 ]["label" ], "raise_exception_handler"
331
341
)
332
342
self .assertIsInstance (xray_fault ["exceptions" ][0 ]["stack" ][0 ]["line" ], int )
333
343
self .assertTrue (
334
- xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (os .path .relpath (__file__ ))
344
+ xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (
345
+ os .path .relpath (__file__ )
346
+ )
335
347
)
336
348
self .assertEqual (len (xray_fault ["paths" ]), 1 )
337
349
self .assertTrue (xray_fault ["paths" ][0 ].endswith (os .path .relpath (__file__ )))
@@ -460,7 +472,9 @@ def raise_exception_handler(json_input, lambda_context):
460
472
try :
461
473
import invalid_module # noqa: F401
462
474
except ImportError :
463
- raise bootstrap .FaultException ("FaultExceptionType" , "Fault exception msg" , None )
475
+ raise bootstrap .FaultException (
476
+ "FaultExceptionType" , "Fault exception msg" , None
477
+ )
464
478
465
479
bootstrap .handle_event_request (
466
480
self .lambda_runtime ,
@@ -474,14 +488,14 @@ def raise_exception_handler(json_input, lambda_context):
474
488
0 ,
475
489
bootstrap .StandardLogSink (),
476
490
)
477
- error_logs = (
478
- "[ERROR] FaultExceptionType: Fault exception msg\r Traceback (most recent call last):\n "
479
- )
491
+ error_logs = "[ERROR] FaultExceptionType: Fault exception msg\r Traceback (most recent call last):\n "
480
492
481
493
self .assertEqual (mock_stdout .getvalue (), error_logs )
482
494
483
495
@patch ("sys.stdout" , new_callable = StringIO )
484
- def test_handle_event_request_fault_exception_logging_nomessage_notrace (self , mock_stdout ):
496
+ def test_handle_event_request_fault_exception_logging_nomessage_notrace (
497
+ self , mock_stdout
498
+ ):
485
499
def raise_exception_handler (json_input , lambda_context ):
486
500
try :
487
501
import invalid_module # noqa: F401
@@ -505,7 +519,9 @@ def raise_exception_handler(json_input, lambda_context):
505
519
self .assertEqual (mock_stdout .getvalue (), error_logs )
506
520
507
521
@patch ("sys.stdout" , new_callable = StringIO )
508
- def test_handle_event_request_fault_exception_logging_notype_notrace (self , mock_stdout ):
522
+ def test_handle_event_request_fault_exception_logging_notype_notrace (
523
+ self , mock_stdout
524
+ ):
509
525
def raise_exception_handler (json_input , lambda_context ):
510
526
try :
511
527
import invalid_module # noqa: F401
@@ -529,7 +545,9 @@ def raise_exception_handler(json_input, lambda_context):
529
545
self .assertEqual (mock_stdout .getvalue (), error_logs )
530
546
531
547
@patch ("sys.stdout" , new_callable = StringIO )
532
- def test_handle_event_request_fault_exception_logging_notype_nomessage (self , mock_stdout ):
548
+ def test_handle_event_request_fault_exception_logging_notype_nomessage (
549
+ self , mock_stdout
550
+ ):
533
551
def raise_exception_handler (json_input , lambda_context ):
534
552
try :
535
553
import invalid_module # noqa: F401
@@ -652,7 +670,9 @@ def __init__(self):
652
670
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["label" ], "test_method" )
653
671
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["path" ], "test.py" )
654
672
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["line" ], 28 )
655
- self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["label" ], "another_test_method" )
673
+ self .assertEqual (
674
+ actual ["exceptions" ][0 ]["stack" ][1 ]["label" ], "another_test_method"
675
+ )
656
676
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["path" ], "another_test.py" )
657
677
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["line" ], 2718 )
658
678
@@ -662,7 +682,9 @@ class FaultExceptionMatcher(BaseException):
662
682
def __init__ (self , msg , exception_type = None , trace_pattern = None ):
663
683
self .msg = msg
664
684
self .exception_type = exception_type
665
- self .trace = trace_pattern if trace_pattern is None else re .compile (trace_pattern )
685
+ self .trace = (
686
+ trace_pattern if trace_pattern is None else re .compile (trace_pattern )
687
+ )
666
688
667
689
def __eq__ (self , other ):
668
690
trace_matches = True
@@ -710,8 +732,12 @@ def test_get_event_handler_import_error(self):
710
732
711
733
def test_get_event_handler_syntax_error (self ):
712
734
importlib .invalidate_caches ()
713
- with tempfile .NamedTemporaryFile (suffix = ".py" , dir = "." , delete = False ) as tmp_file :
714
- tmp_file .write (b"def syntax_error()\n \t print('syntax error, no colon after function')" )
735
+ with tempfile .NamedTemporaryFile (
736
+ suffix = ".py" , dir = "." , delete = False
737
+ ) as tmp_file :
738
+ tmp_file .write (
739
+ b"def syntax_error()\n \t print('syntax error, no colon after function')"
740
+ )
715
741
tmp_file .flush ()
716
742
717
743
filename_w_ext = os .path .basename (tmp_file .name )
@@ -733,7 +759,9 @@ def test_get_event_handler_syntax_error(self):
733
759
734
760
def test_get_event_handler_missing_error (self ):
735
761
importlib .invalidate_caches ()
736
- with tempfile .NamedTemporaryFile (suffix = ".py" , dir = "." , delete = False ) as tmp_file :
762
+ with tempfile .NamedTemporaryFile (
763
+ suffix = ".py" , dir = "." , delete = False
764
+ ) as tmp_file :
737
765
tmp_file .write (b"def wrong_handler_name():\n \t print('hello')" )
738
766
tmp_file .flush ()
739
767
@@ -772,11 +800,15 @@ def test_get_event_handler_build_in_conflict(self):
772
800
)
773
801
774
802
def test_get_event_handler_doesnt_throw_build_in_module_name_slash (self ):
775
- response_handler = bootstrap ._get_handler ("tests/test_built_in_module_name/sys.my_handler" )
803
+ response_handler = bootstrap ._get_handler (
804
+ "tests/test_built_in_module_name/sys.my_handler"
805
+ )
776
806
response_handler ()
777
807
778
808
def test_get_event_handler_doent_throw_build_in_module_name (self ):
779
- response_handler = bootstrap ._get_handler ("tests.test_built_in_module_name.sys.my_handler" )
809
+ response_handler = bootstrap ._get_handler (
810
+ "tests.test_built_in_module_name.sys.my_handler"
811
+ )
780
812
response_handler ()
781
813
782
814
@@ -946,7 +978,9 @@ def test_log_error_indentation_framed_log_sink(self):
946
978
947
979
@patch ("sys.stdout" , new_callable = StringIO )
948
980
def test_log_error_empty_stacktrace_line_standard_log_sink (self , mock_stdout ):
949
- err_to_log = bootstrap .make_error ("Error message" , "ErrorType" , ["line1" , "" , "line2" ])
981
+ err_to_log = bootstrap .make_error (
982
+ "Error message" , "ErrorType" , ["line1" , "" , "line2" ]
983
+ )
950
984
bootstrap .log_error (err_to_log , bootstrap .StandardLogSink ())
951
985
952
986
expected_logged_error = "[ERROR] ErrorType: Error message\r Traceback (most recent call last):\r line1\r \r line2\n "
@@ -1117,7 +1151,9 @@ def test_run(self, mock_runtime_client, mock_handle_event_request):
1117
1151
]
1118
1152
1119
1153
with self .assertRaises (TypeError ):
1120
- bootstrap .run (expected_app_root , expected_handler , expected_lambda_runtime_api_addr )
1154
+ bootstrap .run (
1155
+ expected_app_root , expected_handler , expected_lambda_runtime_api_addr
1156
+ )
1121
1157
1122
1158
mock_handle_event_request .assert_called_once ()
1123
1159
@@ -1140,7 +1176,9 @@ class TestException(Exception):
1140
1176
mock_sys .exit .side_effect = TestException ("Boom!" )
1141
1177
1142
1178
with self .assertRaises (TestException ):
1143
- bootstrap .run (expected_app_root , expected_handler , expected_lambda_runtime_api_addr )
1179
+ bootstrap .run (
1180
+ expected_app_root , expected_handler , expected_lambda_runtime_api_addr
1181
+ )
1144
1182
1145
1183
mock_sys .exit .assert_called_once_with (1 )
1146
1184
0 commit comments