Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-71339: Use new assertion methods in test_traceback #128848

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_caret(self):
err = self.get_exception_format(self.syntax_error_with_caret,
SyntaxError)
self.assertEqual(len(err), 4)
self.assertTrue(err[1].strip() == "return x!")
self.assertEqual(err[1].strip(), "return x!")
self.assertIn("^", err[2]) # third line has caret
self.assertEqual(err[1].find("!"), err[2].find("^")) # in the right place
self.assertEqual(err[2].count("^"), 1)
Expand Down Expand Up @@ -419,16 +419,10 @@ def do_test(firstlines, message, charset, lineno):
err_line = "raise RuntimeError('{0}')".format(message_ascii)
err_msg = "RuntimeError: {0}".format(message_ascii)

self.assertIn(("line %s" % lineno), stdout[1],
"Invalid line number: {0!r} instead of {1}".format(
stdout[1], lineno))
self.assertTrue(stdout[2].endswith(err_line),
"Invalid traceback line: {0!r} instead of {1!r}".format(
stdout[2], err_line))
self.assertIn("line %s" % lineno, stdout[1])
self.assertEndsWith(stdout[2], err_line)
actual_err_msg = stdout[3]
self.assertTrue(actual_err_msg == err_msg,
"Invalid error message: {0!r} instead of {1!r}".format(
actual_err_msg, err_msg))
self.assertEqual(actual_err_msg, err_msg)

do_test("", "foo", "ascii", 3)
for charset in ("ascii", "iso-8859-1", "utf-8", "GBK"):
Expand Down Expand Up @@ -1809,9 +1803,9 @@ def check_traceback_format(self, cleanup_func=None):
banner = tb_lines[0]
self.assertEqual(len(tb_lines), 5)
location, source_line = tb_lines[-2], tb_lines[-1]
self.assertTrue(banner.startswith('Traceback'))
self.assertTrue(location.startswith(' File'))
self.assertTrue(source_line.startswith(' raise'))
self.assertStartsWith(banner, 'Traceback')
self.assertStartsWith(location, ' File')
self.assertStartsWith(source_line, ' raise')

def test_traceback_format(self):
self.check_traceback_format()
Expand Down Expand Up @@ -2190,12 +2184,12 @@ def zero_div(self):
def check_zero_div(self, msg):
lines = msg.splitlines()
if has_no_debug_ranges():
self.assertTrue(lines[-3].startswith(' File'))
self.assertStartsWith(lines[-3], ' File')
self.assertIn('1/0 # In zero_div', lines[-2])
else:
self.assertTrue(lines[-4].startswith(' File'))
self.assertStartsWith(lines[-4], ' File')
self.assertIn('1/0 # In zero_div', lines[-3])
self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
self.assertStartsWith(lines[-1], 'ZeroDivisionError')

def test_simple(self):
try:
Expand All @@ -2205,12 +2199,12 @@ def test_simple(self):
lines = self.get_report(e).splitlines()
if has_no_debug_ranges():
self.assertEqual(len(lines), 4)
self.assertTrue(lines[3].startswith('ZeroDivisionError'))
self.assertStartsWith(lines[3], 'ZeroDivisionError')
else:
self.assertEqual(len(lines), 5)
self.assertTrue(lines[4].startswith('ZeroDivisionError'))
self.assertTrue(lines[0].startswith('Traceback'))
self.assertTrue(lines[1].startswith(' File'))
self.assertStartsWith(lines[4], 'ZeroDivisionError')
self.assertStartsWith(lines[0], 'Traceback')
self.assertStartsWith(lines[1], ' File')
self.assertIn('1/0 # Marker', lines[2])

def test_cause(self):
Expand Down Expand Up @@ -2251,9 +2245,9 @@ def test_context_suppression(self):
e = _
lines = self.get_report(e).splitlines()
self.assertEqual(len(lines), 4)
self.assertTrue(lines[3].startswith('ZeroDivisionError'))
self.assertTrue(lines[0].startswith('Traceback'))
self.assertTrue(lines[1].startswith(' File'))
self.assertStartsWith(lines[3], 'ZeroDivisionError')
self.assertStartsWith(lines[0], 'Traceback')
self.assertStartsWith(lines[1], ' File')
self.assertIn('ZeroDivisionError from None', lines[2])

def test_cause_and_context(self):
Expand Down
Loading