diff options
| author | Rami Ali | 2016-12-21 14:47:02 +1100 |
|---|---|---|
| committer | Damien George | 2016-12-21 15:44:41 +1100 |
| commit | 531c206e8b2e4d1af735af473c2fdeb8c1b36247 (patch) | |
| tree | e4b8399b32609cf6f6fd3e04cdd8b09005b3f777 /tests/basics | |
| parent | 46a6592f9ac072386ee2a106c8928d2a1d955cbb (diff) | |
tests: Add tests to improve coverage of runtime.c.
Diffstat (limited to 'tests/basics')
| -rw-r--r-- | tests/basics/gen_yield_from_close.py | 22 | ||||
| -rw-r--r-- | tests/basics/int_big_add.py | 11 | ||||
| -rw-r--r-- | tests/basics/iter1.py | 9 | ||||
| -rw-r--r-- | tests/basics/try2.py | 9 |
4 files changed, 51 insertions, 0 deletions
diff --git a/tests/basics/gen_yield_from_close.py b/tests/basics/gen_yield_from_close.py index 674e117a0..d66691ff9 100644 --- a/tests/basics/gen_yield_from_close.py +++ b/tests/basics/gen_yield_from_close.py @@ -99,3 +99,25 @@ try: g.close() except RuntimeError: print('RuntimeError') + +# case where close is propagated up to a built-in iterator +def gen8(): + g = reversed([2, 1]) + yield from g +g = gen8() +print(next(g)) +g.close() + +# case with a user-defined close method +class Iter: + def __iter__(self): + return self + def __next__(self): + return 1 + def close(self): + print('close') +def gen9(): + yield from Iter() +g = gen9() +print(next(g)) +g.close() diff --git a/tests/basics/int_big_add.py b/tests/basics/int_big_add.py new file mode 100644 index 000000000..f0c3336d0 --- /dev/null +++ b/tests/basics/int_big_add.py @@ -0,0 +1,11 @@ +# tests transition from small to large int representation by addition + +# 31-bit overflow +i = 0x3fffffff +print(i + i) +print(-i + -i) + +# 63-bit overflow +i = 0x3fffffffffffffff +print(i + i) +print(-i + -i) diff --git a/tests/basics/iter1.py b/tests/basics/iter1.py index 5bd7f5090..9117dfd2b 100644 --- a/tests/basics/iter1.py +++ b/tests/basics/iter1.py @@ -9,6 +9,15 @@ try: except TypeError: print('TypeError') +# this class has no __next__ implementation +class NotIterable: + def __iter__(self): + return self +try: + print(all(NotIterable())) +except TypeError: + print('TypeError') + class MyStopIteration(StopIteration): pass diff --git a/tests/basics/try2.py b/tests/basics/try2.py index 5827699e9..11e60b3c2 100644 --- a/tests/basics/try2.py +++ b/tests/basics/try2.py @@ -22,6 +22,15 @@ try: except NameError: print("except 1") +# raised exception not contained in except tuple +try: + try: + raise Exception + except (RuntimeError, SyntaxError): + print('except 2') +except Exception: + print('except 1') + # Check that exceptions across function boundaries work as expected def func1(): try: |
