-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathtest.py
More file actions
173 lines (153 loc) · 4.29 KB
/
test.py
File metadata and controls
173 lines (153 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright 2023 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import array
print("globals:")
for name in ("typecodes", "array"):
v = getattr(array, name)
print("\narray.%s:\n%s" % (name,repr(v)))
pass
def assertEqual(x, y):
assert x == y, "got: %s, want: %s" % (repr(x), repr(y))
assertEqual(array.typecodes, 'bBuhHiIlLqQfd')
for i, typ in enumerate(array.typecodes):
print("")
print("typecode '%s'" % (typ,))
if typ == 'u':
arr = array.array(typ, "?世界!")
if typ in "bhilq":
arr = array.array(typ, [-1, -2, -3, -4])
if typ in "BHILQ":
arr = array.array(typ, [+1, +2, +3, +4])
if typ in "fd":
arr = array.array(typ, [-1.0, -2.0, -3.0, -4.0])
print(" array: %s ## repr" % (repr(arr),))
print(" array: %s ## str" % (str(arr),))
print(" itemsize: %s" % (arr.itemsize,))
print(" typecode: %s" % (arr.typecode,))
print(" len: %s" % (len(arr),))
print(" arr[0]: %s" % (arr[0],))
print(" arr[-1]: %s" % (arr[-1],))
try:
arr[-10]
print(" ERROR1: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr[10]
print(" ERROR2: expected an exception")
except:
print(" caught an exception [ok]")
arr[-2] = 33
if typ in "fd":
arr[-2] = 0.3
print(" arr[-2]: %s" % (arr[-2],))
try:
arr[-10] = 2
print(" ERROR3: expected an exception")
except:
print(" caught an exception [ok]")
if typ in "bhilqfd":
arr.extend([-5,-6])
if typ in "BHILQ":
arr.extend([5,6])
if typ == 'u':
arr.extend("he")
print(" array: %s" % (repr(arr),))
print(" len: %s" % (len(arr),))
if typ in "bhilqfd":
arr.append(-7)
if typ in "BHILQ":
arr.append(7)
if typ == 'u':
arr.append("l")
print(" array: %s" % (repr(arr),))
print(" len: %s" % (len(arr),))
try:
arr.append()
print(" ERROR4: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr.append([])
print(" ERROR5: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr.append(1, 2)
print(" ERROR6: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr.append(None)
print(" ERROR7: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr.extend()
print(" ERROR8: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr.extend(None)
print(" ERROR9: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr.extend([1,None])
print(" ERROR10: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr.extend(1,None)
print(" ERROR11: expected an exception")
except:
print(" caught an exception [ok]")
try:
arr[0] = object()
print(" ERROR12: expected an exception")
except:
print(" caught an exception [ok]")
pass
print("\n")
print("## testing array.array(...)")
try:
arr = array.array()
print("ERROR1: expected an exception")
except:
print("caught an exception [ok]")
try:
arr = array.array(b"d")
print("ERROR2: expected an exception")
except:
print("caught an exception [ok]")
try:
arr = array.array("?")
print("ERROR3: expected an exception")
except:
print("caught an exception [ok]")
try:
arr = array.array("dd")
print("ERROR4: expected an exception")
except:
print("caught an exception [ok]")
try:
arr = array.array("d", initializer=[1,2])
print("ERROR5: expected an exception")
except:
print("caught an exception [ok]")
try:
arr = array.array("d", [1], [])
print("ERROR6: expected an exception")
except:
print("caught an exception [ok]")
try:
arr = array.array("d", 1)
print("ERROR7: expected an exception")
except:
print("caught an exception [ok]")
try:
arr = array.array("d", ["a","b"])
print("ERROR8: expected an exception")
except:
print("caught an exception [ok]")