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

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

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 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
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 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")
492 check_syntax_error(self, "class foo:yield from ()")
493
462 494
463 def test_raise(self): 495 def test_raise(self):
464 # 'raise' test [',' test] 496 # 'raise' test [',' test]
465 try: raise RuntimeError('just testing') 497 try: raise RuntimeError('just testing')
466 except RuntimeError: pass 498 except RuntimeError: pass
467 try: raise KeyboardInterrupt 499 try: raise KeyboardInterrupt
468 except KeyboardInterrupt: pass 500 except KeyboardInterrupt: pass
469 501
470 def test_import(self): 502 def test_import(self):
471 # 'import' dotted_as_names 503 # 'import' dotted_as_names
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 self.assertTrue(False is (2 is 3)) 977 self.assertTrue(False is (2 is 3))
946 self.assertFalse((False is 2) is 3) 978 self.assertFalse((False is 2) is 3)
947 self.assertFalse(False is 2 is 3) 979 self.assertFalse(False is 2 is 3)
948 980
949 981
950 def test_main(): 982 def test_main():
951 run_unittest(TokenTests, GrammarTests) 983 run_unittest(TokenTests, GrammarTests)
952 984
953 if __name__ == '__main__': 985 if __name__ == '__main__':
954 test_main() 986 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_generators.py ('k') | Lib/test/test_parser.py » ('j') | Modules/parsermodule.c » ('J')

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