@@ -277,21 +277,15 @@ 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 (
281
- xray_fault ["exceptions" ][0 ]["message" ], expected_response ["errorMessage" ]
282
- )
283
- self .assertEqual (
284
- xray_fault ["exceptions" ][0 ]["type" ], expected_response ["errorType" ]
285
- )
280
+ self .assertEqual (xray_fault ["exceptions" ][0 ]["message" ], expected_response ["errorMessage" ])
281
+ self .assertEqual (xray_fault ["exceptions" ][0 ]["type" ], expected_response ["errorType" ])
286
282
self .assertEqual (len (xray_fault ["exceptions" ][0 ]["stack" ]), 1 )
287
283
self .assertEqual (
288
284
xray_fault ["exceptions" ][0 ]["stack" ][0 ]["label" ], "raise_exception_handler"
289
285
)
290
286
self .assertIsInstance (xray_fault ["exceptions" ][0 ]["stack" ][0 ]["line" ], int )
291
287
self .assertTrue (
292
- xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (
293
- os .path .relpath (__file__ )
294
- )
288
+ xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (os .path .relpath (__file__ ))
295
289
)
296
290
self .assertEqual (len (xray_fault ["paths" ]), 1 )
297
291
self .assertTrue (xray_fault ["paths" ][0 ].endswith (os .path .relpath (__file__ )))
@@ -329,21 +323,15 @@ def __init__(self, message):
329
323
xray_fault = json .loads (args [2 ])
330
324
self .assertEqual (xray_fault ["working_directory" ], self .working_directory )
331
325
self .assertEqual (len (xray_fault ["exceptions" ]), 1 )
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
- )
326
+ self .assertEqual (xray_fault ["exceptions" ][0 ]["message" ], expected_response ["errorMessage" ])
327
+ self .assertEqual (xray_fault ["exceptions" ][0 ]["type" ], expected_response ["errorType" ])
338
328
self .assertEqual (len (xray_fault ["exceptions" ][0 ]["stack" ]), 1 )
339
329
self .assertEqual (
340
330
xray_fault ["exceptions" ][0 ]["stack" ][0 ]["label" ], "raise_exception_handler"
341
331
)
342
332
self .assertIsInstance (xray_fault ["exceptions" ][0 ]["stack" ][0 ]["line" ], int )
343
333
self .assertTrue (
344
- xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (
345
- os .path .relpath (__file__ )
346
- )
334
+ xray_fault ["exceptions" ][0 ]["stack" ][0 ]["path" ].endswith (os .path .relpath (__file__ ))
347
335
)
348
336
self .assertEqual (len (xray_fault ["paths" ]), 1 )
349
337
self .assertTrue (xray_fault ["paths" ][0 ].endswith (os .path .relpath (__file__ )))
@@ -472,9 +460,7 @@ def raise_exception_handler(json_input, lambda_context):
472
460
try :
473
461
import invalid_module # noqa: F401
474
462
except ImportError :
475
- raise bootstrap .FaultException (
476
- "FaultExceptionType" , "Fault exception msg" , None
477
- )
463
+ raise bootstrap .FaultException ("FaultExceptionType" , "Fault exception msg" , None )
478
464
479
465
bootstrap .handle_event_request (
480
466
self .lambda_runtime ,
@@ -488,14 +474,14 @@ def raise_exception_handler(json_input, lambda_context):
488
474
0 ,
489
475
bootstrap .StandardLogSink (),
490
476
)
491
- error_logs = "[ERROR] FaultExceptionType: Fault exception msg\r Traceback (most recent call last):\n "
477
+ error_logs = (
478
+ "[ERROR] FaultExceptionType: Fault exception msg\r Traceback (most recent call last):\n "
479
+ )
492
480
493
481
self .assertEqual (mock_stdout .getvalue (), error_logs )
494
482
495
483
@patch ("sys.stdout" , new_callable = StringIO )
496
- def test_handle_event_request_fault_exception_logging_nomessage_notrace (
497
- self , mock_stdout
498
- ):
484
+ def test_handle_event_request_fault_exception_logging_nomessage_notrace (self , mock_stdout ):
499
485
def raise_exception_handler (json_input , lambda_context ):
500
486
try :
501
487
import invalid_module # noqa: F401
@@ -519,9 +505,7 @@ def raise_exception_handler(json_input, lambda_context):
519
505
self .assertEqual (mock_stdout .getvalue (), error_logs )
520
506
521
507
@patch ("sys.stdout" , new_callable = StringIO )
522
- def test_handle_event_request_fault_exception_logging_notype_notrace (
523
- self , mock_stdout
524
- ):
508
+ def test_handle_event_request_fault_exception_logging_notype_notrace (self , mock_stdout ):
525
509
def raise_exception_handler (json_input , lambda_context ):
526
510
try :
527
511
import invalid_module # noqa: F401
@@ -545,9 +529,7 @@ def raise_exception_handler(json_input, lambda_context):
545
529
self .assertEqual (mock_stdout .getvalue (), error_logs )
546
530
547
531
@patch ("sys.stdout" , new_callable = StringIO )
548
- def test_handle_event_request_fault_exception_logging_notype_nomessage (
549
- self , mock_stdout
550
- ):
532
+ def test_handle_event_request_fault_exception_logging_notype_nomessage (self , mock_stdout ):
551
533
def raise_exception_handler (json_input , lambda_context ):
552
534
try :
553
535
import invalid_module # noqa: F401
@@ -670,9 +652,7 @@ def __init__(self):
670
652
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["label" ], "test_method" )
671
653
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["path" ], "test.py" )
672
654
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["line" ], 28 )
673
- self .assertEqual (
674
- actual ["exceptions" ][0 ]["stack" ][1 ]["label" ], "another_test_method"
675
- )
655
+ self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["label" ], "another_test_method" )
676
656
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["path" ], "another_test.py" )
677
657
self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["line" ], 2718 )
678
658
@@ -682,9 +662,7 @@ class FaultExceptionMatcher(BaseException):
682
662
def __init__ (self , msg , exception_type = None , trace_pattern = None ):
683
663
self .msg = msg
684
664
self .exception_type = exception_type
685
- self .trace = (
686
- trace_pattern if trace_pattern is None else re .compile (trace_pattern )
687
- )
665
+ self .trace = trace_pattern if trace_pattern is None else re .compile (trace_pattern )
688
666
689
667
def __eq__ (self , other ):
690
668
trace_matches = True
@@ -732,12 +710,8 @@ def test_get_event_handler_import_error(self):
732
710
733
711
def test_get_event_handler_syntax_error (self ):
734
712
importlib .invalidate_caches ()
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
- )
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')" )
741
715
tmp_file .flush ()
742
716
743
717
filename_w_ext = os .path .basename (tmp_file .name )
@@ -759,9 +733,7 @@ def test_get_event_handler_syntax_error(self):
759
733
760
734
def test_get_event_handler_missing_error (self ):
761
735
importlib .invalidate_caches ()
762
- with tempfile .NamedTemporaryFile (
763
- suffix = ".py" , dir = "." , delete = False
764
- ) as tmp_file :
736
+ with tempfile .NamedTemporaryFile (suffix = ".py" , dir = "." , delete = False ) as tmp_file :
765
737
tmp_file .write (b"def wrong_handler_name():\n \t print('hello')" )
766
738
tmp_file .flush ()
767
739
@@ -800,15 +772,11 @@ def test_get_event_handler_build_in_conflict(self):
800
772
)
801
773
802
774
def test_get_event_handler_doesnt_throw_build_in_module_name_slash (self ):
803
- response_handler = bootstrap ._get_handler (
804
- "tests/test_built_in_module_name/sys.my_handler"
805
- )
775
+ response_handler = bootstrap ._get_handler ("tests/test_built_in_module_name/sys.my_handler" )
806
776
response_handler ()
807
777
808
778
def test_get_event_handler_doent_throw_build_in_module_name (self ):
809
- response_handler = bootstrap ._get_handler (
810
- "tests.test_built_in_module_name.sys.my_handler"
811
- )
779
+ response_handler = bootstrap ._get_handler ("tests.test_built_in_module_name.sys.my_handler" )
812
780
response_handler ()
813
781
814
782
@@ -914,7 +882,9 @@ def test_log_error_standard_log_sink(self, mock_stdout):
914
882
915
883
def test_log_error_framed_log_sink (self ):
916
884
with NamedTemporaryFile () as temp_file :
917
- with bootstrap .FramedTelemetryLogSink (os .open (temp_file .name , os .O_CREAT | os .O_RDWR )) as log_sink :
885
+ with bootstrap .FramedTelemetryLogSink (
886
+ os .open (temp_file .name , os .O_CREAT | os .O_RDWR )
887
+ ) as log_sink :
918
888
err_to_log = bootstrap .make_error ("Error message" , "ErrorType" , None )
919
889
bootstrap .log_error (err_to_log , log_sink )
920
890
@@ -949,7 +919,9 @@ def test_log_error_indentation_standard_log_sink(self, mock_stdout):
949
919
950
920
def test_log_error_indentation_framed_log_sink (self ):
951
921
with NamedTemporaryFile () as temp_file :
952
- with bootstrap .FramedTelemetryLogSink (os .open (temp_file .name , os .O_CREAT | os .O_RDWR )) as log_sink :
922
+ with bootstrap .FramedTelemetryLogSink (
923
+ os .open (temp_file .name , os .O_CREAT | os .O_RDWR )
924
+ ) as log_sink :
953
925
err_to_log = bootstrap .make_error (
954
926
"Error message" , "ErrorType" , [" line1 " , " line2 " , " " ]
955
927
)
@@ -974,17 +946,17 @@ def test_log_error_indentation_framed_log_sink(self):
974
946
975
947
@patch ("sys.stdout" , new_callable = StringIO )
976
948
def test_log_error_empty_stacktrace_line_standard_log_sink (self , mock_stdout ):
977
- err_to_log = bootstrap .make_error (
978
- "Error message" , "ErrorType" , ["line1" , "" , "line2" ]
979
- )
949
+ err_to_log = bootstrap .make_error ("Error message" , "ErrorType" , ["line1" , "" , "line2" ])
980
950
bootstrap .log_error (err_to_log , bootstrap .StandardLogSink ())
981
951
982
952
expected_logged_error = "[ERROR] ErrorType: Error message\r Traceback (most recent call last):\r line1\r \r line2\n "
983
953
self .assertEqual (mock_stdout .getvalue (), expected_logged_error )
984
954
985
955
def test_log_error_empty_stacktrace_line_framed_log_sink (self ):
986
956
with NamedTemporaryFile () as temp_file :
987
- with bootstrap .FramedTelemetryLogSink (os .open (temp_file .name , os .O_CREAT | os .O_RDWR )) as log_sink :
957
+ with bootstrap .FramedTelemetryLogSink (
958
+ os .open (temp_file .name , os .O_CREAT | os .O_RDWR )
959
+ ) as log_sink :
988
960
err_to_log = bootstrap .make_error (
989
961
"Error message" , "ErrorType" , ["line1" , "" , "line2" ]
990
962
)
@@ -1082,7 +1054,9 @@ def test_create_framed_telemetry_log_sinks(self):
1082
1054
def test_single_frame (self ):
1083
1055
with NamedTemporaryFile () as temp_file :
1084
1056
message = "hello world\n something on a new line!\n "
1085
- with bootstrap .FramedTelemetryLogSink (os .open (temp_file .name , os .O_CREAT | os .O_RDWR )) as ls :
1057
+ with bootstrap .FramedTelemetryLogSink (
1058
+ os .open (temp_file .name , os .O_CREAT | os .O_RDWR )
1059
+ ) as ls :
1086
1060
ls .log (message )
1087
1061
with open (temp_file .name , "rb" ) as f :
1088
1062
content = f .read ()
@@ -1101,7 +1075,9 @@ def test_multiple_frame(self):
1101
1075
first_message = "hello world\n something on a new line!"
1102
1076
second_message = "hello again\n here's another message\n "
1103
1077
1104
- with bootstrap .FramedTelemetryLogSink (os .open (temp_file .name , os .O_CREAT | os .O_RDWR )) as ls :
1078
+ with bootstrap .FramedTelemetryLogSink (
1079
+ os .open (temp_file .name , os .O_CREAT | os .O_RDWR )
1080
+ ) as ls :
1105
1081
ls .log (first_message )
1106
1082
ls .log (second_message )
1107
1083
@@ -1141,9 +1117,7 @@ def test_run(self, mock_runtime_client, mock_handle_event_request):
1141
1117
]
1142
1118
1143
1119
with self .assertRaises (TypeError ):
1144
- bootstrap .run (
1145
- expected_app_root , expected_handler , expected_lambda_runtime_api_addr
1146
- )
1120
+ bootstrap .run (expected_app_root , expected_handler , expected_lambda_runtime_api_addr )
1147
1121
1148
1122
mock_handle_event_request .assert_called_once ()
1149
1123
@@ -1166,9 +1140,7 @@ class TestException(Exception):
1166
1140
mock_sys .exit .side_effect = TestException ("Boom!" )
1167
1141
1168
1142
with self .assertRaises (TestException ):
1169
- bootstrap .run (
1170
- expected_app_root , expected_handler , expected_lambda_runtime_api_addr
1171
- )
1143
+ bootstrap .run (expected_app_root , expected_handler , expected_lambda_runtime_api_addr )
1172
1144
1173
1145
mock_sys .exit .assert_called_once_with (1 )
1174
1146
0 commit comments