Author: Armin Rigo <[email protected]>
Branch: generator-in-rpython
Changeset: r50829:9d9bba8e1c24
Date: 2011-12-23 11:34 +0100
http://bitbucket.org/pypy/pypy/changeset/9d9bba8e1c24/

Log:    A non-test for a non-feature.

diff --git a/pypy/rpython/test/test_generator.py 
b/pypy/rpython/test/test_generator.py
--- a/pypy/rpython/test/test_generator.py
+++ b/pypy/rpython/test/test_generator.py
@@ -17,6 +17,40 @@
         res = self.interpret(f, [])
         assert res == 358
 
+    def test_cannot_merge(self):
+        # merging two different generators is not supported
+        # right now, but we can use workarounds like here
+        class MyGen:
+            def next(self):
+                raise NotImplementedError
+        class MyG1(MyGen):
+            def __init__(self, a):
+                self._gen = self.g1(a)
+            def next(self):
+                return self._gen.next()
+            @staticmethod
+            def g1(a):
+                yield a + 1
+                yield a + 2
+        class MyG2(MyGen):
+            def __init__(self):
+                self._gen = self.g2()
+            def next(self):
+                return self._gen.next()
+            @staticmethod
+            def g2():
+                yield 42
+        def f(n):
+            if n > 0:
+                gen = MyG1(n)
+            else:
+                gen = MyG2()
+            return gen.next()
+        res = self.interpret(f, [10])
+        assert res == 11
+        res = self.interpret(f, [0])
+        assert res == 42
+
 
 class TestLLtype(BaseTestGenerator, LLRtypeMixin):
     pass
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to