Skip to content

Commit 2b18201

Browse files
Update test_run.py
1 parent ab7bf20 commit 2b18201

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Lib/idlelib/idle_test/test_run.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,24 @@ def __eq__(self, other):
4545
('int.reel', AttributeError,
4646
"type object 'int' has no attribute 'reel'. "
4747
"Did you mean: 'real'?\n"),
48+
('raise NameError("123\\n456")', NameError, "123\n456"),
4849
)
4950

5051
@force_not_colorized
5152
def test_get_message(self):
5253
for code, exc, msg in self.data:
5354
with self.subTest(code=code):
5455
try:
55-
eval(compile(code, '', 'eval'))
56+
if "raise " not in code:
57+
eval(compile(code, '', 'eval'))
58+
else:
59+
exec(compile(code, '', 'exec'))
5660
except exc:
57-
typ, val, tb = sys.exc_info()
58-
actual = run.get_message_lines(typ, val, tb)[0]
61+
if "raise " in code:
62+
actual = run.print_exception(in_test=True)
63+
else:
64+
typ, val, tb = sys.exc_info()
65+
actual = run.get_message_lines(typ, val, tb)[0]
5966
expect = f'{exc.__name__}: {msg}'
6067
self.assertEqual(actual, expect)
6168

0 commit comments

Comments
 (0)