@@ -4263,6 +4263,28 @@ def raise_attribute_error_with_bad_name():
42634263 )
42644264 self .assertNotIn ("?" , result_lines [- 1 ])
42654265
4266+ def test_exception_punctuation_handling_with_suggestions (self ):
4267+ def raise_with_period (): raise NameError ("Error." , name = 'time' )
4268+ def raise_with_exclamation (): raise NameError ("Error!" , name = 'time' )
4269+ def raise_with_question (): raise NameError ("Error?" , name = 'time' )
4270+ def raise_without_punctuation (): raise NameError ("Error" , name = 'time' )
4271+
4272+ test_cases = [
4273+ (raise_with_period , "." ),
4274+ (raise_with_exclamation , "!" ),
4275+ (raise_with_question , "?" ),
4276+ (raise_without_punctuation , "." ),
4277+ ]
4278+
4279+ for raise_function , punctuation in test_cases :
4280+ with self .subTest (raise_func = raise_function .__name__ ):
4281+ result_lines = self .get_exception (
4282+ raise_function , slice_start = - 1 , slice_end = None
4283+ )
4284+ expected = f"NameError: Error{ punctuation } Did you forget to import 'time'?"
4285+ self .assertEqual (result_lines [0 ], expected )
4286+
4287+
42664288 def test_attribute_error_inside_nested_getattr (self ):
42674289 class A :
42684290 bluch = 1
0 commit comments