tests: Update tests, and add new ones, for recent generator tweaks.

This commit is contained in:
Damien George 2017-01-17 00:17:44 +11:00
parent 239f920299
commit 96baaa68a4
4 changed files with 40 additions and 10 deletions

View File

@ -1,5 +1,5 @@
# uPy differs from CPython for this test
# generator ignored GeneratorExit
# generator ignores a thrown GeneratorExit (this is allowed)
def gen():
try:
yield 123
@ -7,9 +7,12 @@ def gen():
print('GeneratorExit')
yield 456
# thrown a class
g = gen()
print(next(g))
try:
g.throw(GeneratorExit)
except RuntimeError:
print('RuntimeError')
print(g.throw(GeneratorExit))
# thrown an instance
g = gen()
print(next(g))
print(g.throw(GeneratorExit()))

View File

@ -1,3 +0,0 @@
123
GeneratorExit
RuntimeError

View File

@ -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))

View File

@ -281,7 +281,7 @@ def run_tests(pyb, tests, args):
# 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_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/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