summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/gen_yield_from_throw3.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-01-17 00:17:44 +1100
committerDamien George <damien.p.george@gmail.com>2017-01-17 00:17:44 +1100
commit96baaa68a4430efd585f2186976cfa473ca73bfc (patch)
tree926f422e0eeb3af4adaef8a57e5a9e9ed774b00c /tests/basics/gen_yield_from_throw3.py
parent239f92029910cddb08a2669f3ebcd987f0a2d0a8 (diff)
downloadmicropython-96baaa68a4430efd585f2186976cfa473ca73bfc.tar.gz
micropython-96baaa68a4430efd585f2186976cfa473ca73bfc.zip
tests: Update tests, and add new ones, for recent generator tweaks.
Diffstat (limited to 'tests/basics/gen_yield_from_throw3.py')
-rw-r--r--tests/basics/gen_yield_from_throw3.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/basics/gen_yield_from_throw3.py b/tests/basics/gen_yield_from_throw3.py
new file mode 100644
index 0000000000..0f6c7c8429
--- /dev/null
+++ b/tests/basics/gen_yield_from_throw3.py
@@ -0,0 +1,30 @@
+# yield-from a user-defined generator with a throw() method
+
+class Iter:
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ return 1
+
+ def throw(self, x):
+ print('throw', x)
+ return 456
+
+def gen():
+ yield from Iter()
+
+# calling close() should not call throw()
+g = gen()
+print(next(g))
+g.close()
+
+# can throw a non-exception object
+g = gen()
+print(next(g))
+print(g.throw(123))
+
+# throwing an exception class just injects that class
+g = gen()
+print(next(g))
+print(g.throw(ZeroDivisionError))