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

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

Issue 11682: PEP 380 reference implementation for 3.3
Left Patch Set: Created 7 years, 6 months ago
Right Patch Set: Created 7 years, 4 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 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 """ 3 """
4 Test suite for PEP 380 implementation 4 Test suite for PEP 380 implementation
5 5
6 adapted from original tests written by Greg Ewing 6 adapted from original tests written by Greg Ewing
7 see <http://www.cosc.canterbury.ac.nz/greg.ewing/python/yield-from/YieldFrom-Pyt hon3.1.2-rev5.zip> 7 see <http://www.cosc.canterbury.ac.nz/greg.ewing/python/yield-from/YieldFrom-Pyt hon3.1.2-rev5.zip>
8 """ 8 """
9 9
10 import unittest 10 import unittest
11 import io 11 import io
12 import sys 12 import sys
13 import traceback 13 import traceback
14 import parser 14 import parser
15 15
16 from test.bytecode_helper import BytecodeTestCase
17 from test.support import captured_stderr 16 from test.support import captured_stderr
18
19
20 class PEP380Test(unittest.TestCase):
21 pass
22
23
24 class TestPEP380Bytecode(BytecodeTestCase):
25 """
26 Test code generation
27 """
28
29 def test_ordinary_yield(self):
30 def g():
31 yield
32 yield 42
33 self.assertBytecodeMatches(g, (
34 ('LOAD_CONST', None),
35 ('YIELD_VALUE', None),
36 ('POP_TOP', None),
37 ('LOAD_CONST', 42),
38 ('YIELD_VALUE', None),
39 ('POP_TOP', None),
40 ('LOAD_CONST', None),
41 ('RETURN_VALUE', None),
42 ))
43
44 def test_bare_yield_from(self):
45 def g():
46 yield from x
47 self.assertBytecodeMatches(g, (
48 ('LOAD_GLOBAL', 'x'),
49 ('YIELD_FROM', None),
50 ('POP_TOP', None),
51 ('LOAD_CONST', None),
52 ('RETURN_VALUE', None),
53 ))
54
55 def test_yield_from_assigned_to_local(self):
56 def g():
57 x = yield from x
58 self.assertBytecodeMatches(g, (
59 ('LOAD_FAST', 'x'),
60 ('YIELD_FROM', None),
61 ('STORE_FAST', 'x'),
62 ('LOAD_CONST', None),
63 ('RETURN_VALUE', None),
64 ))
65
66 def test_parsing_yield_from_as_function_argument(self):
67 def g():
68 f(yield from x)
69 self.assertBytecodeMatches(g, (
70 ('LOAD_GLOBAL', 'f'),
71 ('LOAD_GLOBAL', 'x'),
72 ('YIELD_FROM', None),
73 ('CALL_FUNCTION', 1),
74 ('POP_TOP', None),
75 ('LOAD_CONST', None),
76 ('RETURN_VALUE', None),
77 ))
78
79 17
80 class TestPEP380Operation(unittest.TestCase): 18 class TestPEP380Operation(unittest.TestCase):
81 """ 19 """
82 Test semantics. 20 Test semantics.
83 """ 21 """
84 22
85 def test_delegation_of_initial_next_to_subgenerator(self): 23 def test_delegation_of_initial_next_to_subgenerator(self):
86 """ 24 """
87 Test delegation of initial next() call to subgenerator 25 Test delegation of initial next() call to subgenerator
88 """ 26 """
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 else: 827 else:
890 self.fail("subgenerator failed to raise ValueError") 828 self.fail("subgenerator failed to raise ValueError")
891 self.assertEqual(trace,[ 829 self.assertEqual(trace,[
892 "Enter g", 830 "Enter g",
893 "Enter f", 831 "Enter f",
894 ]) 832 ])
895 833
896 834
897 def test_main(): 835 def test_main():
898 from test import support 836 from test import support
899 test_classes = [TestPEP380Bytecode, TestPEP380Operation] 837 test_classes = [TestPEP380Operation]
900 support.run_unittest(*test_classes) 838 support.run_unittest(*test_classes)
901 839
902 840
903 if __name__ == '__main__': 841 if __name__ == '__main__':
904 test_main() 842 test_main()
LEFTRIGHT

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