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

Side by Side Diff: Lib/test/test_grammar.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_gdb.py ('k') | Lib/test/test_gzip.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 # Python test set -- part 1, grammar. 1 # Python test set -- part 1, grammar.
2 # This just tests whether the parser accepts them all. 2 # This just tests whether the parser accepts them all.
3 3
4 from test.support import run_unittest, check_syntax_error 4 from test.support import run_unittest, check_syntax_error
5 import unittest 5 import unittest
6 import sys 6 import sys
7 # testing import * 7 # testing import *
8 from sys import * 8 from sys import *
9 9
10 10
(...skipping 14 matching lines...) Expand all
25 self.assertEqual(0xff, 255) 25 self.assertEqual(0xff, 255)
26 self.assertEqual(0o377, 255) 26 self.assertEqual(0o377, 255)
27 self.assertEqual(2147483647, 0o17777777777) 27 self.assertEqual(2147483647, 0o17777777777)
28 self.assertEqual(0b1001, 9) 28 self.assertEqual(0b1001, 9)
29 # "0x" is not a valid literal 29 # "0x" is not a valid literal
30 self.assertRaises(SyntaxError, eval, "0x") 30 self.assertRaises(SyntaxError, eval, "0x")
31 from sys import maxsize 31 from sys import maxsize
32 if maxsize == 2147483647: 32 if maxsize == 2147483647:
33 self.assertEqual(-2147483647-1, -0o20000000000) 33 self.assertEqual(-2147483647-1, -0o20000000000)
34 # XXX -2147483648 34 # XXX -2147483648
35 self.assertTrue(0o37777777777 > 0) 35 self.assertGreater(0o37777777777, 0)
36 self.assertTrue(0xffffffff > 0) 36 self.assertGreater(0xffffffff, 0)
37 self.assertTrue(0b1111111111111111111111111111111 > 0) 37 self.assertGreater(0b1111111111111111111111111111111, 0)
38 for s in ('2147483648', '0o40000000000', '0x100000000', 38 for s in ('2147483648', '0o40000000000', '0x100000000',
39 '0b10000000000000000000000000000000'): 39 '0b10000000000000000000000000000000'):
40 try: 40 try:
41 x = eval(s) 41 x = eval(s)
42 except OverflowError: 42 except OverflowError:
43 self.fail("OverflowError on huge integer literal %r" % s) 43 self.fail("OverflowError on huge integer literal %r" % s)
44 elif maxsize == 9223372036854775807: 44 elif maxsize == 9223372036854775807:
45 self.assertEqual(-9223372036854775807-1, -0o1000000000000000000000) 45 self.assertEqual(-9223372036854775807-1, -0o1000000000000000000000)
46 self.assertTrue(0o1777777777777777777777 > 0) 46 self.assertGreater(0o1777777777777777777777, 0)
47 self.assertTrue(0xffffffffffffffff > 0) 47 self.assertGreater(0xffffffffffffffff, 0)
48 self.assertTrue(0b11111111111111111111111111111111111111111111111111 111111111111 > 0) 48 self.assertGreater(0b11111111111111111111111111111111111111111111111 111111111111111, 0)
49 for s in '9223372036854775808', '0o2000000000000000000000', \ 49 for s in '9223372036854775808', '0o2000000000000000000000', \
50 '0x10000000000000000', \ 50 '0x10000000000000000', \
51 '0b10000000000000000000000000000000000000000000000000000000 0000000': 51 '0b10000000000000000000000000000000000000000000000000000000 0000000':
52 try: 52 try:
53 x = eval(s) 53 x = eval(s)
54 except OverflowError: 54 except OverflowError:
55 self.fail("OverflowError on huge integer literal %r" % s) 55 self.fail("OverflowError on huge integer literal %r" % s)
56 else: 56 else:
57 self.fail('Weird maxsize value %r' % maxsize) 57 self.fail('Weird maxsize value %r' % maxsize)
58 58
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 y = '\n\ 115 y = '\n\
116 The \"quick\"\n\ 116 The \"quick\"\n\
117 brown fox\n\ 117 brown fox\n\
118 jumps over\n\ 118 jumps over\n\
119 the \'lazy\' dog.\n\ 119 the \'lazy\' dog.\n\
120 ' 120 '
121 self.assertEqual(x, y) 121 self.assertEqual(x, y)
122 122
123 def test_ellipsis(self): 123 def test_ellipsis(self):
124 x = ... 124 x = ...
125 self.assertTrue(x is Ellipsis) 125 self.assertIs(x, Ellipsis)
126 self.assertRaises(SyntaxError, eval, ".. .") 126 self.assertRaises(SyntaxError, eval, ".. .")
127 127
128 def test_eof_error(self): 128 def test_eof_error(self):
129 samples = ("def foo(", "\ndef foo(", "def foo(\n") 129 samples = ("def foo(", "\ndef foo(", "def foo(\n")
130 for s in samples: 130 for s in samples:
131 with self.assertRaises(SyntaxError) as cm: 131 with self.assertRaises(SyntaxError) as cm:
132 compile(s, "<test>", "exec") 132 compile(s, "<test>", "exec")
133 self.assertIn("unexpected EOF", str(cm.exception)) 133 self.assertIn("unexpected EOF", str(cm.exception))
134 134
135 class GrammarTests(unittest.TestCase): 135 class GrammarTests(unittest.TestCase):
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 self.assertTrue(False is (2 is 3)) 977 self.assertTrue(False is (2 is 3))
978 self.assertFalse((False is 2) is 3) 978 self.assertFalse((False is 2) is 3)
979 self.assertFalse(False is 2 is 3) 979 self.assertFalse(False is 2 is 3)
980 980
981 981
982 def test_main(): 982 def test_main():
983 run_unittest(TokenTests, GrammarTests) 983 run_unittest(TokenTests, GrammarTests)
984 984
985 if __name__ == '__main__': 985 if __name__ == '__main__':
986 test_main() 986 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_gdb.py ('k') | Lib/test/test_gzip.py » ('j') | no next file with comments »

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