Skip to content

Commit 5849913

Browse files
test: add test_exception_punctuation_handling_with_suggestions
1 parent c22677e commit 5849913

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Lib/test/test_traceback.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,28 +4263,6 @@ 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-
42884266
def test_attribute_error_inside_nested_getattr(self):
42894267
class A:
42904268
bluch = 1
@@ -4900,6 +4878,28 @@ class PurePythonSuggestionFormattingTests(
49004878
traceback printing in traceback.py.
49014879
"""
49024880

4881+
def test_exception_punctuation_handling_with_suggestions(self):
4882+
def raise_with_period(): raise NameError("Error.", name='time')
4883+
def raise_with_exclamation(): raise NameError("Error!", name='time')
4884+
def raise_with_question(): raise NameError("Error?", name='time')
4885+
def raise_without_punctuation(): raise NameError("Error", name='time')
4886+
4887+
test_cases = [
4888+
(raise_with_period, "."),
4889+
(raise_with_exclamation, "!"),
4890+
(raise_with_question, "?"),
4891+
(raise_without_punctuation, "."),
4892+
]
4893+
4894+
for raise_function, punctuation in test_cases:
4895+
with self.subTest(raise_func=raise_function.__name__):
4896+
result_lines = self.get_exception(
4897+
raise_function, slice_start=-1, slice_end=None
4898+
)
4899+
expected = f"NameError: Error{punctuation} Did you forget to import 'time'?"
4900+
self.assertEqual(result_lines[0], expected)
4901+
4902+
49034903

49044904
@cpython_only
49054905
class CPythonSuggestionFormattingTests(

0 commit comments

Comments
 (0)