Skip to content

Commit 96baaa6

Browse files
committed
tests: Update tests, and add new ones, for recent generator tweaks.
1 parent 239f920 commit 96baaa6

4 files changed

Lines changed: 40 additions & 10 deletions

File tree

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
# uPy differs from CPython for this test
2-
# generator ignored GeneratorExit
1+
# generator ignores a thrown GeneratorExit (this is allowed)
2+
33
def gen():
44
try:
55
yield 123
66
except GeneratorExit:
77
print('GeneratorExit')
88
yield 456
99

10+
# thrown a class
1011
g = gen()
1112
print(next(g))
12-
try:
13-
g.throw(GeneratorExit)
14-
except RuntimeError:
15-
print('RuntimeError')
13+
print(g.throw(GeneratorExit))
14+
15+
# thrown an instance
16+
g = gen()
17+
print(next(g))
18+
print(g.throw(GeneratorExit()))

tests/basics/gen_yield_from_throw2.py.exp

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yield-from a user-defined generator with a throw() method
2+
3+
class Iter:
4+
def __iter__(self):
5+
return self
6+
7+
def __next__(self):
8+
return 1
9+
10+
def throw(self, x):
11+
print('throw', x)
12+
return 456
13+
14+
def gen():
15+
yield from Iter()
16+
17+
# calling close() should not call throw()
18+
g = gen()
19+
print(next(g))
20+
g.close()
21+
22+
# can throw a non-exception object
23+
g = gen()
24+
print(next(g))
25+
print(g.throw(123))
26+
27+
# throwing an exception class just injects that class
28+
g = gen()
29+
print(next(g))
30+
print(g.throw(ZeroDivisionError))

tests/run-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def run_tests(pyb, tests, args):
281281
# Some tests are known to fail with native emitter
282282
# Remove them from the below when they work
283283
if args.emit == 'native':
284-
skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_stopped gen_yield_from_throw gen_yield_from_throw2 generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send'.split()}) # require yield
284+
skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_stopped gen_yield_from_throw gen_yield_from_throw2 gen_yield_from_throw3 generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send'.split()}) # require yield
285285
skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class globals_del string_join'.split()}) # require yield
286286
skip_tests.update({'basics/async_%s.py' % t for t in 'def await await2 for for2 with with2'.split()}) # require yield
287287
skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs

0 commit comments

Comments
 (0)