@@ -277,21 +277,15 @@ def __init__(self, message):
277277 xray_fault = json .loads (args [2 ])
278278 self .assertEqual (xray_fault ["working_directory" ], self .working_directory )
279279 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" ])
286282 self .assertEqual (len (xray_fault ["exceptions" ][0 ]["stack" ]), 1 )
287283 self .assertEqual (
288284 xray_fault ["exceptions" ][0 ]["stack" ][0 ]["label" ], "raise_exception_handler"
289285 )
290286 self .assertIsInstance (xray_fault ["exceptions" ][0 ]["stack" ][0 ]["line" ], int )
291287 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__ ))
295289 )
296290 self .assertEqual (len (xray_fault ["paths" ]), 1 )
297291 self .assertTrue (xray_fault ["paths" ][0 ].endswith (os .path .relpath (__file__ )))
@@ -329,21 +323,15 @@ def __init__(self, message):
329323 xray_fault = json .loads (args [2 ])
330324 self .assertEqual (xray_fault ["working_directory" ], self .working_directory )
331325 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" ])
338328 self .assertEqual (len (xray_fault ["exceptions" ][0 ]["stack" ]), 1 )
339329 self .assertEqual (
340330 xray_fault ["exceptions" ][0 ]["stack" ][0 ]["label" ], "raise_exception_handler"
341331 )
342332 self .assertIsInstance (xray_fault ["exceptions" ][0 ]["stack" ][0 ]["line" ], int )
343333 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__ ))
347335 )
348336 self .assertEqual (len (xray_fault ["paths" ]), 1 )
349337 self .assertTrue (xray_fault ["paths" ][0 ].endswith (os .path .relpath (__file__ )))
@@ -472,9 +460,7 @@ def raise_exception_handler(json_input, lambda_context):
472460 try :
473461 import invalid_module # noqa: F401
474462 except ImportError :
475- raise bootstrap .FaultException (
476- "FaultExceptionType" , "Fault exception msg" , None
477- )
463+ raise bootstrap .FaultException ("FaultExceptionType" , "Fault exception msg" , None )
478464
479465 bootstrap .handle_event_request (
480466 self .lambda_runtime ,
@@ -488,14 +474,14 @@ def raise_exception_handler(json_input, lambda_context):
488474 0 ,
489475 bootstrap .StandardLogSink (),
490476 )
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+ )
492480
493481 self .assertEqual (mock_stdout .getvalue (), error_logs )
494482
495483 @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 ):
499485 def raise_exception_handler (json_input , lambda_context ):
500486 try :
501487 import invalid_module # noqa: F401
@@ -519,9 +505,7 @@ def raise_exception_handler(json_input, lambda_context):
519505 self .assertEqual (mock_stdout .getvalue (), error_logs )
520506
521507 @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 ):
525509 def raise_exception_handler (json_input , lambda_context ):
526510 try :
527511 import invalid_module # noqa: F401
@@ -545,9 +529,7 @@ def raise_exception_handler(json_input, lambda_context):
545529 self .assertEqual (mock_stdout .getvalue (), error_logs )
546530
547531 @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 ):
551533 def raise_exception_handler (json_input , lambda_context ):
552534 try :
553535 import invalid_module # noqa: F401
@@ -670,9 +652,7 @@ def __init__(self):
670652 self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["label" ], "test_method" )
671653 self .assertEqual (actual ["exceptions" ][0 ]["stack" ][0 ]["path" ], "test.py" )
672654 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" )
676656 self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["path" ], "another_test.py" )
677657 self .assertEqual (actual ["exceptions" ][0 ]["stack" ][1 ]["line" ], 2718 )
678658
@@ -682,9 +662,7 @@ class FaultExceptionMatcher(BaseException):
682662 def __init__ (self , msg , exception_type = None , trace_pattern = None ):
683663 self .msg = msg
684664 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 )
688666
689667 def __eq__ (self , other ):
690668 trace_matches = True
@@ -732,12 +710,8 @@ def test_get_event_handler_import_error(self):
732710
733711 def test_get_event_handler_syntax_error (self ):
734712 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')" )
741715 tmp_file .flush ()
742716
743717 filename_w_ext = os .path .basename (tmp_file .name )
@@ -759,9 +733,7 @@ def test_get_event_handler_syntax_error(self):
759733
760734 def test_get_event_handler_missing_error (self ):
761735 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 :
765737 tmp_file .write (b"def wrong_handler_name():\n \t print('hello')" )
766738 tmp_file .flush ()
767739
@@ -800,15 +772,11 @@ def test_get_event_handler_build_in_conflict(self):
800772 )
801773
802774 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" )
806776 response_handler ()
807777
808778 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" )
812780 response_handler ()
813781
814782
@@ -914,7 +882,9 @@ def test_log_error_standard_log_sink(self, mock_stdout):
914882
915883 def test_log_error_framed_log_sink (self ):
916884 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 :
918888 err_to_log = bootstrap .make_error ("Error message" , "ErrorType" , None )
919889 bootstrap .log_error (err_to_log , log_sink )
920890
@@ -949,7 +919,9 @@ def test_log_error_indentation_standard_log_sink(self, mock_stdout):
949919
950920 def test_log_error_indentation_framed_log_sink (self ):
951921 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 :
953925 err_to_log = bootstrap .make_error (
954926 "Error message" , "ErrorType" , [" line1 " , " line2 " , " " ]
955927 )
@@ -974,17 +946,17 @@ def test_log_error_indentation_framed_log_sink(self):
974946
975947 @patch ("sys.stdout" , new_callable = StringIO )
976948 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" ])
980950 bootstrap .log_error (err_to_log , bootstrap .StandardLogSink ())
981951
982952 expected_logged_error = "[ERROR] ErrorType: Error message\r Traceback (most recent call last):\r line1\r \r line2\n "
983953 self .assertEqual (mock_stdout .getvalue (), expected_logged_error )
984954
985955 def test_log_error_empty_stacktrace_line_framed_log_sink (self ):
986956 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 :
988960 err_to_log = bootstrap .make_error (
989961 "Error message" , "ErrorType" , ["line1" , "" , "line2" ]
990962 )
@@ -1082,7 +1054,9 @@ def test_create_framed_telemetry_log_sinks(self):
10821054 def test_single_frame (self ):
10831055 with NamedTemporaryFile () as temp_file :
10841056 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 :
10861060 ls .log (message )
10871061 with open (temp_file .name , "rb" ) as f :
10881062 content = f .read ()
@@ -1101,7 +1075,9 @@ def test_multiple_frame(self):
11011075 first_message = "hello world\n something on a new line!"
11021076 second_message = "hello again\n here's another message\n "
11031077
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 :
11051081 ls .log (first_message )
11061082 ls .log (second_message )
11071083
@@ -1141,9 +1117,7 @@ def test_run(self, mock_runtime_client, mock_handle_event_request):
11411117 ]
11421118
11431119 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 )
11471121
11481122 mock_handle_event_request .assert_called_once ()
11491123
@@ -1166,9 +1140,7 @@ class TestException(Exception):
11661140 mock_sys .exit .side_effect = TestException ("Boom!" )
11671141
11681142 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 )
11721144
11731145 mock_sys .exit .assert_called_once_with (1 )
11741146
0 commit comments