Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(269882)

Side by Side Diff: Lib/test/test_traceback.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_time.py ('k') | Lib/test/test_trace.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Test cases for traceback module""" 1 """Test cases for traceback module"""
2 2
3 from io import StringIO 3 from io import StringIO
4 import sys 4 import sys
5 import unittest 5 import unittest
6 import re 6 import re
7 from test.support import run_unittest, Error, captured_output 7 from test.support import run_unittest, Error, captured_output
8 from test.support import TESTFN, unlink, cpython_only 8 from test.support import TESTFN, unlink, cpython_only
9 9
10 import traceback 10 import traceback
(...skipping 23 matching lines...) Expand all
34 def syntax_error_with_caret_non_ascii(self): 34 def syntax_error_with_caret_non_ascii(self):
35 compile('Python = "\u1e54\xfd\u0163\u0125\xf2\xf1" +', "?", "exec") 35 compile('Python = "\u1e54\xfd\u0163\u0125\xf2\xf1" +', "?", "exec")
36 36
37 def syntax_error_bad_indentation2(self): 37 def syntax_error_bad_indentation2(self):
38 compile(" print(2)", "?", "exec") 38 compile(" print(2)", "?", "exec")
39 39
40 def test_caret(self): 40 def test_caret(self):
41 err = self.get_exception_format(self.syntax_error_with_caret, 41 err = self.get_exception_format(self.syntax_error_with_caret,
42 SyntaxError) 42 SyntaxError)
43 self.assertEqual(len(err), 4) 43 self.assertEqual(len(err), 4)
44 self.assertTrue(err[1].strip() == "return x!") 44 self.assertEqual(err[1].strip(), "return x!")
45 self.assertIn("^", err[2]) # third line has caret 45 self.assertIn("^", err[2]) # third line has caret
46 self.assertEqual(err[1].find("!"), err[2].find("^")) # in the right plac e 46 self.assertEqual(err[1].find("!"), err[2].find("^")) # in the right plac e
47 47
48 err = self.get_exception_format(self.syntax_error_with_caret_2, 48 err = self.get_exception_format(self.syntax_error_with_caret_2,
49 SyntaxError) 49 SyntaxError)
50 self.assertIn("^", err[2]) # third line has caret 50 self.assertIn("^", err[2]) # third line has caret
51 self.assertEqual(err[2].count('\n'), 1) # and no additional newline 51 self.assertEqual(err[2].count('\n'), 1) # and no additional newline
52 self.assertEqual(err[1].find("+"), err[2].find("^")) # in the right pla ce 52 self.assertEqual(err[1].find("+"), err[2].find("^")) # in the right pla ce
53 53
54 err = self.get_exception_format(self.syntax_error_with_caret_non_ascii, 54 err = self.get_exception_format(self.syntax_error_with_caret_non_ascii,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 err_line = "raise RuntimeError('{0}')".format(message_ascii) 142 err_line = "raise RuntimeError('{0}')".format(message_ascii)
143 err_msg = "RuntimeError: {0}".format(message_ascii) 143 err_msg = "RuntimeError: {0}".format(message_ascii)
144 144
145 self.assertIn(("line %s" % lineno), stdout[1], 145 self.assertIn(("line %s" % lineno), stdout[1],
146 "Invalid line number: {0!r} instead of {1}".format( 146 "Invalid line number: {0!r} instead of {1}".format(
147 stdout[1], lineno)) 147 stdout[1], lineno))
148 self.assertTrue(stdout[2].endswith(err_line), 148 self.assertTrue(stdout[2].endswith(err_line),
149 "Invalid traceback line: {0!r} instead of {1!r}".format( 149 "Invalid traceback line: {0!r} instead of {1!r}".format(
150 stdout[2], err_line)) 150 stdout[2], err_line))
151 self.assertTrue(stdout[3] == err_msg, 151 self.assertEqual(stdout[3], err_msg,
152 "Invalid error message: {0!r} instead of {1!r}".format( 152 "Invalid error message: {0!r} instead of {1!r}".format(
153 stdout[3], err_msg)) 153 stdout[3], err_msg))
154 154
155 do_test("", "foo", "ascii", 3) 155 do_test("", "foo", "ascii", 3)
156 for charset in ("ascii", "iso-8859-1", "utf-8", "GBK"): 156 for charset in ("ascii", "iso-8859-1", "utf-8", "GBK"):
157 if charset == "ascii": 157 if charset == "ascii":
158 text = "foo" 158 text = "foo"
159 elif charset == "GBK": 159 elif charset == "GBK":
160 text = "\u4E02\u5100" 160 text = "\u4E02\u5100"
161 else: 161 else:
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 # Local variable dict should now be empty. 443 # Local variable dict should now be empty.
444 self.assertEqual(len(inner_frame.f_locals), 0) 444 self.assertEqual(len(inner_frame.f_locals), 0)
445 445
446 446
447 def test_main(): 447 def test_main():
448 run_unittest(__name__) 448 run_unittest(__name__)
449 449
450 if __name__ == "__main__": 450 if __name__ == "__main__":
451 test_main() 451 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_time.py ('k') | Lib/test/test_trace.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+