1 # Check every path through every method of UserList
3 from UserList
import UserList
4 from test_support
import TestFailed
6 # Use check instead of assert so -O doesn't render the
8 # XXX: could use the verify function in test_support instead
9 def check(predicate
, msg
):
11 raise TestFailed(msg
+ " failed")
29 v
= UserList(tuple(u
))
31 def __init__(self
, initlist
):
32 self
.__data
= initlist
34 return len(self
.__data
)
35 def __getitem__(self
, i
):
37 v0
= UserList(OtherList(u0
))
38 vv
= UserList("this is also a sequence")
42 check(str(u0
) == str(l0
), "str(u0) == str(l0)")
43 check(repr(u1
) == repr(l1
), "repr(u1) == repr(l1)")
44 check(`u2`
== `l2`
, "`u2` == `l2`")
46 # Test __cmp__ and __len__
54 all
= [l0
, l1
, l2
, u
, u0
, u1
, u2
, uu
, uu0
, uu1
, uu2
]
57 check(mycmp(a
, b
) == mycmp(len(a
), len(b
)),
58 "mycmp(a, b) == mycmp(len(a), len(b))")
62 for i
in range(len(u2
)):
63 check(u2
[i
] == i
, "u2[i] == i")
74 raise TestFailed("uu2[2] shouldn't be assignable")
85 raise TestFailed("uu2[0] shouldn't be deletable")
89 for i
in range(-3, 4):
90 check(u2
[:i
] == l2
[:i
], "u2[:i] == l2[:i]")
91 check(u2
[i
:] == l2
[i
:], "u2[i:] == l2[i:]")
92 for j
in range(-3, 4):
93 check(u2
[i
:j
] == l2
[i
:j
], "u2[i:j] == l2[i:j]")
97 for i
in range(-3, 4):
99 check(u2
== l2
, "u2 == l2")
101 check(u2
== l2
, "u2 == l2")
102 for j
in range(-3, 4):
104 check(u2
== l2
, "u2 == l2")
108 check(uu2
== [-2, -1, 0, 1], "uu2 == [-2, -1, 0, 1]")
110 check(uu2
== [], "uu2 == []")
114 check(i
in u2
, "i in u2")
115 for i
in min(u2
)-1, max(u2
)+1:
116 check(i
not in u2
, "i not in u2")
123 check(uu2
== [], "uu2 == []")
128 check(uu2
== [], "uu2 == []")
130 # Test __add__, __radd__, __mul__ and __rmul__
132 check(u1
+ [] == [] + u1
== u1
, "u1 + [] == [] + u1 == u1")
133 check(u1
+ [1] == u2
, "u1 + [1] == u2")
134 check([-1] + u1
== [-1, 0], "[-1] + u1 == [-1, 0]")
135 check(u2
== u2
*1 == 1*u2
, "u2 == u2*1 == 1*u2")
136 check(u2
+u2
== u2
*2 == 2*u2
, "u2+u2 == u2*2 == 2*u2")
137 check(u2
+u2
+u2
== u2
*3 == 3*u2
, "u2+u2+u2 == u2*3 == 3*u2")
143 check(u
== u2
, "u == u2")
149 check(u
== [-1, 0, 1], "u == [-1, 0, 1]")
155 check(u
== [-1, 0], "u == [-1, 0]")
157 check(u
== [0], "u == [0]")
163 check(u
== u1
, "u == u1")
167 check(u
.count(0) == 3, "u.count(0) == 3")
168 check(u
.count(1) == 3, "u.count(1) == 3")
169 check(u
.count(2) == 0, "u.count(2) == 0")
174 check(u2
.index(0) == 0, "u2.index(0) == 0")
175 check(u2
.index(1) == 1, "u2.index(1) == 1")
181 raise TestFailed("expected ValueError")
187 check(u
== [1, 0], "u == [1, 0]")
189 check(u
== u2
, "u == u2")
195 check(u
== u2
, "u == u2")
201 check(u
== u1
+ u2
, "u == u1 + u2")