tests/basics: Split out gen throw tests from yield-from-throw tests.
This commit is contained in:
parent
e9012a20f7
commit
e6078dfed2
|
@ -16,29 +16,3 @@ try:
|
|||
print(next(g))
|
||||
except TypeError:
|
||||
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(KeyError)
|
||||
except KeyError:
|
||||
print('got KeyError from downstream!')
|
||||
|
||||
# case where a thrown exception is caught and stops the generator
|
||||
def gen4():
|
||||
try:
|
||||
yield 1
|
||||
yield 2
|
||||
except:
|
||||
pass
|
||||
g4 = gen4()
|
||||
print(next(g4))
|
||||
try:
|
||||
g4.throw(ValueError)
|
||||
except StopIteration:
|
||||
print('got StopIteration')
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# case where generator doesn't intercept the thrown/injected exception
|
||||
def gen():
|
||||
yield 123
|
||||
yield 456
|
||||
|
||||
g = gen()
|
||||
print(next(g))
|
||||
try:
|
||||
g.throw(KeyError)
|
||||
except KeyError:
|
||||
print('got KeyError from downstream!')
|
||||
|
||||
# case where a thrown exception is caught and stops the generator
|
||||
def gen():
|
||||
try:
|
||||
yield 1
|
||||
yield 2
|
||||
except:
|
||||
pass
|
||||
g = gen()
|
||||
print(next(g))
|
||||
try:
|
||||
g.throw(ValueError)
|
||||
except StopIteration:
|
||||
print('got StopIteration')
|
||||
|
||||
# generator ignores a thrown GeneratorExit (this is allowed)
|
||||
def gen():
|
||||
try:
|
||||
yield 123
|
||||
except GeneratorExit:
|
||||
print('GeneratorExit')
|
||||
yield 456
|
||||
|
||||
# thrown a class
|
||||
g = gen()
|
||||
print(next(g))
|
||||
print(g.throw(GeneratorExit))
|
||||
|
||||
# thrown an instance
|
||||
g = gen()
|
||||
print(next(g))
|
||||
print(g.throw(GeneratorExit()))
|
|
@ -352,7 +352,7 @@ def run_tests(pyb, tests, args, base_path="."):
|
|||
# Some tests are known to fail with native emitter
|
||||
# Remove them from the below when they work
|
||||
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_executing 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_name generator_pend_throw generator_return generator_send generator_pep479'.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_executing 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_name generator_pend_throw generator_return generator_send generator_throw generator_pep479'.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 with_break with_return'.split()}) # require yield
|
||||
skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs
|
||||
|
|
Loading…
Reference in New Issue