1. rndblnch
  2. cpython-pep380

Commits

rndblnch  committed 317eadf

factorized test adaptation

  • Participants
  • Parent commits 25c6371
  • Branches default

Comments (0)

Files changed (1)

File pep380-tests

View file
  • Ignore whitespace
 
 diff -r 744b89eef9dd Lib/test/test_pep380.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/Lib/test/test_pep380.py	Wed Jun 29 02:22:23 2011 +0200
-@@ -0,0 +1,1227 @@
++++ b/Lib/test/test_pep380.py	Thu Jun 30 23:45:00 2011 +0200
+@@ -0,0 +1,1091 @@
 +# -*- coding: utf-8 -*-
 +
-+
 +"""
 +Test suite for PEP 380 implementation
 +
 +        self.out = io.StringIO()
 +        sys.stdout = sys.stderr = self.out
 +    
++    def test(self):
++        try:
++            self.case()
++        except:
++            et, ev, tb = sys.exc_info()
++            tb = tb.tb_next
++            traceback.print_exception(et, ev, tb)
++    
++        self.assertEqual(self.out.getvalue(),
++                         self.expected)
++    
 +    def tearDown(self):
 +        sys.stdout = sys.__stdout__
 +        sys.stderr = sys.__stderr__
 +    """
 +    Test grammar and code generation
 +    """
++    
 +    expected = """\
 +---------- g1 ----------
-+%3i           0 LOAD_CONST               0 (None) 
++ 73           0 LOAD_CONST               0 (None) 
 +              3 YIELD_VALUE          
 +              4 POP_TOP              
 +
-+%3i           5 LOAD_CONST               1 (42) 
++ 74           5 LOAD_CONST               1 (42) 
 +              8 YIELD_VALUE          
 +              9 POP_TOP              
 +             10 LOAD_CONST               0 (None) 
 +             13 RETURN_VALUE         
 +---------- g2 ----------
-+%3i           0 LOAD_GLOBAL              0 (x) 
++ 77           0 LOAD_GLOBAL              0 (x) 
 +              3 YIELD_FROM           
 +              4 POP_TOP              
 +              5 LOAD_CONST               0 (None) 
 +              8 RETURN_VALUE         
 +---------- g3 ----------
-+%3i           0 LOAD_FAST                0 (x) 
++ 80           0 LOAD_FAST                0 (x) 
 +              3 YIELD_FROM           
 +              4 STORE_FAST               0 (x) 
 +              7 LOAD_CONST               0 (None) 
 +             10 RETURN_VALUE         
-+"""
++""".format(__file__)
 +
-+    def test_1(self):
-+        try:
-+            import dis
-+            
-+            def g1():
-+                yield
-+                yield 42
-+            
-+            def g2():
-+                yield from x
-+            
-+            def g3():
-+                x = yield from x
-+            
-+            def disgen(g):
-+                print("---------- %s ----------" % g.__name__)
-+                dis.dis(g)
-+            
-+            disgen(g1)
-+            disgen(g2)
-+            disgen(g3)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
++    def case(self):
++        import dis
++        
++        def g1():
++            yield
++            yield 42
++        
++        def g2():
++            yield from x
++        
++        def g3():
++            x = yield from x
++        
++        def disgen(g):
++            print("---------- %s ----------" % g.__name__)
++            dis.dis(g)
++        
++        disgen(g1)
++        disgen(g2)
++        disgen(g3)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected % (g1.__code__.co_firstlineno+1,
-+                                          g1.__code__.co_firstlineno+2,
-+                                          g2.__code__.co_firstlineno+1,
-+                                          g3.__code__.co_firstlineno+1))
 +
 +class Test2(PEP380Test):
 +    """
 +    Test delegation of initial next() call to subgenerator
 +    """
++    
 +    expected = """\
 +Starting g1
 +Starting g2
 +Finishing g2
 +Finishing g1
 +""".format(__file__)
-+    def test_2(self):
-+        try:
-+            def g1():
-+                print("Starting g1")
-+                yield from g2()
-+                print("Finishing g1")
-+            
-+            def g2():
-+                print("Starting g2")
-+                yield 42
-+                print("Finishing g2")
-+            
-+            for x in g1():
-+                print("Yielded", x)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            print("Starting g1")
++            yield from g2()
++            print("Finishing g1")
++        
++        def g2():
++            print("Starting g2")
++            yield 42
++            print("Finishing g2")
++        
++        for x in g1():
++            print("Yielded", x)
++
 +
 +class Test3(PEP380Test):
 +    """
 +    Test raising exception in initial next() call
 +    """
++    
 +    expected = """\
 +Starting g1
 +Starting g2
 +Finishing g2
 +Finishing g1
 +Traceback (most recent call last):
-+  File "{0}", line 155, in test_3
++  File "{0}", line 154, in case
 +    for x in g1():
-+  File "{0}", line 144, in g1
++  File "{0}", line 143, in g1
 +    yield from g2()
-+  File "{0}", line 151, in g2
++  File "{0}", line 150, in g2
 +    raise ValueError("spanish inquisition occurred")
 +ValueError: spanish inquisition occurred
 +""".format(__file__)
-+    def test_3(self):
-+        try:
-+            def g1():
-+                try:
-+                    print("Starting g1")
-+                    yield from g2()
-+                finally:
-+                    print("Finishing g1")
-+            
-+            def g2():
-+                try:
-+                    print("Starting g2")
-+                    raise ValueError("spanish inquisition occurred")
-+                finally:
-+                    print("Finishing g2")
-+            
-+            for x in g1():
-+                print("Yielded", x)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            try:
++                print("Starting g1")
++                yield from g2()
++            finally:
++                print("Finishing g1")
++        
++        def g2():
++            try:
++                print("Starting g2")
++                raise ValueError("spanish inquisition occurred")
++            finally:
++                print("Finishing g2")
++        
++        for x in g1():
++            print("Yielded", x)
 +
 +
 +class Test4(PEP380Test):
 +    """
 +    Test delegation of next() call to subgenerator
 +    """
++    
 +    expected = """\
 +Starting g1
 +Yielded g1 ham
 +Yielded g1 eggs
 +Finishing g1
 +""".format(__file__)
-+    def test_4(self):
-+        try:
-+            
-+            def g1():
-+                print("Starting g1")
-+                yield "g1 ham"
-+                yield from g2()
-+                yield "g1 eggs"
-+                print("Finishing g1")
-+            
-+            def g2():
-+                print("Starting g2")
-+                yield "g2 spam"
-+                yield "g2 more spam"
-+                print("Finishing g2")
-+            
-+            for x in g1():
-+                print("Yielded", x)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        
++        def g1():
++            print("Starting g1")
++            yield "g1 ham"
++            yield from g2()
++            yield "g1 eggs"
++            print("Finishing g1")
++        
++        def g2():
++            print("Starting g2")
++            yield "g2 spam"
++            yield "g2 more spam"
++            print("Finishing g2")
++        
++        for x in g1():
++            print("Yielded", x)
 +
 +
 +class Test5(PEP380Test):
 +    """
 +    Test raising exception in delegated next() call
 +    """
++    
 +    expected = """\
 +Starting g1
 +Yielded g1 ham
 +Finishing g2
 +Finishing g1
 +Traceback (most recent call last):
-+  File "{0}", line 245, in test_5
++  File "{0}", line 234, in case
 +    for x in g1():
-+  File "{0}", line 231, in g1
++  File "{0}", line 220, in g1
 +    yield from g2()
-+  File "{0}", line 240, in g2
++  File "{0}", line 229, in g2
 +    raise ValueError("hovercraft is full of eels")
 +ValueError: hovercraft is full of eels
 +""".format(__file__)
-+    def test_5(self):
-+        try:
-+            def g1():
-+                try:
-+                    print("Starting g1")
-+                    yield "g1 ham"
-+                    yield from g2()
-+                    yield "g1 eggs"
-+                finally:
-+                    print("Finishing g1")
-+            
-+            def g2():
-+                try:
-+                    print("Starting g2")
-+                    yield "g2 spam"
-+                    raise ValueError("hovercraft is full of eels")
-+                    yield "g2 more spam"
-+                finally:
-+                    print("Finishing g2")
-+            
-+            for x in g1():
-+                print("Yielded", x)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            try:
++                print("Starting g1")
++                yield "g1 ham"
++                yield from g2()
++                yield "g1 eggs"
++            finally:
++                print("Finishing g1")
++        
++        def g2():
++            try:
++                print("Starting g2")
++                yield "g2 spam"
++                raise ValueError("hovercraft is full of eels")
++                yield "g2 more spam"
++            finally:
++                print("Finishing g2")
++        
++        for x in g1():
++            print("Yielded", x)
 +
 +
 +class Test6(PEP380Test):
 +    """
 +    Test delegation of send()
 +    """
++    
 +    expected = """\
 +Starting g1
 +g1 received 1
 +g1 received 4
 +Finishing g1
 +""".format(__file__)
-+    def test_6(self):
++
++    def case(self):
++        def g1():
++            print("Starting g1")
++            x = yield "g1 ham"
++            print("g1 received", x)
++            yield from g2()
++            x = yield "g1 eggs"
++            print("g1 received", x)
++            print("Finishing g1")
++        
++        def g2():
++            print("Starting g2")
++            x = yield "g2 spam"
++            print("g2 received", x)
++            x = yield "g2 more spam"
++            print("g2 received", x)
++            print("Finishing g2")
++        
++        g = g1()
++        y = next(g)
++        x = 1
 +        try:
-+            def g1():
-+                print("Starting g1")
-+                x = yield "g1 ham"
-+                print("g1 received", x)
-+                yield from g2()
-+                x = yield "g1 eggs"
-+                print("g1 received", x)
-+                print("Finishing g1")
-+            
-+            def g2():
-+                print("Starting g2")
-+                x = yield "g2 spam"
-+                print("g2 received", x)
-+                x = yield "g2 more spam"
-+                print("g2 received", x)
-+                print("Finishing g2")
-+            
-+            g = g1()
-+            y = next(g)
-+            x = 1
-+            try:
-+                while 1:
-+                    y = g.send(x)
-+                    print("Yielded", y)
-+                    x += 1
-+            except StopIteration:
-+                pass
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
-+
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++            while 1:
++                y = g.send(x)
++                print("Yielded", y)
++                x += 1
++        except StopIteration:
++            pass
 +
 +
 +class Test7(PEP380Test):
 +    """
 +    Test handling exception while delegating 'send'
 +    """
++    
 +    expected = """\
 +Starting g1
 +g1 received 1
 +Yielded g2 spam
 +g2 received 2
 +Traceback (most recent call last):
-+  File "{0}", line 353, in test_7
++  File "{0}", line 332, in case
 +    y = g.send(x)
-+  File "{0}", line 334, in g1
++  File "{0}", line 313, in g1
 +    yield from g2()
-+  File "{0}", line 343, in g2
++  File "{0}", line 322, in g2
 +    raise ValueError("hovercraft is full of eels")
 +ValueError: hovercraft is full of eels
 +""".format(__file__)
-+    def test_7(self):
++
++    def case(self):
++        def g1():
++            print("Starting g1")
++            x = yield "g1 ham"
++            print("g1 received", x)
++            yield from g2()
++            x = yield "g1 eggs"
++            print("g1 received", x)
++            print("Finishing g1")
++        
++        def g2():
++            print("Starting g2")
++            x = yield "g2 spam"
++            print("g2 received", x)
++            raise ValueError("hovercraft is full of eels")
++            x = yield "g2 more spam"
++            print("g2 received", x)
++            print("Finishing g2")
++        
++        g = g1()
++        y = next(g)
++        x = 1
 +        try:
-+            def g1():
-+                print("Starting g1")
-+                x = yield "g1 ham"
-+                print("g1 received", x)
-+                yield from g2()
-+                x = yield "g1 eggs"
-+                print("g1 received", x)
-+                print("Finishing g1")
-+            
-+            def g2():
-+                print("Starting g2")
-+                x = yield "g2 spam"
-+                print("g2 received", x)
-+                raise ValueError("hovercraft is full of eels")
-+                x = yield "g2 more spam"
-+                print("g2 received", x)
-+                print("Finishing g2")
-+            
-+            g = g1()
-+            y = next(g)
-+            x = 1
-+            try:
-+                while 1:
-+                    y = g.send(x)
-+                    print("Yielded", y)
-+                    x += 1
-+            except StopIteration:
-+                print("StopIteration")
-+            
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
-+
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++            while 1:
++                y = g.send(x)
++                print("Yielded", y)
++                x += 1
++        except StopIteration:
++            print("StopIteration")
++        
 +
 +
 +class Test8(PEP380Test):
 +    """
 +    Test delegating 'close'
 +    """
++    
 +    expected = """\
 +Starting g1
 +Yielded g1 ham
 +Finishing g2
 +Finishing g1
 +""".format(__file__)
-+    def test_8(self):
-+        try:
-+            def g1():
-+                try:
-+                    print("Starting g1")
-+                    yield "g1 ham"
-+                    yield from g2()
-+                    yield "g1 eggs"
-+                finally:
-+                    print("Finishing g1")
-+            
-+            def g2():
-+                try:
-+                    print("Starting g2")
-+                    yield "g2 spam"
-+                    yield "g2 more spam"
-+                finally:
-+                    print("Finishing g2")
-+            
-+            g = g1()
-+            for i in range(2):
-+                x = next(g)
-+                print("Yielded", x)
-+            g.close()
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            try:
++                print("Starting g1")
++                yield "g1 ham"
++                yield from g2()
++                yield "g1 eggs"
++            finally:
++                print("Finishing g1")
++        
++        def g2():
++            try:
++                print("Starting g2")
++                yield "g2 spam"
++                yield "g2 more spam"
++            finally:
++                print("Finishing g2")
++        
++        g = g1()
++        for i in range(2):
++            x = next(g)
++            print("Yielded", x)
++        g.close()
 +
 +
 +class Test9(PEP380Test):
 +    """
 +    Test handling exception while delegating 'close'
 +    """
++    
 +    expected = """\
 +Starting g1
 +Yielded g1 ham
 +Finishing g2
 +Finishing g1
 +Traceback (most recent call last):
-+  File "{0}", line 452, in g2
++  File "{0}", line 421, in g2
 +    yield "g2 spam"
 +GeneratorExit
 +
 +During handling of the above exception, another exception occurred:
 +
 +Traceback (most recent call last):
-+  File "{0}", line 462, in test_9
++  File "{0}", line 431, in case
 +    g.close()
-+  File "{0}", line 444, in g1
++  File "{0}", line 413, in g1
 +    yield from g2()
-+  File "{0}", line 456, in g2
++  File "{0}", line 425, in g2
 +    raise ValueError("nybbles have exploded with delight")
 +ValueError: nybbles have exploded with delight
 +""".format(__file__)
-+    def test_9(self):
-+        try:
-+            def g1():
-+                try:
-+                    print("Starting g1")
-+                    yield "g1 ham"
-+                    yield from g2()
-+                    yield "g1 eggs"
-+                finally:
-+                    print("Finishing g1")
-+            
-+            def g2():
-+                try:
-+                    print("Starting g2")
-+                    yield "g2 spam"
-+                    yield "g2 more spam"
-+                finally:
-+                    print("Finishing g2")
-+                    raise ValueError("nybbles have exploded with delight")
-+            
-+            g = g1()
-+            for i in range(2):
-+                x = next(g)
-+                print("Yielded", x)
-+            g.close()
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            try:
++                print("Starting g1")
++                yield "g1 ham"
++                yield from g2()
++                yield "g1 eggs"
++            finally:
++                print("Finishing g1")
++        
++        def g2():
++            try:
++                print("Starting g2")
++                yield "g2 spam"
++                yield "g2 more spam"
++            finally:
++                print("Finishing g2")
++                raise ValueError("nybbles have exploded with delight")
++        
++        g = g1()
++        for i in range(2):
++            x = next(g)
++            print("Yielded", x)
++        g.close()
 +
 +
 +class Test10(PEP380Test):
 +    """
 +    Test delegating 'throw'
 +    """
++    
 +    expected = """\
 +Starting g1
 +Yielded g1 ham
 +Finishing g2
 +Finishing g1
 +Traceback (most recent call last):
-+  File "{0}", line 515, in test_10
++  File "{0}", line 479, in case
 +    g.throw(e)
-+  File "{0}", line 497, in g1
++  File "{0}", line 461, in g1
 +    yield from g2()
-+  File "{0}", line 505, in g2
++  File "{0}", line 469, in g2
 +    yield "g2 spam"
 +ValueError: tomato ejected
 +""".format(__file__)
-+    def test_10(self):
-+        try:
-+            def g1():
-+                try:
-+                    print("Starting g1")
-+                    yield "g1 ham"
-+                    yield from g2()
-+                    yield "g1 eggs"
-+                finally:
-+                    print("Finishing g1")
-+            
-+            def g2():
-+                try:
-+                    print("Starting g2")
-+                    yield "g2 spam"
-+                    yield "g2 more spam"
-+                finally:
-+                    print("Finishing g2")
-+            
-+            g = g1()
-+            for i in range(2):
-+                x = next(g)
-+                print("Yielded", x)
-+            e = ValueError("tomato ejected")
-+            g.throw(e)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            try:
++                print("Starting g1")
++                yield "g1 ham"
++                yield from g2()
++                yield "g1 eggs"
++            finally:
++                print("Finishing g1")
++        
++        def g2():
++            try:
++                print("Starting g2")
++                yield "g2 spam"
++                yield "g2 more spam"
++            finally:
++                print("Finishing g2")
++        
++        g = g1()
++        for i in range(2):
++            x = next(g)
++            print("Yielded", x)
++        e = ValueError("tomato ejected")
++        g.throw(e)
 +
 +
 +class Test11(PEP380Test):
 +    """
 +    Test 'value' attribute of StopIteration exception
 +    """
++    
 +    expected = """\
 +StopIteration: 
 +value = None
 +StopIteration: spam
 +value = eggs
 +""".format(__file__)
-+    def test_11(self):
-+        try:
-+            def pex(e):
-+                print("%s: %s" % (e.__class__.__name__, e))
-+                print("value =", e.value)
-+            
-+            e = StopIteration()
-+            pex(e)
-+            e = StopIteration("spam")
-+            pex(e)
-+            e.value = "eggs"
-+            pex(e)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def pex(e):
++            print("%s: %s" % (e.__class__.__name__, e))
++            print("value =", e.value)
++        
++        e = StopIteration()
++        pex(e)
++        e = StopIteration("spam")
++        pex(e)
++        e.value = "eggs"
++        pex(e)
 +
 +
 +class Test12(PEP380Test):
 +    """
 +    Test generator return value
 +    """
++    
 +    expected = """\
 +Starting g1
 +Yielded g1 ham
 +Yielded g1 eggs
 +Finishing g1
 +""".format(__file__)
-+    def test_12(self):
-+        try:
-+            def g1():
-+                print("Starting g1")
-+                yield "g1 ham"
-+                ret = yield from g2()
-+                print("g2 returned", ret)
-+                ret = yield from g2(42)
-+                print("g2 returned", ret)
-+                yield "g1 eggs"
-+                print("Finishing g1")
-+            
-+            def g2(v = None):
-+                print("Starting g2")
-+                yield "g2 spam"
-+                yield "g2 more spam"
-+                print("Finishing g2")
-+                if v:
-+                    return v
-+            
-+            for x in g1():
-+                print("Yielded", x)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            print("Starting g1")
++            yield "g1 ham"
++            ret = yield from g2()
++            print("g2 returned", ret)
++            ret = yield from g2(42)
++            print("g2 returned", ret)
++            yield "g1 eggs"
++            print("Finishing g1")
++        
++        def g2(v = None):
++            print("Starting g2")
++            yield "g2 spam"
++            yield "g2 more spam"
++            print("Finishing g2")
++            if v:
++                return v
++        
++        for x in g1():
++            print("Yielded", x)
 +
 +
 +class Test13(PEP380Test):
 +    """
 +    Test delegation of next() to non-generator
 +    """
++    
 +    expected = """\
 +Yielded 0
 +Yielded 1
 +Yielded 2
 +""".format(__file__)
-+    def test_13(self):
-+        try:
-+            def g():
-+                yield from range(3)
-+            
-+            for x in g():
-+                print("Yielded", x)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g():
++            yield from range(3)
++        
++        for x in g():
++            print("Yielded", x)
 +
 +
 +class Test14(PEP380Test):
 +    """
 +    Test conversion of send(None) to next()
 +    """
++    
 +    expected = """\
 +Yielded: 0
 +Yielded: 1
 +Yielded: 2
 +""".format(__file__)
-+    def test_14(self):
-+        try:
-+            def g():
-+                yield from range(3)
-+            
-+            gi = g()
-+            for x in range(3):
-+                y = gi.send(None)
-+                print("Yielded:", y)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g():
++            yield from range(3)
++        
++        gi = g()
++        for x in range(3):
++            y = gi.send(None)
++            print("Yielded:", y)
 +
 +
 +class Test15(PEP380Test):
 +    """
 +    Test delegation of close() to non-generator
 +    """
++    
 +    expected = """\
 +starting g
 +finishing g
 +""".format(__file__)
-+    def test_15(self):
-+        try:
-+            def g():
-+                try:
-+                    print("starting g")
-+                    yield from range(3)
-+                    print("g should not be here")
-+                finally:
-+                    print("finishing g")
-+            
-+            gi = g()
-+            next(gi)
-+            gi.close()
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g():
++            try:
++                print("starting g")
++                yield from range(3)
++                print("g should not be here")
++            finally:
++                print("finishing g")
++        
++        gi = g()
++        next(gi)
++        gi.close()
 +
 +
 +class Test16(PEP380Test):
 +    """
 +    Test delegating 'throw' to non-generator
 +    """
++    
 +    expected = """\
 +Starting g
 +Yielded 0
 +Yielded 4
 +Finishing g
 +Traceback (most recent call last):
-+  File "{0}", line 718, in test_16
++  File "{0}", line 652, in case
 +    gi.throw(e)
-+  File "{0}", line 709, in g
++  File "{0}", line 643, in g
 +    yield from range(10)
 +ValueError: tomato ejected
 +""".format(__file__)
-+    def test_16(self):
-+        try:
-+            def g():
-+                try:
-+                    print("Starting g")
-+                    yield from range(10)
-+                finally:
-+                    print("Finishing g")
-+            
-+            gi = g()
-+            for i in range(5):
-+                x = next(gi)
-+                print("Yielded", x)
-+            e = ValueError("tomato ejected")
-+            gi.throw(e)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g():
++            try:
++                print("Starting g")
++                yield from range(10)
++            finally:
++                print("Finishing g")
++        
++        gi = g()
++        for i in range(5):
++            x = next(gi)
++            print("Yielded", x)
++        e = ValueError("tomato ejected")
++        gi.throw(e)
 +
 +
 +class Test17(PEP380Test):
 +    """
 +    Test attempting to send to non-generator
 +    """
++    
 +    expected = """\
 +starting g
 +finishing g
 +Traceback (most recent call last):
-+  File "{0}", line 754, in test_17
++  File "{0}", line 683, in case
 +    y = gi.send(42)
-+  File "{0}", line 746, in g
++  File "{0}", line 675, in g
 +    yield from range(3)
 +AttributeError: send
 +""".format(__file__)
-+    def test_17(self):
-+        try:
-+            def g():
-+                try:
-+                    print("starting g")
-+                    yield from range(3)
-+                    print("g should not be here")
-+                finally:
-+                    print("finishing g")
-+            
-+            gi = g()
-+            next(gi)
-+            for x in range(3):
-+                y = gi.send(42)
-+                print("Should not have yielded:", y)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g():
++            try:
++                print("starting g")
++                yield from range(3)
++                print("g should not be here")
++            finally:
++                print("finishing g")
++        
++        gi = g()
++        next(gi)
++        for x in range(3):
++            y = gi.send(42)
++            print("Should not have yielded:", y)
 +
 +
 +class Test18(PEP380Test):
 +    """
 +    Test exception in initial next() call
 +    """
++    
 +    expected = """\
 +g1 about to yield from g2
 +Traceback (most recent call last):
-+  File "{0}", line 790, in test_18
++  File "{0}", line 714, in case
 +    next(gi)
-+  File "{0}", line 783, in g1
++  File "{0}", line 707, in g1
 +    yield from g2()
-+  File "{0}", line 787, in g2
++  File "{0}", line 711, in g2
 +    yield 1/0
 +ZeroDivisionError: division by zero
 +""".format(__file__)
-+    def test_18(self):
-+        try:
-+            def g1():
-+                print("g1 about to yield from g2")
-+                yield from g2()
-+                print("g1 should not be here")
-+            
-+            def g2():
-+                yield 1/0
-+            
-+            gi = g1()
-+            next(gi)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            print("g1 about to yield from g2")
++            yield from g2()
++            print("g1 should not be here")
++        
++        def g2():
++            yield 1/0
++        
++        gi = g1()
++        next(gi)
 +
 +
 +class Test19(PEP380Test):
 +    """
 +    Test attempted yield-from loop
 +    """
++    
 +    expected = """\
 +g1: starting
 +Yielded: y1
 +Yielded: y2
 +g2: about to yield from g1
 +Traceback (most recent call last):
-+  File "{0}", line 836, in test_19
++  File "{0}", line 755, in case
 +    for y in gi:
-+  File "{0}", line 832, in g2
++  File "{0}", line 751, in g2
 +    yield from gi
-+  File "{0}", line 825, in g1
++  File "{0}", line 744, in g1
 +    yield from g2()
 +ValueError: generator already executing
 +""".format(__file__)
-+    def test_19(self):
-+        try:
-+            def g1():
-+                print("g1: starting")
-+                yield "y1"
-+                print("g1: about to yield from g2")
-+                yield from g2()
-+                print("g1 should not be here")
-+            
-+            def g2():
-+                print("g2: starting")
-+                yield "y2"
-+                print("g2: about to yield from g1")
-+                yield from gi
-+                print("g2 should not be here")
-+            
-+            gi = g1()
-+            for y in gi:
-+                print("Yielded:", y)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            print("g1: starting")
++            yield "y1"
++            print("g1: about to yield from g2")
++            yield from g2()
++            print("g1 should not be here")
++        
++        def g2():
++            print("g2: starting")
++            yield "y2"
++            print("g2: about to yield from g1")
++            yield from gi
++            print("g2 should not be here")
++        
++        gi = g1()
++        for y in gi:
++            print("Yielded:", y)
 +
 +
 +class Test20(PEP380Test):
 +    """
 +    Test returning value from delegated 'throw'
 +    """
++    
 +    expected = """\
 +Starting g1
 +Yielded g1 ham
 +Yielded g1 eggs
 +Finishing g1
 +""".format(__file__)
-+    def test_20(self):
-+        try:
-+            def g1():
-+                try:
-+                    print("Starting g1")
-+                    yield "g1 ham"
-+                    yield from g2()
-+                    yield "g1 eggs"
-+                finally:
-+                    print("Finishing g1")
-+            
-+            def g2():
-+                try:
-+                    print("Starting g2")
-+                    yield "g2 spam"
-+                    yield "g2 more spam"
-+                except LunchError:
-+                    print("Caught LunchError in g2")
-+                    yield "g2 lunch saved"
-+                    yield "g2 yet more spam"
-+            
-+            class LunchError(Exception):
-+                pass
-+            
-+            g = g1()
-+            for i in range(2):
-+                x = next(g)
-+                print("Yielded", x)
-+            e = LunchError("tomato ejected")
-+            g.throw(e)
-+            for x in g:
-+                print("Yielded", x)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def g1():
++            try:
++                print("Starting g1")
++                yield "g1 ham"
++                yield from g2()
++                yield "g1 eggs"
++            finally:
++                print("Finishing g1")
++        
++        def g2():
++            try:
++                print("Starting g2")
++                yield "g2 spam"
++                yield "g2 more spam"
++            except LunchError:
++                print("Caught LunchError in g2")
++                yield "g2 lunch saved"
++                yield "g2 yet more spam"
++        
++        class LunchError(Exception):
++            pass
++        
++        g = g1()
++        for i in range(2):
++            x = next(g)
++            print("Yielded", x)
++        e = LunchError("tomato ejected")
++        g.throw(e)
++        for x in g:
++            print("Yielded", x)
 +
 +
 +class Test21(PEP380Test):
 +    """
 +    Test next and return with value
 +    """
++    
 +    expected = """\
 +g starting
 +f resuming g
 +g returning 42
 +f caught StopIteration(42,)
 +""".format(__file__)
-+    def test_21(self):
-+        try:
-+            def f(r):
-+                gi = g(r)
++
++    def case(self):
++        def f(r):
++            gi = g(r)
++            next(gi)
++            try:
++                print("f resuming g")
 +                next(gi)
-+                try:
-+                    print("f resuming g")
-+                    next(gi)
-+                    print("f SHOULD NOT BE HERE")
-+                except StopIteration as e:
-+                    print("f caught", repr(e))
-+            
-+            def g(r):
-+                print("g starting")
-+                yield
-+                print("g returning", r)
-+                return r
-+            
-+            f(None)
-+            f(42)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
-+
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++                print("f SHOULD NOT BE HERE")
++            except StopIteration as e:
++                print("f caught", repr(e))
++        
++        def g(r):
++            print("g starting")
++            yield
++            print("g returning", r)
++            return r
++        
++        f(None)
++        f(42)
 +
 +
 +class Test22(PEP380Test):
 +    """
 +    Test send and return with value
 +    """
++    
 +    expected = """\
 +g starting
 +f sending spam to g
 +g returning 42
 +f caught StopIteration(42,)
 +""".format(__file__)
-+    def test_22(self):
-+        try:
-+            def f(r):
-+                gi = g(r)
-+                next(gi)
-+                try:
-+                    print("f sending spam to g")
-+                    gi.send("spam")
-+                    print("f SHOULD NOT BE HERE")
-+                except StopIteration as e:
-+                    print("f caught", repr(e))
-+            
-+            def g(r):
-+                print("g starting")
-+                x = yield
-+                print("g received", x)
-+                print("g returning", r)
-+                return r
-+            
-+            f(None)
-+            f(42)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def f(r):
++            gi = g(r)
++            next(gi)
++            try:
++                print("f sending spam to g")
++                gi.send("spam")
++                print("f SHOULD NOT BE HERE")
++            except StopIteration as e:
++                print("f caught", repr(e))
++        
++        def g(r):
++            print("g starting")
++            x = yield
++            print("g received", x)
++            print("g returning", r)
++            return r
++        
++        f(None)
++        f(42)
 +
 +
 +class Test23(PEP380Test):
 +    """
 +    Test parsing yield from as function argument
 +    """
++    
 +    expected = """\
-+%3i           0 LOAD_GLOBAL              0 (f) 
++904           0 LOAD_GLOBAL              0 (f) 
 +              3 LOAD_GLOBAL              1 (x) 
 +              6 YIELD_FROM           
 +              7 CALL_FUNCTION            1 
 +             11 LOAD_CONST               0 (None) 
 +             14 RETURN_VALUE         
 +""".format(__file__)
-+    def test_23(self):
-+        try:
-+            from dis import dis
-+            
-+            def g():
-+                f(yield from x)
-+            
-+            dis(g)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected % (g.__code__.co_firstlineno+1,))
++    def case(self):
++        from dis import dis
++        
++        def g():
++            f(yield from x)
++        
++        dis(g)
 +
 +
 +class Test24(PEP380Test):
 +    """
 +    Test parser module
 +    """
++    
 +    expected = """\
 +(257, (268, (269, (270, (276, (280, (336, (1, 'yield'), (337, (1, 'from'), (302, (306, (307, (308, (309, (312, (313, (314, (315, (316, (317, (318, (319, (320, (2, '1')))))))))))))))))))), (4, ''))), (4, ''), (0, ''))
 +True
 +(257, (268, (269, (270, (271, (272, (302, (306, (307, (308, (309, (312, (313, (314, (315, (316, (317, (318, (319, (320, (1, 'f')), (322, (7, '('), (330, (331, (338, (1, 'yield'), (1, 'from'), (302, (306, (307, (308, (309, (312, (313, (314, (315, (316, (317, (318, (319, (320, (2, '1')))))))))))))))))), (8, ')')))))))))))))))))), (4, ''))), (4, ''), (0, ''))
 +True
 +""".format(__file__)
-+    def test_24(self):
-+        try:
-+            import parser
-+            
-+            def test(src):
-+                st1 = parser.suite(src)
-+                tup1 = st1.totuple()
-+                print(tup1)
-+                st2 = parser.sequence2st(tup1)
-+                tup2 = st2.totuple()
-+                print(tup1 == tup2)
-+            
-+            test("yield from 1")
-+            test("f(yield from 1)")
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        import parser
++        
++        def test(src):
++            st1 = parser.suite(src)
++            tup1 = st1.totuple()
++            print(tup1)
++            st2 = parser.sequence2st(tup1)
++            tup2 = st2.totuple()
++            print(tup1 == tup2)
++        
++        test("yield from 1")
++        test("f(yield from 1)")
 +
 +
 +class Test25(PEP380Test):
 +    Test catching an exception thrown into a
 +    subgenerator and returning a value
 +    """
++    
 +    expected = """\
 +1
 +inner caught ValueError
 +inner returned 2 to outer
 +2
 +""".format(__file__)
-+    def test_25(self):
-+        try:
-+            def inner():
-+               try:
-+                   yield 1
-+               except ValueError:
-+                   print("inner caught ValueError") #pass
-+               return 2
-+            
-+            def outer():
-+               v = yield from inner()
-+               print("inner returned %r to outer" % v)
-+               yield v
-+            
-+            g = outer()
-+            print(next(g))              # prints 1
-+            print(g.throw(ValueError))  # prints 2
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def inner():
++           try:
++               yield 1
++           except ValueError:
++               print("inner caught ValueError") #pass
++           return 2
++        
++        def outer():
++           v = yield from inner()
++           print("inner returned %r to outer" % v)
++           yield v
++        
++        g = outer()
++        print(next(g))              # prints 1
++        print(g.throw(ValueError))  # prints 2
 +
 +
 +class Test26(PEP380Test):
 +    Test throwing GeneratorExit into a subgenerator that
 +    catches it and returns normally.
 +    """
++    
 +    expected = """\
 +Enter g
 +Enter f
 +Traceback (most recent call last):
-+  File "{0}", line 1116, in test_26
++  File "{0}", line 1000, in case
 +    gi.throw(GeneratorExit)
-+  File "{0}", line 1111, in g
++  File "{0}", line 995, in g
 +    yield from f()
 +GeneratorExit
 +""".format(__file__)
-+    def test_26(self):
-+        try:
-+            def f():
-+                try:
-+                    print("Enter f")
-+                    yield
-+                    print("Exit f")
-+                except GeneratorExit:
-+                    return
-+            
-+            def g():
-+                print("Enter g")
-+                yield from f()
-+                print("Exit g")
-+            
-+            gi = g()
-+            next(gi)
-+            gi.throw(GeneratorExit)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def f():
++            try:
++                print("Enter f")
++                yield
++                print("Exit f")
++            except GeneratorExit:
++                return
++        
++        def g():
++            print("Enter g")
++            yield from f()
++            print("Exit g")
++        
++        gi = g()
++        next(gi)
++        gi.throw(GeneratorExit)
 +
 +
 +class Test27(PEP380Test):
 +    Test throwing GeneratorExit into a subgenerator that
 +    catches it and yields.
 +    """
++    
 +    expected = """\
 +Enter g
 +Enter f
 +Traceback (most recent call last):
-+  File "{0}", line 1157, in test_27
++  File "{0}", line 1036, in case
 +    gi.throw(GeneratorExit)
-+  File "{0}", line 1152, in g
++  File "{0}", line 1031, in g
 +    yield from f()
 +RuntimeError: generator ignored GeneratorExit
 +""".format(__file__)
-+    def test_27(self):
-+        try:
-+            def f():
-+                try:
-+                    print("Enter f")
-+                    yield
-+                    print("Exit f")
-+                except GeneratorExit:
-+                    yield
-+            
-+            def g():
-+                print("Enter g")
-+                yield from f()
-+                print("Exit g")
-+            
-+            gi = g()
-+            next(gi)
-+            gi.throw(GeneratorExit)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
++    def case(self):
++        def f():
++            try:
++                print("Enter f")
++                yield
++                print("Exit f")
++            except GeneratorExit:
++                yield
++        
++        def g():
++            print("Enter g")
++            yield from f()
++            print("Exit g")
++        
++        gi = g()
++        next(gi)
++        gi.throw(GeneratorExit)
 +
 +
 +class Test28(PEP380Test):
 +    Test throwing GeneratorExit into a subgenerator that
 +    catches it and raises a different exception.
 +    """
++    
 +    expected = """\
 +Enter g
 +Enter f
 +Traceback (most recent call last):
-+  File "{0}", line 1195, in f
++  File "{0}", line 1069, in f
 +    yield
 +GeneratorExit
 +
 +During handling of the above exception, another exception occurred:
 +
 +Traceback (most recent call last):
-+  File "{0}", line 1207, in test_28
++  File "{0}", line 1081, in case
 +    gi.throw(GeneratorExit)
-+  File "{0}", line 1202, in g
++  File "{0}", line 1076, in g
 +    yield from f()
-+  File "{0}", line 1198, in f
++  File "{0}", line 1072, in f
 +    raise ValueError("Vorpal bunny encountered")
 +ValueError: Vorpal bunny encountered
 +""".format(__file__)
-+    def test_28(self):
-+        try:
-+            def f():
-+                try:
-+                    print("Enter f")
-+                    yield
-+                    print("Exit f")
-+                except GeneratorExit:
-+                    raise ValueError("Vorpal bunny encountered")
-+            
-+            def g():
-+                print("Enter g")
-+                yield from f()
-+                print("Exit g")
-+            
-+            gi = g()
-+            next(gi)
-+            gi.throw(GeneratorExit)
-+        except:
-+            et, ev, tb = sys.exc_info()
-+            traceback.print_exception(et, ev, tb)
 +
-+        self.assertEqual(self.out.getvalue(),
-+                         self.expected)
-+
++    def case(self):
++        def f():
++            try:
++                print("Enter f")
++                yield
++                print("Exit f")
++            except GeneratorExit:
++                raise ValueError("Vorpal bunny encountered")
++        
++        def g():
++            print("Enter g")
++            yield from f()
++            print("Exit g")
++        
++        gi = g()
++        next(gi)
++        gi.throw(GeneratorExit)
 +
 +
 +def test_main():
 +    from test import support
-+    test_classes = [Test1, Test2, Test3, Test4, Test5, Test6, Test7, Test8,
-+                    Test9, Test10, Test11, Test12, Test13, Test14, Test15,
-+                    Test16, Test17, Test18, Test19, Test20, Test21, Test22,
-+                    Test23, Test24, Test25, Test26, Test27, Test28]
++    test_classes = [Test1, Test2, Test3, Test4, Test5, Test6, Test7, Test8, Test9, Test10, Test11, Test12, Test13, Test14, Test15, Test16, Test17, Test18, Test19, Test20, Test21, Test22, Test23, Test24, Test25, Test26, Test27, Test28]
 +    support.run_unittest(*test_classes)
 +
 +