@@ -603,43 +603,6 @@ def raise_exception_handler(json_input, lambda_context):
603
603
604
604
self .assertEqual (mock_stdout .getvalue (), error_logs )
605
605
606
- # The order of patches matter. Using MagicMock resets sys.stdout to the default.
607
- @patch ("importlib.import_module" )
608
- @patch ("sys.stdout" , new_callable = StringIO )
609
- def test_handle_event_request_fault_exception_logging_syntax_error (
610
- self , mock_stdout , mock_import_module
611
- ):
612
- try :
613
- eval ("-" )
614
- except SyntaxError as e :
615
- syntax_error = e
616
-
617
- mock_import_module .side_effect = syntax_error
618
-
619
- response_handler = bootstrap ._get_handler ("a.b" )
620
-
621
- bootstrap .handle_event_request (
622
- self .lambda_runtime ,
623
- response_handler ,
624
- "invoke_id" ,
625
- self .event_body ,
626
- "application/json" ,
627
- {},
628
- {},
629
- "invoked_function_arn" ,
630
- 0 ,
631
- bootstrap .StandardLogSink (),
632
- )
633
- error_logs = (
634
- lambda_unhandled_exception_warning_message
635
- + f"[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'a': { syntax_error } \r "
636
- )
637
- error_logs += "Traceback (most recent call last):\r "
638
- error_logs += ' File "<string>" Line 1\r '
639
- error_logs += " -\n "
640
-
641
- self .assertEqual (mock_stdout .getvalue (), error_logs )
642
-
643
606
644
607
class TestXrayFault (unittest .TestCase ):
645
608
def test_make_xray (self ):
@@ -717,10 +680,8 @@ def __eq__(self, other):
717
680
718
681
def test_get_event_handler_bad_handler (self ):
719
682
handler_name = "bad_handler"
720
- response_handler = bootstrap ._get_handler (handler_name )
721
683
with self .assertRaises (FaultException ) as cm :
722
- response_handler ()
723
-
684
+ response_handler = bootstrap ._get_handler (handler_name )
724
685
returned_exception = cm .exception
725
686
self .assertEqual (
726
687
self .FaultExceptionMatcher (
@@ -732,9 +693,8 @@ def test_get_event_handler_bad_handler(self):
732
693
733
694
def test_get_event_handler_import_error (self ):
734
695
handler_name = "no_module.handler"
735
- response_handler = bootstrap ._get_handler (handler_name )
736
696
with self .assertRaises (FaultException ) as cm :
737
- response_handler ( )
697
+ response_handler = bootstrap . _get_handler ( handler_name )
738
698
returned_exception = cm .exception
739
699
self .assertEqual (
740
700
self .FaultExceptionMatcher (
@@ -757,10 +717,9 @@ def test_get_event_handler_syntax_error(self):
757
717
filename_w_ext = os .path .basename (tmp_file .name )
758
718
filename , _ = os .path .splitext (filename_w_ext )
759
719
handler_name = "{}.syntax_error" .format (filename )
760
- response_handler = bootstrap ._get_handler (handler_name )
761
720
762
721
with self .assertRaises (FaultException ) as cm :
763
- response_handler ( )
722
+ response_handler = bootstrap . _get_handler ( handler_name )
764
723
returned_exception = cm .exception
765
724
self .assertEqual (
766
725
self .FaultExceptionMatcher (
@@ -782,9 +741,8 @@ def test_get_event_handler_missing_error(self):
782
741
filename_w_ext = os .path .basename (tmp_file .name )
783
742
filename , _ = os .path .splitext (filename_w_ext )
784
743
handler_name = "{}.my_handler" .format (filename )
785
- response_handler = bootstrap ._get_handler (handler_name )
786
744
with self .assertRaises (FaultException ) as cm :
787
- response_handler ( )
745
+ response_handler = bootstrap . _get_handler ( handler_name )
788
746
returned_exception = cm .exception
789
747
self .assertEqual (
790
748
self .FaultExceptionMatcher (
@@ -801,9 +759,8 @@ def test_get_event_handler_slash(self):
801
759
response_handler ()
802
760
803
761
def test_get_event_handler_build_in_conflict (self ):
804
- response_handler = bootstrap ._get_handler ("sys.hello" )
805
762
with self .assertRaises (FaultException ) as cm :
806
- response_handler ( )
763
+ response_handler = bootstrap . _get_handler ( "sys.hello" )
807
764
returned_exception = cm .exception
808
765
self .assertEqual (
809
766
self .FaultExceptionMatcher (
@@ -1452,9 +1409,8 @@ def test_set_log_level_with_dictConfig(self, mock_stderr, mock_stdout):
1452
1409
1453
1410
1454
1411
class TestBootstrapModule (unittest .TestCase ):
1455
- @patch ("awslambdaric.bootstrap.handle_event_request" )
1456
1412
@patch ("awslambdaric.bootstrap.LambdaRuntimeClient" )
1457
- def test_run (self , mock_runtime_client , mock_handle_event_request ):
1413
+ def test_run (self , mock_runtime_client ):
1458
1414
expected_app_root = "/tmp/test/app_root"
1459
1415
expected_handler = "app.my_test_handler"
1460
1416
expected_lambda_runtime_api_addr = "test_addr"
@@ -1467,12 +1423,12 @@ def test_run(self, mock_runtime_client, mock_handle_event_request):
1467
1423
MagicMock (),
1468
1424
]
1469
1425
1470
- with self .assertRaises (TypeError ) :
1426
+ with self .assertRaises (SystemExit ) as cm :
1471
1427
bootstrap .run (
1472
1428
expected_app_root , expected_handler , expected_lambda_runtime_api_addr
1473
1429
)
1474
1430
1475
- mock_handle_event_request . assert_called_once ( )
1431
+ self . assertEqual ( cm . exception . code , 1 )
1476
1432
1477
1433
@patch (
1478
1434
"awslambdaric.bootstrap.LambdaLoggerHandler" ,
0 commit comments