1010
1111from sagemaker .hyperpod .common .cli_decorators import (
1212 handle_cli_exceptions ,
13- handle_cli_exceptions_with_debug ,
14- smart_cli_exception_handler ,
1513 _detect_resource_type ,
1614 _detect_operation_type
1715)
@@ -56,50 +54,12 @@ def documented_function():
5654 assert documented_function .__doc__ == "This is a test function."
5755
5856
59- class TestHandleCliExceptionsWithDebug :
60- """Test handle_cli_exceptions_with_debug decorator."""
57+ class TestHandleCliExceptions404Handling :
58+ """Test handle_cli_exceptions decorator 404 handling functionality ."""
6159
6260 def test_successful_function_execution (self ):
6361 """Test decorator allows successful function execution."""
64- @handle_cli_exceptions_with_debug
65- def test_function ():
66- return "success"
67-
68- result = test_function ()
69- assert result == "success"
70-
71- @patch ('sagemaker.hyperpod.common.cli_decorators.click' )
72- @patch ('sagemaker.hyperpod.common.cli_decorators.sys' )
73- @patch ('sagemaker.hyperpod.common.cli_decorators.logger' )
74- def test_exception_handling_with_debug (self , mock_logger , mock_sys , mock_click ):
75- """Test decorator handles exceptions with debug logging."""
76- @handle_cli_exceptions_with_debug
77- def failing_function ():
78- raise Exception ("Debug test error" )
79-
80- failing_function ()
81-
82- mock_logger .debug .assert_called_once ()
83- mock_click .echo .assert_called_once_with ("Debug test error" )
84- mock_sys .exit .assert_called_once_with (1 )
85-
86- def test_preserves_function_metadata (self ):
87- """Test decorator preserves original function metadata."""
88- @handle_cli_exceptions_with_debug
89- def documented_function ():
90- """This is a debug test function."""
91- pass
92-
93- assert documented_function .__name__ == "documented_function"
94- assert documented_function .__doc__ == "This is a debug test function."
95-
96-
97- class TestSmartCliExceptionHandler :
98- """Test smart_cli_exception_handler decorator."""
99-
100- def test_successful_function_execution (self ):
101- """Test decorator allows successful function execution."""
102- @smart_cli_exception_handler
62+ @handle_cli_exceptions
10363 def test_function ():
10464 return "success"
10565
@@ -114,7 +74,7 @@ def test_404_exception_handling(self, mock_sys, mock_click, mock_handle_404):
11474 # Create 404 ApiException
11575 api_exception = ApiException (status = 404 , reason = "Not Found" )
11676
117- @smart_cli_exception_handler
77+ @handle_cli_exceptions
11878 def js_delete (name , namespace ):
11979 raise api_exception
12080
@@ -137,7 +97,7 @@ def js_delete(name, namespace):
13797 @patch ('sagemaker.hyperpod.common.cli_decorators.sys' )
13898 def test_non_404_exception_handling (self , mock_sys , mock_click ):
13999 """Test decorator handles non-404 exceptions normally."""
140- @smart_cli_exception_handler
100+ @handle_cli_exceptions
141101 def failing_function ():
142102 raise Exception ("Generic error" )
143103
@@ -150,7 +110,7 @@ def failing_function():
150110 @patch ('sagemaker.hyperpod.common.cli_decorators.sys' )
151111 def test_non_api_exception_handling (self , mock_sys , mock_click ):
152112 """Test decorator handles non-ApiException errors normally."""
153- @smart_cli_exception_handler
113+ @handle_cli_exceptions
154114 def failing_function ():
155115 raise ValueError ("Value error" )
156116
@@ -166,7 +126,7 @@ def test_404_detection_failure_fallback(self, mock_sys, mock_click, mock_handle_
166126 """Test decorator falls back when resource/operation detection fails."""
167127 api_exception = ApiException (status = 404 , reason = "Not Found" )
168128
169- @smart_cli_exception_handler
129+ @handle_cli_exceptions
170130 def unknown_function (name , namespace ):
171131 raise api_exception
172132
@@ -179,7 +139,7 @@ def unknown_function(name, namespace):
179139
180140 def test_preserves_function_metadata (self ):
181141 """Test decorator preserves original function metadata."""
182- @smart_cli_exception_handler
142+ @handle_cli_exceptions
183143 def documented_function ():
184144 """This is a smart test function."""
185145 pass
@@ -303,7 +263,7 @@ def test_complete_jumpstart_delete_flow(self, mock_sys, mock_click, mock_handle_
303263 api_exception = ApiException (status = 404 , reason = "Not Found" )
304264 mock_handle_404 .side_effect = Exception ("Enhanced 404 message" )
305265
306- @smart_cli_exception_handler
266+ @handle_cli_exceptions
307267 def js_delete (name , namespace = "default" ):
308268 raise api_exception
309269
@@ -327,7 +287,7 @@ def test_complete_custom_describe_flow(self, mock_sys, mock_click, mock_handle_4
327287 api_exception = ApiException (status = 404 , reason = "Not Found" )
328288 mock_handle_404 .side_effect = Exception ("Custom endpoint not found message" )
329289
330- @smart_cli_exception_handler
290+ @handle_cli_exceptions
331291 def custom_describe (name , namespace = "default" ):
332292 raise api_exception
333293
@@ -351,7 +311,7 @@ def test_complete_training_list_flow(self, mock_sys, mock_click, mock_handle_404
351311 api_exception = ApiException (status = 404 , reason = "Not Found" )
352312 mock_handle_404 .side_effect = Exception ("Training job not found message" )
353313
354- @smart_cli_exception_handler
314+ @handle_cli_exceptions
355315 def training_list (name , namespace = "default" ):
356316 raise api_exception
357317
@@ -371,7 +331,7 @@ def training_list(name, namespace="default"):
371331 @patch ('sagemaker.hyperpod.common.cli_decorators.sys' )
372332 def test_non_404_exception_passthrough (self , mock_sys , mock_click ):
373333 """Test non-404 exceptions are handled normally."""
374- @smart_cli_exception_handler
334+ @handle_cli_exceptions
375335 def js_delete (name , namespace = "default" ):
376336 raise ValueError ("Invalid configuration" )
377337
@@ -382,7 +342,7 @@ def js_delete(name, namespace="default"):
382342
383343 def test_function_with_no_exceptions (self ):
384344 """Test function that completes successfully."""
385- @smart_cli_exception_handler
345+ @handle_cli_exceptions
386346 def successful_function (name , namespace = "default" ):
387347 return f"Success: { name } in { namespace } "
388348
0 commit comments