tests/basics: Improve test coverage for generators.
This commit is contained in:
parent
1e7a801e2d
commit
5d06a74303
@ -85,3 +85,17 @@ try:
|
|||||||
print(next(g))
|
print(next(g))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
print("StopIteration")
|
print("StopIteration")
|
||||||
|
|
||||||
|
# case where generator ignores the close request and yields instead
|
||||||
|
def gen7():
|
||||||
|
try:
|
||||||
|
yield 123
|
||||||
|
except GeneratorExit:
|
||||||
|
yield 456
|
||||||
|
|
||||||
|
g = gen7()
|
||||||
|
print(next(g))
|
||||||
|
try:
|
||||||
|
g.close()
|
||||||
|
except RuntimeError:
|
||||||
|
print('RuntimeError')
|
||||||
|
@ -17,3 +17,14 @@ try:
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
print("got TypeError from downstream!")
|
print("got TypeError from downstream!")
|
||||||
|
|
||||||
|
# case where generator doesn't intercept the thrown/injected exception
|
||||||
|
def gen3():
|
||||||
|
yield 123
|
||||||
|
yield 456
|
||||||
|
|
||||||
|
g3 = gen3()
|
||||||
|
print(next(g3))
|
||||||
|
try:
|
||||||
|
g3.throw(StopIteration)
|
||||||
|
except StopIteration:
|
||||||
|
print('got StopIteration from downstream!')
|
||||||
|
15
tests/basics/gen_yield_from_throw2.py
Normal file
15
tests/basics/gen_yield_from_throw2.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# uPy differs from CPython for this test
|
||||||
|
# generator ignored GeneratorExit
|
||||||
|
def gen():
|
||||||
|
try:
|
||||||
|
yield 123
|
||||||
|
except GeneratorExit:
|
||||||
|
print('GeneratorExit')
|
||||||
|
yield 456
|
||||||
|
|
||||||
|
g = gen()
|
||||||
|
print(next(g))
|
||||||
|
try:
|
||||||
|
g.throw(GeneratorExit)
|
||||||
|
except RuntimeError:
|
||||||
|
print('RuntimeError')
|
3
tests/basics/gen_yield_from_throw2.py.exp
Normal file
3
tests/basics/gen_yield_from_throw2.py.exp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
123
|
||||||
|
GeneratorExit
|
||||||
|
RuntimeError
|
@ -20,3 +20,6 @@ for val in f(3):
|
|||||||
#print(gen.__next__())
|
#print(gen.__next__())
|
||||||
#print(gen.__next__())
|
#print(gen.__next__())
|
||||||
#print(gen.__next__())
|
#print(gen.__next__())
|
||||||
|
|
||||||
|
# test printing, but only the first chars that match CPython
|
||||||
|
print(repr(f(0))[0:17])
|
||||||
|
@ -271,7 +271,7 @@ def run_tests(pyb, tests, args):
|
|||||||
# Some tests are known to fail with native emitter
|
# Some tests are known to fail with native emitter
|
||||||
# Remove them from the below when they work
|
# Remove them from the below when they work
|
||||||
if args.emit == 'native':
|
if args.emit == 'native':
|
||||||
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 generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send'.split()}) # require yield
|
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
|
||||||
skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class globals_del string_join'.split()}) # require yield
|
skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class globals_del string_join'.split()}) # require yield
|
||||||
skip_tests.update({'basics/async_%s.py' % t for t in 'def await await2 for for2 with with2'.split()}) # require yield
|
skip_tests.update({'basics/async_%s.py' % t for t in 'def await await2 for for2 with with2'.split()}) # require yield
|
||||||
skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs
|
skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs
|
||||||
|
Loading…
Reference in New Issue
Block a user