Skip to content

Commit 214179b

Browse files
committed
tests: Add tests for SyntaxError, TypeError, and other missing things.
This is intended to improve coverage of the test suite.
1 parent 44f65c0 commit 214179b

24 files changed

+296
-6
lines changed

tests/basics/array1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@
1111
print(len(array.array('h')))
1212
print(array.array('i'))
1313

14+
# bool operator acting on arrays
15+
print(bool(array.array('i')))
16+
print(bool(array.array('i', [1])))
17+
18+
# bad typecode
19+
try:
20+
array.array('X')
21+
except ValueError:
22+
print("ValueError")

tests/basics/array_construct.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
# convert from other arrays
1515
print(array('H', array('b', [1, 2])))
1616
print(array('b', array('I', [1, 2])))
17+
18+
# construct from something with unknown length
19+
print(array('i', (i for i in range(10))))

tests/basics/bool1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# tests for bool objects
2+
3+
# basic logic
4+
print(not False)
5+
print(not True)
6+
print(False and True)
7+
print(False or True)
8+
9+
# unary operators
10+
print(+True)
11+
print(-True)

tests/basics/bytearray_slice_assign.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@
4141
l = bytearray(x)
4242
#del l[:-3]
4343
print(l)
44+
45+
# slice assignment that extends the array
46+
b = bytearray(2)
47+
b[2:] = bytearray(10)
48+
print(b)

tests/basics/closure_manyvars.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# test closure with lots of closed over variables
2+
3+
def f():
4+
a, b, c, d, e, f, g, h = [i for i in range(8)]
5+
def x():
6+
print(a, b, c, d, e, f, g, h)
7+
x()
8+
9+
f()

tests/basics/fun_str.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# test str of function
2+
3+
def f():
4+
pass
5+
print(str(f)[:8])

tests/basics/int1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ def test(value, base):
8181

8282
# check that we don't parse this as a floating point number
8383
print(0x1e+1)
84+
85+
# can't convert list to int
86+
try:
87+
int([])
88+
except TypeError:
89+
print("TypeError")

tests/basics/int2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# test basic int operations
2+
3+
# test conversion of bool on RHS of binary op
4+
a = False
5+
print(1 + a)
6+
a = True
7+
print(1 + a)

tests/basics/list_index.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232
print("Raised ValueError")
3333
else:
3434
print("Did not raise ValueError")
35+
36+
# 3rd argument to index greater than length of list
37+
print([1, 2].index(1, 0, 4))

tests/basics/memoryview1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
print(list(m[1:]))
2626
print(list(m[1:-1]))
2727

28+
# this tests get_buffer of memoryview
29+
m = memoryview(bytearray(2))
30+
print(bytearray(m))
31+
2832
import array
2933
a = array.array('i', [1, 2, 3, 4])
3034
m = memoryview(a)

0 commit comments

Comments
 (0)