Skip to content

Commit 531c206

Browse files
flowergrassdpgeorge
authored andcommitted
tests: Add tests to improve coverage of runtime.c.
1 parent 46a6592 commit 531c206

6 files changed

Lines changed: 63 additions & 0 deletions

File tree

tests/basics/gen_yield_from_close.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,25 @@ def gen7():
9999
g.close()
100100
except RuntimeError:
101101
print('RuntimeError')
102+
103+
# case where close is propagated up to a built-in iterator
104+
def gen8():
105+
g = reversed([2, 1])
106+
yield from g
107+
g = gen8()
108+
print(next(g))
109+
g.close()
110+
111+
# case with a user-defined close method
112+
class Iter:
113+
def __iter__(self):
114+
return self
115+
def __next__(self):
116+
return 1
117+
def close(self):
118+
print('close')
119+
def gen9():
120+
yield from Iter()
121+
g = gen9()
122+
print(next(g))
123+
g.close()

tests/basics/int_big_add.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# tests transition from small to large int representation by addition
2+
3+
# 31-bit overflow
4+
i = 0x3fffffff
5+
print(i + i)
6+
print(-i + -i)
7+
8+
# 63-bit overflow
9+
i = 0x3fffffffffffffff
10+
print(i + i)
11+
print(-i + -i)

tests/basics/iter1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ class NotIterable:
99
except TypeError:
1010
print('TypeError')
1111

12+
# this class has no __next__ implementation
13+
class NotIterable:
14+
def __iter__(self):
15+
return self
16+
try:
17+
print(all(NotIterable()))
18+
except TypeError:
19+
print('TypeError')
20+
1221
class MyStopIteration(StopIteration):
1322
pass
1423

tests/basics/try2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
except NameError:
2323
print("except 1")
2424

25+
# raised exception not contained in except tuple
26+
try:
27+
try:
28+
raise Exception
29+
except (RuntimeError, SyntaxError):
30+
print('except 2')
31+
except Exception:
32+
print('except 1')
33+
2534
# Check that exceptions across function boundaries work as expected
2635
def func1():
2736
try:

tests/float/complex1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
except TypeError:
7676
print("TypeError")
7777

78+
#small int on LHS, complex on RHS, unsupported op
79+
try:
80+
print(1 | 1j)
81+
except TypeError:
82+
print('TypeError')
83+
7884
# zero division
7985
try:
8086
1j / 0

tests/float/float1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
except TypeError:
8888
print("TypeError")
8989

90+
# small int on LHS, float on RHS, unsupported op
91+
try:
92+
print(1 | 1.0)
93+
except TypeError:
94+
print('TypeError')
95+
9096
# can't convert list to float
9197
try:
9298
float([])

0 commit comments

Comments
 (0)