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

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

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 3 months ago
Right Patch Set: Created 5 years, 10 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
« no previous file with change/comment | « Lib/test/test_pep3120.py ('k') | Lib/test/test_platform.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 inspect 13 import inspect
14 import parser 14 import parser
15 15
16 from test.support import captured_stderr 16 from test.support import captured_stderr, disable_gc, gc_collect
17 17
18 class TestPEP380Operation(unittest.TestCase): 18 class TestPEP380Operation(unittest.TestCase):
19 """ 19 """
20 Test semantics. 20 Test semantics.
21 """ 21 """
22 22
23 def test_delegation_of_initial_next_to_subgenerator(self): 23 def test_delegation_of_initial_next_to_subgenerator(self):
24 """ 24 """
25 Test delegation of initial next() call to subgenerator 25 Test delegation of initial next() call to subgenerator
26 """ 26 """
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 return self 948 return self
949 def __next__(self): 949 def __next__(self):
950 raise StopIteration(42) 950 raise StopIteration(42)
951 def gen(): 951 def gen():
952 nonlocal ret 952 nonlocal ret
953 ret = yield from MyIter() 953 ret = yield from MyIter()
954 ret = None 954 ret = None
955 list(gen()) 955 list(gen())
956 self.assertEqual(ret, 42) 956 self.assertEqual(ret, 42)
957 957
958 def test_close_with_cleared_frame(self):
959 # See issue #17669.
960 #
961 # Create a stack of generators: outer() delegating to inner()
962 # delegating to innermost(). The key point is that the instance of
963 # inner is created first: this ensures that its frame appears before
964 # the instance of outer in the GC linked list.
965 #
966 # At the gc.collect call:
967 # - frame_clear is called on the inner_gen frame.
968 # - gen_dealloc is called on the outer_gen generator (the only
969 # reference is in the frame's locals).
970 # - gen_close is called on the outer_gen generator.
971 # - gen_close_iter is called to close the inner_gen generator, which
972 # in turn calls gen_close, and gen_yf.
973 #
974 # Previously, gen_yf would crash since inner_gen's frame had been
975 # cleared (and in particular f_stacktop was NULL).
976
977 def innermost():
978 yield
979 def inner():
980 outer_gen = yield
981 yield from innermost()
982 def outer():
983 inner_gen = yield
984 yield from inner_gen
985
986 with disable_gc():
987 inner_gen = inner()
988 outer_gen = outer()
989 outer_gen.send(None)
990 outer_gen.send(inner_gen)
991 outer_gen.send(outer_gen)
992
993 del outer_gen
994 del inner_gen
995 gc_collect()
996
958 997
959 def test_main(): 998 def test_main():
960 from test import support 999 from test import support
961 test_classes = [TestPEP380Operation] 1000 test_classes = [TestPEP380Operation]
962 support.run_unittest(*test_classes) 1001 support.run_unittest(*test_classes)
963 1002
964 1003
965 if __name__ == '__main__': 1004 if __name__ == '__main__':
966 test_main() 1005 test_main()
LEFTRIGHT

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