tests: Update tests, and add new ones, for recent generator tweaks.
This commit is contained in:
parent
239f920299
commit
96baaa68a4
|
@ -1,5 +1,5 @@
|
||||||
# uPy differs from CPython for this test
|
# generator ignores a thrown GeneratorExit (this is allowed)
|
||||||
# generator ignored GeneratorExit
|
|
||||||
def gen():
|
def gen():
|
||||||
try:
|
try:
|
||||||
yield 123
|
yield 123
|
||||||
|
@ -7,9 +7,12 @@ def gen():
|
||||||
print('GeneratorExit')
|
print('GeneratorExit')
|
||||||
yield 456
|
yield 456
|
||||||
|
|
||||||
|
# thrown a class
|
||||||
g = gen()
|
g = gen()
|
||||||
print(next(g))
|
print(next(g))
|
||||||
try:
|
print(g.throw(GeneratorExit))
|
||||||
g.throw(GeneratorExit)
|
|
||||||
except RuntimeError:
|
# thrown an instance
|
||||||
print('RuntimeError')
|
g = gen()
|
||||||
|
print(next(g))
|
||||||
|
print(g.throw(GeneratorExit()))
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
123
|
|
||||||
GeneratorExit
|
|
||||||
RuntimeError
|
|
|
@ -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))
|
|
@ -281,7 +281,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 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 '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
|
||||||
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