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

Delta Between Two Patch Sets: Lib/test/test_grammar.py

Issue 11682: PEP 380 reference implementation for 3.3
Left Patch Set: Created 8 years, 2 months ago
Right Patch Set: Created 7 years, 8 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 def test_return(self): 452 def test_return(self):
453 # 'return' [testlist] 453 # 'return' [testlist]
454 def g1(): return 454 def g1(): return
455 def g2(): return 1 455 def g2(): return 1
456 g1() 456 g1()
457 x = g2() 457 x = g2()
458 check_syntax_error(self, "class foo:return 1") 458 check_syntax_error(self, "class foo:return 1")
459 459
460 def test_yield(self): 460 def test_yield(self):
461 # Allowed as standalone statement
462 def g(): yield 1
463 def g(): yield from ()
464 # Allowed as RHS of assignment
465 def g(): x = yield 1
466 def g(): x = yield from ()
467 # Ordinary yield accepts implicit tuples
468 def g(): yield 1, 1
469 def g(): x = yield 1, 1
470 # 'yield from' does not
471 check_syntax_error(self, "def g(): yield from (), 1")
472 check_syntax_error(self, "def g(): x = yield from (), 1")
473 # Requires parentheses as subexpression
474 def g(): 1, (yield 1)
475 def g(): 1, (yield from ())
476 check_syntax_error(self, "def g(): 1, yield 1")
477 check_syntax_error(self, "def g(): 1, yield from ()")
478 # Requires parentheses as call argument
479 def g(): f((yield 1))
480 def g(): f((yield 1), 1)
481 def g(): f((yield from ()))
482 def g(): f((yield from ()), 1)
483 check_syntax_error(self, "def g(): f(yield 1)")
484 check_syntax_error(self, "def g(): f(yield 1, 1)")
485 check_syntax_error(self, "def g(): f(yield from ())")
486 check_syntax_error(self, "def g(): f(yield from (), 1)")
487 # Not allowed at top level
488 check_syntax_error(self, "yield")
489 check_syntax_error(self, "yield from")
490 # Not allowed at class scope
461 check_syntax_error(self, "class foo:yield 1") 491 check_syntax_error(self, "class foo:yield 1")
462 check_syntax_error(self, "yield from") 492 check_syntax_error(self, "class foo:yield from ()")
493
463 494
464 def test_raise(self): 495 def test_raise(self):
465 # 'raise' test [',' test] 496 # 'raise' test [',' test]
466 try: raise RuntimeError('just testing') 497 try: raise RuntimeError('just testing')
467 except RuntimeError: pass 498 except RuntimeError: pass
468 try: raise KeyboardInterrupt 499 try: raise KeyboardInterrupt
469 except KeyboardInterrupt: pass 500 except KeyboardInterrupt: pass
470 501
471 def test_import(self): 502 def test_import(self):
472 # 'import' dotted_as_names 503 # 'import' dotted_as_names
(...skipping 21 matching lines...) Expand all
494 def f(): 525 def f():
495 nonlocal x 526 nonlocal x
496 nonlocal x, y 527 nonlocal x, y
497 528
498 def test_assert(self): 529 def test_assert(self):
499 # assertTruestmt: 'assert' test [',' test] 530 # assertTruestmt: 'assert' test [',' test]
500 assert 1 531 assert 1
501 assert 1, 1 532 assert 1, 1
502 assert lambda x:x 533 assert lambda x:x
503 assert 1, lambda x:x+1 534 assert 1, lambda x:x+1
535
536 try:
537 assert True
538 except AssertionError as e:
539 self.fail("'assert True' should not have raised an AssertionError")
540
541 try:
542 assert True, 'this should always pass'
543 except AssertionError as e:
544 self.fail("'assert True, msg' should not have "
545 "raised an AssertionError")
546
547 # these tests fail if python is run with -O, so check __debug__
548 @unittest.skipUnless(__debug__, "Won't work if __debug__ is False")
549 def testAssert2(self):
504 try: 550 try:
505 assert 0, "msg" 551 assert 0, "msg"
506 except AssertionError as e: 552 except AssertionError as e:
507 self.assertEqual(e.args[0], "msg") 553 self.assertEqual(e.args[0], "msg")
508 else: 554 else:
509 if __debug__: 555 self.fail("AssertionError not raised by assert 0")
510 self.fail("AssertionError not raised by assert 0") 556
557 try:
558 assert False
559 except AssertionError as e:
560 self.assertEqual(len(e.args), 0)
561 else:
562 self.fail("AssertionError not raised by 'assert False'")
563
511 564
512 ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | cl assdef 565 ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | cl assdef
513 # Tested below 566 # Tested below
514 567
515 def test_if(self): 568 def test_if(self):
516 # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] 569 # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
517 if 1: pass 570 if 1: pass
518 if 1: pass 571 if 1: pass
519 else: pass 572 else: pass
520 if 0: pass 573 if 0: pass
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 self.assertTrue(False is (2 is 3)) 977 self.assertTrue(False is (2 is 3))
925 self.assertFalse((False is 2) is 3) 978 self.assertFalse((False is 2) is 3)
926 self.assertFalse(False is 2 is 3) 979 self.assertFalse(False is 2 is 3)
927 980
928 981
929 def test_main(): 982 def test_main():
930 run_unittest(TokenTests, GrammarTests) 983 run_unittest(TokenTests, GrammarTests)
931 984
932 if __name__ == '__main__': 985 if __name__ == '__main__':
933 test_main() 986 test_main()
LEFTRIGHT

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