Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_list.ListTest Class Reference
Inheritance diagram for test.test_list.ListTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_list.ListTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_basic
def test_truth
def test_identity
def test_len
def test_overflow
def test_init
def test_repr
def test_print
def test_set_subscript
def test_reversed
def test_setitem
def test_delitem
def test_setslice
def test_delslice
def test_append
def test_extend
def test_insert
def test_pop
def test_remove
def test_count
def test_index
def test_reverse
def test_sort
def test_slice
def test_iadd
def test_imul
def test_extendedslicing
def test_constructor_exception_handling
def test_constructors
def test_getitem
def test_getslice
def test_contains
def test_contains_fake
def test_contains_order
def test_minmax
def test_addmul
def test_getitemoverwriteiter
def test_repeat
def test_bigrepeat
def test_subscript

Public Attributes

 victim

Static Public Attributes

 type2test = list

Detailed Description

Definition at line 4 of file test_list.py.


Member Function Documentation

def test.seq_tests.CommonTest.test_addmul (   self) [inherited]

Definition at line 245 of file seq_tests.py.

00245 
00246     def test_addmul(self):
00247         u1 = self.type2test([0])
00248         u2 = self.type2test([0, 1])
00249         self.assertEqual(u1, u1 + self.type2test())
00250         self.assertEqual(u1, self.type2test() + u1)
00251         self.assertEqual(u1 + self.type2test([1]), u2)
00252         self.assertEqual(self.type2test([-1]) + u1, self.type2test([-1, 0]))
00253         self.assertEqual(self.type2test(), u2*0)
00254         self.assertEqual(self.type2test(), 0*u2)
00255         self.assertEqual(self.type2test(), u2*0)
00256         self.assertEqual(self.type2test(), 0*u2)
00257         self.assertEqual(u2, u2*1)
00258         self.assertEqual(u2, 1*u2)
00259         self.assertEqual(u2, u2*1)
00260         self.assertEqual(u2, 1*u2)
00261         self.assertEqual(u2+u2, u2*2)
00262         self.assertEqual(u2+u2, 2*u2)
00263         self.assertEqual(u2+u2, u2*2)
00264         self.assertEqual(u2+u2, 2*u2)
00265         self.assertEqual(u2+u2+u2, u2*3)
00266         self.assertEqual(u2+u2+u2, 3*u2)
00267 
00268         class subclass(self.type2test):
00269             pass
00270         u3 = subclass([0, 1])
00271         self.assertEqual(u3, u3*1)
00272         self.assertIsNot(u3, u3*1)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_append (   self) [inherited]

Definition at line 232 of file list_tests.py.

00232 
00233     def test_append(self):
00234         a = self.type2test([])
00235         a.append(0)
00236         a.append(1)
00237         a.append(2)
00238         self.assertEqual(a, self.type2test([0, 1, 2]))
00239 
00240         self.assertRaises(TypeError, a.append)

Here is the call graph for this function:

Definition at line 7 of file test_list.py.

00007 
00008     def test_basic(self):
00009         self.assertEqual(list([]), [])
00010         l0_3 = [0, 1, 2, 3]
00011         l0_3_bis = list(l0_3)
00012         self.assertEqual(l0_3, l0_3_bis)
00013         self.assertTrue(l0_3 is not l0_3_bis)
00014         self.assertEqual(list(()), [])
00015         self.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3])
00016         self.assertEqual(list(''), [])
00017         self.assertEqual(list('spam'), ['s', 'p', 'a', 'm'])
00018 
00019         if sys.maxsize == 0x7fffffff:
00020             # This test can currently only work on 32-bit machines.
00021             # XXX If/when PySequence_Length() returns a ssize_t, it should be
00022             # XXX re-enabled.
00023             # Verify clearing of bug #556025.
00024             # This assumes that the max data size (sys.maxint) == max
00025             # address size this also assumes that the address size is at
00026             # least 4 bytes with 8 byte addresses, the bug is not well
00027             # tested
00028             #
00029             # Note: This test is expected to SEGV under Cygwin 1.3.12 or
00030             # earlier due to a newlib bug.  See the following mailing list
00031             # thread for the details:
00032 
00033             #     http://sources.redhat.com/ml/newlib/2002/msg00369.html
00034             self.assertRaises(MemoryError, list, range(sys.maxsize // 2))
00035 
00036         # This code used to segfault in Py2.4a3
00037         x = []
00038         x.extend(-y for y in x)
00039         self.assertEqual(x, [])

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_bigrepeat (   self) [inherited]

Definition at line 306 of file seq_tests.py.

00306 
00307     def test_bigrepeat(self):
00308         import sys
00309         if sys.maxsize <= 2147483647:
00310             x = self.type2test([0])
00311             x *= 2**16
00312             self.assertRaises(MemoryError, x.__mul__, 2**16)
00313             if hasattr(x, '__imul__'):
00314                 self.assertRaises(MemoryError, x.__imul__, 2**16)

Here is the call graph for this function:

Definition at line 539 of file list_tests.py.

00539 
00540     def test_constructor_exception_handling(self):
00541         # Bug #1242657
00542         class F(object):
00543             def __iter__(self):
00544                 raise KeyboardInterrupt
00545         self.assertRaises(KeyboardInterrupt, list, F())

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_constructors (   self) [inherited]

Reimplemented in test.test_tuple.TupleTest.

Definition at line 91 of file seq_tests.py.

00091 
00092     def test_constructors(self):
00093         l0 = []
00094         l1 = [0]
00095         l2 = [0, 1]
00096 
00097         u = self.type2test()
00098         u0 = self.type2test(l0)
00099         u1 = self.type2test(l1)
00100         u2 = self.type2test(l2)
00101 
00102         uu = self.type2test(u)
00103         uu0 = self.type2test(u0)
00104         uu1 = self.type2test(u1)
00105         uu2 = self.type2test(u2)
00106 
00107         v = self.type2test(tuple(u))
00108         class OtherSeq:
00109             def __init__(self, initseq):
00110                 self.__data = initseq
00111             def __len__(self):
00112                 return len(self.__data)
00113             def __getitem__(self, i):
00114                 return self.__data[i]
00115         s = OtherSeq(u0)
00116         v0 = self.type2test(s)
00117         self.assertEqual(len(v0), len(s))
00118 
00119         s = "this is also a sequence"
00120         vv = self.type2test(s)
00121         self.assertEqual(len(vv), len(s))
00122 
00123         # Create from various iteratables
00124         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
00125             for g in (Sequence, IterFunc, IterGen,
00126                       itermulti, iterfunc):
00127                 self.assertEqual(self.type2test(g(s)), self.type2test(s))
00128             self.assertEqual(self.type2test(IterFuncStop(s)), self.type2test())
00129             self.assertEqual(self.type2test(c for c in "123"), self.type2test("123"))
00130             self.assertRaises(TypeError, self.type2test, IterNextOnly(s))
00131             self.assertRaises(TypeError, self.type2test, IterNoNext(s))
00132             self.assertRaises(ZeroDivisionError, self.type2test, IterGenExc(s))

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_contains (   self) [inherited]

Definition at line 199 of file seq_tests.py.

00199 
00200     def test_contains(self):
00201         u = self.type2test([0, 1, 2])
00202         for i in u:
00203             self.assertIn(i, u)
00204         for i in min(u)-1, max(u)+1:
00205             self.assertNotIn(i, u)
00206 
00207         self.assertRaises(TypeError, u.__contains__)

Here is the call graph for this function:

Definition at line 208 of file seq_tests.py.

00208 
00209     def test_contains_fake(self):
00210         class AllEq:
00211             # Sequences must use rich comparison against each item
00212             # (unless "is" is true, or an earlier item answered)
00213             # So instances of AllEq must be found in all non-empty sequences.
00214             def __eq__(self, other):
00215                 return True
00216             __hash__ = None # Can't meet hash invariant requirements
00217         self.assertNotIn(AllEq(), self.type2test([]))
00218         self.assertIn(AllEq(), self.type2test([1]))

Here is the call graph for this function:

Definition at line 219 of file seq_tests.py.

00219 
00220     def test_contains_order(self):
00221         # Sequences must test in-order.  If a rich comparison has side
00222         # effects, these will be visible to tests against later members.
00223         # In this test, the "side effect" is a short-circuiting raise.
00224         class DoNotTestEq(Exception):
00225             pass
00226         class StopCompares:
00227             def __eq__(self, other):
00228                 raise DoNotTestEq
00229 
00230         checkfirst = self.type2test([1, StopCompares()])
00231         self.assertIn(1, checkfirst)
00232         checklast = self.type2test([StopCompares(), 1])
00233         self.assertRaises(DoNotTestEq, checklast.__contains__, 1)

def test.list_tests.CommonTest.test_count (   self) [inherited]

Reimplemented from test.seq_tests.CommonTest.

Definition at line 335 of file list_tests.py.

00335 
00336     def test_count(self):
00337         a = self.type2test([0, 1, 2])*3
00338         self.assertEqual(a.count(0), 3)
00339         self.assertEqual(a.count(1), 3)
00340         self.assertEqual(a.count(3), 0)
00341 
00342         self.assertRaises(TypeError, a.count)
00343 
00344         class BadExc(Exception):
00345             pass
00346 
00347         class BadCmp:
00348             def __eq__(self, other):
00349                 if other == 2:
00350                     raise BadExc()
00351                 return False
00352 
00353         self.assertRaises(BadExc, a.count, BadCmp())

Here is the call graph for this function:

def test.list_tests.CommonTest.test_delitem (   self) [inherited]

Definition at line 123 of file list_tests.py.

00123 
00124     def test_delitem(self):
00125         a = self.type2test([0, 1])
00126         del a[1]
00127         self.assertEqual(a, [0])
00128         del a[0]
00129         self.assertEqual(a, [])
00130 
00131         a = self.type2test([0, 1])
00132         del a[-2]
00133         self.assertEqual(a, [1])
00134         del a[-1]
00135         self.assertEqual(a, [])
00136 
00137         a = self.type2test([0, 1])
00138         self.assertRaises(IndexError, a.__delitem__, -3)
00139         self.assertRaises(IndexError, a.__delitem__, 2)
00140 
00141         a = self.type2test([])
00142         self.assertRaises(IndexError, a.__delitem__, 0)
00143 
00144         self.assertRaises(TypeError, a.__delitem__)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_delslice (   self) [inherited]

Definition at line 191 of file list_tests.py.

00191 
00192     def test_delslice(self):
00193         a = self.type2test([0, 1])
00194         del a[1:2]
00195         del a[0:1]
00196         self.assertEqual(a, self.type2test([]))
00197 
00198         a = self.type2test([0, 1])
00199         del a[1:2]
00200         del a[0:1]
00201         self.assertEqual(a, self.type2test([]))
00202 
00203         a = self.type2test([0, 1])
00204         del a[-2:-1]
00205         self.assertEqual(a, self.type2test([1]))
00206 
00207         a = self.type2test([0, 1])
00208         del a[-2:-1]
00209         self.assertEqual(a, self.type2test([1]))
00210 
00211         a = self.type2test([0, 1])
00212         del a[1:]
00213         del a[:1]
00214         self.assertEqual(a, self.type2test([]))
00215 
00216         a = self.type2test([0, 1])
00217         del a[1:]
00218         del a[:1]
00219         self.assertEqual(a, self.type2test([]))
00220 
00221         a = self.type2test([0, 1])
00222         del a[-1:]
00223         self.assertEqual(a, self.type2test([0]))
00224 
00225         a = self.type2test([0, 1])
00226         del a[-1:]
00227         self.assertEqual(a, self.type2test([0]))
00228 
00229         a = self.type2test([0, 1])
00230         del a[:]
00231         self.assertEqual(a, self.type2test([]))

Here is the call graph for this function:

def test.list_tests.CommonTest.test_extend (   self) [inherited]

Definition at line 241 of file list_tests.py.

00241 
00242     def test_extend(self):
00243         a1 = self.type2test([0])
00244         a2 = self.type2test((0, 1))
00245         a = a1[:]
00246         a.extend(a2)
00247         self.assertEqual(a, a1 + a2)
00248 
00249         a.extend(self.type2test([]))
00250         self.assertEqual(a, a1 + a2)
00251 
00252         a.extend(a)
00253         self.assertEqual(a, self.type2test([0, 0, 1, 0, 0, 1]))
00254 
00255         a = self.type2test("spam")
00256         a.extend("eggs")
00257         self.assertEqual(a, list("spameggs"))
00258 
00259         self.assertRaises(TypeError, a.extend, None)
00260 
00261         self.assertRaises(TypeError, a.extend)

Here is the call graph for this function:

Definition at line 498 of file list_tests.py.

00498 
00499     def test_extendedslicing(self):
00500         #  subscript
00501         a = self.type2test([0,1,2,3,4])
00502 
00503         #  deletion
00504         del a[::2]
00505         self.assertEqual(a, self.type2test([1,3]))
00506         a = self.type2test(range(5))
00507         del a[1::2]
00508         self.assertEqual(a, self.type2test([0,2,4]))
00509         a = self.type2test(range(5))
00510         del a[1::-2]
00511         self.assertEqual(a, self.type2test([0,2,3,4]))
00512         a = self.type2test(range(10))
00513         del a[::1000]
00514         self.assertEqual(a, self.type2test([1, 2, 3, 4, 5, 6, 7, 8, 9]))
00515         #  assignment
00516         a = self.type2test(range(10))
00517         a[::2] = [-1]*5
00518         self.assertEqual(a, self.type2test([-1, 1, -1, 3, -1, 5, -1, 7, -1, 9]))
00519         a = self.type2test(range(10))
00520         a[::-4] = [10]*3
00521         self.assertEqual(a, self.type2test([0, 10, 2, 3, 4, 10, 6, 7, 8 ,10]))
00522         a = self.type2test(range(4))
00523         a[::-1] = a
00524         self.assertEqual(a, self.type2test([3, 2, 1, 0]))
00525         a = self.type2test(range(10))
00526         b = a[:]
00527         c = a[:]
00528         a[2:3] = self.type2test(["two", "elements"])
00529         b[slice(2,3)] = self.type2test(["two", "elements"])
00530         c[2:3:] = self.type2test(["two", "elements"])
00531         self.assertEqual(a, b)
00532         self.assertEqual(a, c)
00533         a = self.type2test(range(10))
00534         a[::2] = tuple(range(5))
00535         self.assertEqual(a, self.type2test([0, 1, 1, 3, 2, 5, 3, 7, 4, 9]))
00536         # test issue7788
00537         a = self.type2test(range(10))
00538         del a[9::1<<333]

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_getitem (   self) [inherited]

Definition at line 137 of file seq_tests.py.

00137 
00138     def test_getitem(self):
00139         u = self.type2test([0, 1, 2, 3, 4])
00140         for i in range(len(u)):
00141             self.assertEqual(u[i], i)
00142             self.assertEqual(u[int(i)], i)
00143         for i in range(-len(u), -1):
00144             self.assertEqual(u[i], len(u)+i)
00145             self.assertEqual(u[int(i)], len(u)+i)
00146         self.assertRaises(IndexError, u.__getitem__, -len(u)-1)
00147         self.assertRaises(IndexError, u.__getitem__, len(u))
00148         self.assertRaises(ValueError, u.__getitem__, slice(0,10,0))
00149 
00150         u = self.type2test()
00151         self.assertRaises(IndexError, u.__getitem__, 0)
00152         self.assertRaises(IndexError, u.__getitem__, -1)
00153 
00154         self.assertRaises(TypeError, u.__getitem__)
00155 
00156         a = self.type2test([10, 11])
00157         self.assertEqual(a[0], 10)
00158         self.assertEqual(a[1], 11)
00159         self.assertEqual(a[-2], 10)
00160         self.assertEqual(a[-1], 11)
00161         self.assertRaises(IndexError, a.__getitem__, -3)
00162         self.assertRaises(IndexError, a.__getitem__, 3)

Here is the call graph for this function:

Reimplemented in test.test_userlist.UserListTest.

Definition at line 291 of file seq_tests.py.

00291 
00292     def test_getitemoverwriteiter(self):
00293         # Verify that __getitem__ overrides are not recognized by __iter__
00294         class T(self.type2test):
00295             def __getitem__(self, key):
00296                 return str(key) + '!!!'
00297         self.assertEqual(next(iter(T((1,2)))), 1)

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_getslice (   self) [inherited]

Reimplemented in test.test_userlist.UserListTest.

Definition at line 163 of file seq_tests.py.

00163 
00164     def test_getslice(self):
00165         l = [0, 1, 2, 3, 4]
00166         u = self.type2test(l)
00167 
00168         self.assertEqual(u[0:0], self.type2test())
00169         self.assertEqual(u[1:2], self.type2test([1]))
00170         self.assertEqual(u[-2:-1], self.type2test([3]))
00171         self.assertEqual(u[-1000:1000], u)
00172         self.assertEqual(u[1000:-1000], self.type2test([]))
00173         self.assertEqual(u[:], u)
00174         self.assertEqual(u[1:None], self.type2test([1, 2, 3, 4]))
00175         self.assertEqual(u[None:3], self.type2test([0, 1, 2]))
00176 
00177         # Extended slices
00178         self.assertEqual(u[::], u)
00179         self.assertEqual(u[::2], self.type2test([0, 2, 4]))
00180         self.assertEqual(u[1::2], self.type2test([1, 3]))
00181         self.assertEqual(u[::-1], self.type2test([4, 3, 2, 1, 0]))
00182         self.assertEqual(u[::-2], self.type2test([4, 2, 0]))
00183         self.assertEqual(u[3::-2], self.type2test([3, 1]))
00184         self.assertEqual(u[3:3:-2], self.type2test([]))
00185         self.assertEqual(u[3:2:-2], self.type2test([3]))
00186         self.assertEqual(u[3:1:-2], self.type2test([3]))
00187         self.assertEqual(u[3:0:-2], self.type2test([3, 1]))
00188         self.assertEqual(u[::-100], self.type2test([4]))
00189         self.assertEqual(u[100:-100:], self.type2test([]))
00190         self.assertEqual(u[-100:100:], u)
00191         self.assertEqual(u[100:-100:-1], u[::-1])
00192         self.assertEqual(u[-100:100:-1], self.type2test([]))
00193         self.assertEqual(u[-100:100:2], self.type2test([0, 2, 4]))
00194 
00195         # Test extreme cases with long ints
00196         a = self.type2test([0,1,2,3,4])
00197         self.assertEqual(a[ -pow(2,128): 3 ], self.type2test([0,1,2]))
00198         self.assertEqual(a[ 3: pow(2,145) ], self.type2test([3,4]))

Here is the call graph for this function:

def test.list_tests.CommonTest.test_iadd (   self) [inherited]

Reimplemented from test.seq_tests.CommonTest.

Reimplemented in test.test_userlist.UserListTest.

Definition at line 474 of file list_tests.py.

00474 
00475     def test_iadd(self):
00476         super().test_iadd()
00477         u = self.type2test([0, 1])
00478         u2 = u
00479         u += [2, 3]
00480         self.assertIs(u, u2)
00481 
00482         u = self.type2test("spam")
00483         u += "eggs"
00484         self.assertEqual(u, self.type2test("spameggs"))
00485 
00486         self.assertRaises(TypeError, u.__iadd__, None)

Here is the call graph for this function:

Definition at line 45 of file test_list.py.

00045 
00046     def test_identity(self):
00047         self.assertTrue([] is not [])

Here is the call graph for this function:

def test.list_tests.CommonTest.test_imul (   self) [inherited]

Reimplemented from test.seq_tests.CommonTest.

Definition at line 487 of file list_tests.py.

00487 
00488     def test_imul(self):
00489         u = self.type2test([0, 1])
00490         u *= 3
00491         self.assertEqual(u, self.type2test([0, 1, 0, 1, 0, 1]))
00492         u *= 0
00493         self.assertEqual(u, self.type2test([]))
00494         s = self.type2test([])
00495         oldid = id(s)
00496         s *= 10
00497         self.assertEqual(id(s), oldid)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_index (   self) [inherited]

Reimplemented from test.seq_tests.CommonTest.

Definition at line 354 of file list_tests.py.

00354 
00355     def test_index(self):
00356         u = self.type2test([0, 1])
00357         self.assertEqual(u.index(0), 0)
00358         self.assertEqual(u.index(1), 1)
00359         self.assertRaises(ValueError, u.index, 2)
00360 
00361         u = self.type2test([-2, -1, 0, 0, 1, 2])
00362         self.assertEqual(u.count(0), 2)
00363         self.assertEqual(u.index(0), 2)
00364         self.assertEqual(u.index(0, 2), 2)
00365         self.assertEqual(u.index(-2, -10), 0)
00366         self.assertEqual(u.index(0, 3), 3)
00367         self.assertEqual(u.index(0, 3, 4), 3)
00368         self.assertRaises(ValueError, u.index, 2, 0, -10)
00369 
00370         self.assertRaises(TypeError, u.index)
00371 
00372         class BadExc(Exception):
00373             pass
00374 
00375         class BadCmp:
00376             def __eq__(self, other):
00377                 if other == 2:
00378                     raise BadExc()
00379                 return False
00380 
00381         a = self.type2test([0, 1, 2, 3])
00382         self.assertRaises(BadExc, a.index, BadCmp())
00383 
00384         a = self.type2test([-2, -1, 0, 0, 1, 2])
00385         self.assertEqual(a.index(0), 2)
00386         self.assertEqual(a.index(0, 2), 2)
00387         self.assertEqual(a.index(0, -4), 2)
00388         self.assertEqual(a.index(-2, -10), 0)
00389         self.assertEqual(a.index(0, 3), 3)
00390         self.assertEqual(a.index(0, -3), 3)
00391         self.assertEqual(a.index(0, 3, 4), 3)
00392         self.assertEqual(a.index(0, -3, -2), 3)
00393         self.assertEqual(a.index(0, -4*sys.maxsize, 4*sys.maxsize), 2)
00394         self.assertRaises(ValueError, a.index, 0, 4*sys.maxsize,-4*sys.maxsize)
00395         self.assertRaises(ValueError, a.index, 2, 0, -10)
00396         a.remove(0)
00397         self.assertRaises(ValueError, a.index, 2, 0, 4)
00398         self.assertEqual(a, self.type2test([-2, -1, 0, 1, 2]))
00399 
00400         # Test modifying the list during index's iteration
00401         class EvilCmp:
00402             def __init__(self, victim):
00403                 self.victim = victim
00404             def __eq__(self, other):
00405                 del self.victim[:]
00406                 return False
00407         a = self.type2test()
00408         a[:] = [EvilCmp(a) for _ in range(100)]
00409         # This used to seg fault before patch #1005778
00410         self.assertRaises(ValueError, a.index, None)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_init (   self) [inherited]

Definition at line 14 of file list_tests.py.

00014 
00015     def test_init(self):
00016         # Iterable arg is optional
00017         self.assertEqual(self.type2test([]), self.type2test())
00018 
00019         # Init clears previous values
00020         a = self.type2test([1, 2, 3])
00021         a.__init__()
00022         self.assertEqual(a, self.type2test([]))
00023 
00024         # Init overwrites previous values
00025         a = self.type2test([1, 2, 3])
00026         a.__init__([4, 5, 6])
00027         self.assertEqual(a, self.type2test([4, 5, 6]))
00028 
00029         # Mutables always return a new object
00030         b = self.type2test(a)
00031         self.assertNotEqual(id(a), id(b))
00032         self.assertEqual(a, b)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_insert (   self) [inherited]

Definition at line 262 of file list_tests.py.

00262 
00263     def test_insert(self):
00264         a = self.type2test([0, 1, 2])
00265         a.insert(0, -2)
00266         a.insert(1, -1)
00267         a.insert(2, 0)
00268         self.assertEqual(a, [-2, -1, 0, 0, 1, 2])
00269 
00270         b = a[:]
00271         b.insert(-2, "foo")
00272         b.insert(-200, "left")
00273         b.insert(200, "right")
00274         self.assertEqual(b, self.type2test(["left",-2,-1,0,0,"foo",1,2,"right"]))
00275 
00276         self.assertRaises(TypeError, a.insert)

Here is the call graph for this function:

Reimplemented from test.seq_tests.CommonTest.

Definition at line 48 of file test_list.py.

00048 
00049     def test_len(self):
00050         super().test_len()
00051         self.assertEqual(len([]), 0)
00052         self.assertEqual(len([0]), 1)
00053         self.assertEqual(len([0, 1, 2]), 3)

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_minmax (   self) [inherited]

Definition at line 240 of file seq_tests.py.

00240 
00241     def test_minmax(self):
00242         u = self.type2test([0, 1, 2])
00243         self.assertEqual(min(u), 0)
00244         self.assertEqual(max(u), 2)

Here is the call graph for this function:

Definition at line 54 of file test_list.py.

00054 
00055     def test_overflow(self):
00056         lst = [4, 5, 6, 7]
00057         n = int((sys.maxsize*2+2) // len(lst))
00058         def mul(a, b): return a * b
00059         def imul(a, b): a *= b
00060         self.assertRaises((MemoryError, OverflowError), mul, lst, n)
00061         self.assertRaises((MemoryError, OverflowError), imul, lst, n)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_pop (   self) [inherited]

Definition at line 277 of file list_tests.py.

00277 
00278     def test_pop(self):
00279         a = self.type2test([-1, 0, 1])
00280         a.pop()
00281         self.assertEqual(a, [-1, 0])
00282         a.pop(0)
00283         self.assertEqual(a, [0])
00284         self.assertRaises(IndexError, a.pop, 5)
00285         a.pop(0)
00286         self.assertEqual(a, [])
00287         self.assertRaises(IndexError, a.pop)
00288         self.assertRaises(TypeError, a.pop, 42, 42)
00289         a = self.type2test([0, 10, 20, 30, 40])

Here is the call graph for this function:

def test.list_tests.CommonTest.test_print (   self) [inherited]

Definition at line 55 of file list_tests.py.

00055 
00056     def test_print(self):
00057         d = self.type2test(range(200))
00058         d.append(d)
00059         d.extend(range(200,400))
00060         d.append(d)
00061         d.append(400)
00062         try:
00063             with open(support.TESTFN, "w") as fo:
00064                 fo.write(str(d))
00065             with open(support.TESTFN, "r") as fo:
00066                 self.assertEqual(fo.read(), repr(d))
00067         finally:
00068             os.remove(support.TESTFN)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_remove (   self) [inherited]

Definition at line 290 of file list_tests.py.

00290 
00291     def test_remove(self):
00292         a = self.type2test([0, 0, 1])
00293         a.remove(1)
00294         self.assertEqual(a, [0, 0])
00295         a.remove(0)
00296         self.assertEqual(a, [0])
00297         a.remove(0)
00298         self.assertEqual(a, [])
00299 
00300         self.assertRaises(ValueError, a.remove, 0)
00301 
00302         self.assertRaises(TypeError, a.remove)
00303 
00304         class BadExc(Exception):
00305             pass
00306 
00307         class BadCmp:
00308             def __eq__(self, other):
00309                 if other == 2:
00310                     raise BadExc()
00311                 return False
00312 
00313         a = self.type2test([0, 1, 2, 3])
00314         self.assertRaises(BadExc, a.remove, BadCmp())
00315 
00316         class BadCmp2:
00317             def __eq__(self, other):
00318                 raise BadExc()
00319 
00320         d = self.type2test('abcdefghcij')
00321         d.remove('c')
00322         self.assertEqual(d, self.type2test('abdefghcij'))
00323         d.remove('c')
00324         self.assertEqual(d, self.type2test('abdefghij'))
00325         self.assertRaises(ValueError, d.remove, 'c')
00326         self.assertEqual(d, self.type2test('abdefghij'))
00327 
00328         # Handle comparison errors
00329         d = self.type2test(['a', 'b', BadCmp2(), 'c'])
00330         e = self.type2test(d)
00331         self.assertRaises(BadExc, d.remove, 'c')
00332         for x, y in zip(d, e):
00333             # verify that original order and values are retained.
00334             self.assertIs(x, y)

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_repeat (   self) [inherited]

Definition at line 298 of file seq_tests.py.

00298 
00299     def test_repeat(self):
00300         for m in range(4):
00301             s = tuple(range(m))
00302             for n in range(-3, 5):
00303                 self.assertEqual(self.type2test(s*n), self.type2test(s)*n)
00304             self.assertEqual(self.type2test(s)*(-4), self.type2test([]))
00305             self.assertEqual(id(s), id(s*1))

Here is the call graph for this function:

def test.list_tests.CommonTest.test_repr (   self) [inherited]

Definition at line 33 of file list_tests.py.

00033 
00034     def test_repr(self):
00035         l0 = []
00036         l2 = [0, 1, 2]
00037         a0 = self.type2test(l0)
00038         a2 = self.type2test(l2)
00039 
00040         self.assertEqual(str(a0), str(l0))
00041         self.assertEqual(repr(a0), repr(l0))
00042         self.assertEqual(repr(a2), repr(l2))
00043         self.assertEqual(str(a2), "[0, 1, 2]")
00044         self.assertEqual(repr(a2), "[0, 1, 2]")
00045 
00046         a2.append(a2)
00047         a2.append(3)
00048         self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
00049         self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")
00050 
00051         l0 = []
00052         for i in range(sys.getrecursionlimit() + 100):
00053             l0 = [l0]
00054         self.assertRaises(RuntimeError, repr, l0)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_reverse (   self) [inherited]

Definition at line 411 of file list_tests.py.

00411 
00412     def test_reverse(self):
00413         u = self.type2test([-2, -1, 0, 1, 2])
00414         u2 = u[:]
00415         u.reverse()
00416         self.assertEqual(u, [2, 1, 0, -1, -2])
00417         u.reverse()
00418         self.assertEqual(u, u2)
00419 
00420         self.assertRaises(TypeError, u.reverse, 42)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_reversed (   self) [inherited]

Definition at line 80 of file list_tests.py.

00080 
00081     def test_reversed(self):
00082         a = self.type2test(range(20))
00083         r = reversed(a)
00084         self.assertEqual(list(r), self.type2test(range(19, -1, -1)))
00085         self.assertRaises(StopIteration, next, r)
00086         self.assertEqual(list(reversed(self.type2test())),
00087                          self.type2test())
00088         # Bug 3689: make sure list-reversed-iterator doesn't have __len__
00089         self.assertRaises(TypeError, len, reversed([1,2,3]))

Here is the call graph for this function:

Definition at line 69 of file list_tests.py.

00069 
00070     def test_set_subscript(self):
00071         a = self.type2test(range(20))
00072         self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 0), [1,2,3])
00073         self.assertRaises(TypeError, a.__setitem__, slice(0, 10), 1)
00074         self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 2), [1,2])
00075         self.assertRaises(TypeError, a.__getitem__, 'x', 1)
00076         a[slice(2,10,3)] = [1,2,3]
00077         self.assertEqual(a, self.type2test([0, 1, 1, 3, 4, 2, 6, 7, 3,
00078                                             9, 10, 11, 12, 13, 14, 15,
00079                                             16, 17, 18, 19]))

Here is the call graph for this function:

def test.list_tests.CommonTest.test_setitem (   self) [inherited]

Definition at line 90 of file list_tests.py.

00090 
00091     def test_setitem(self):
00092         a = self.type2test([0, 1])
00093         a[0] = 0
00094         a[1] = 100
00095         self.assertEqual(a, self.type2test([0, 100]))
00096         a[-1] = 200
00097         self.assertEqual(a, self.type2test([0, 200]))
00098         a[-2] = 100
00099         self.assertEqual(a, self.type2test([100, 200]))
00100         self.assertRaises(IndexError, a.__setitem__, -3, 200)
00101         self.assertRaises(IndexError, a.__setitem__, 2, 200)
00102 
00103         a = self.type2test([])
00104         self.assertRaises(IndexError, a.__setitem__, 0, 200)
00105         self.assertRaises(IndexError, a.__setitem__, -1, 200)
00106         self.assertRaises(TypeError, a.__setitem__)
00107 
00108         a = self.type2test([0,1,2,3,4])
00109         a[0] = 1
00110         a[1] = 2
00111         a[2] = 3
00112         self.assertEqual(a, self.type2test([1,2,3,3,4]))
00113         a[0] = 5
00114         a[1] = 6
00115         a[2] = 7
00116         self.assertEqual(a, self.type2test([5,6,7,3,4]))
00117         a[-2] = 88
00118         a[-1] = 99
00119         self.assertEqual(a, self.type2test([5,6,7,88,99]))
00120         a[-2] = 8
00121         a[-1] = 9
00122         self.assertEqual(a, self.type2test([5,6,7,8,9]))

Here is the call graph for this function:

def test.list_tests.CommonTest.test_setslice (   self) [inherited]

Definition at line 145 of file list_tests.py.

00145 
00146     def test_setslice(self):
00147         l = [0, 1]
00148         a = self.type2test(l)
00149 
00150         for i in range(-3, 4):
00151             a[:i] = l[:i]
00152             self.assertEqual(a, l)
00153             a2 = a[:]
00154             a2[:i] = a[:i]
00155             self.assertEqual(a2, a)
00156             a[i:] = l[i:]
00157             self.assertEqual(a, l)
00158             a2 = a[:]
00159             a2[i:] = a[i:]
00160             self.assertEqual(a2, a)
00161             for j in range(-3, 4):
00162                 a[i:j] = l[i:j]
00163                 self.assertEqual(a, l)
00164                 a2 = a[:]
00165                 a2[i:j] = a[i:j]
00166                 self.assertEqual(a2, a)
00167 
00168         aa2 = a2[:]
00169         aa2[:0] = [-2, -1]
00170         self.assertEqual(aa2, [-2, -1, 0, 1])
00171         aa2[0:] = []
00172         self.assertEqual(aa2, [])
00173 
00174         a = self.type2test([1, 2, 3, 4, 5])
00175         a[:-1] = a
00176         self.assertEqual(a, self.type2test([1, 2, 3, 4, 5, 5]))
00177         a = self.type2test([1, 2, 3, 4, 5])
00178         a[1:] = a
00179         self.assertEqual(a, self.type2test([1, 1, 2, 3, 4, 5]))
00180         a = self.type2test([1, 2, 3, 4, 5])
00181         a[1:-1] = a
00182         self.assertEqual(a, self.type2test([1, 1, 2, 3, 4, 5, 5]))
00183 
00184         a = self.type2test([])
00185         a[:] = tuple(range(10))
00186         self.assertEqual(a, self.type2test(range(10)))
00187 
00188         self.assertRaises(TypeError, a.__setitem__, slice(0, 1, 5))
00189 
00190         self.assertRaises(TypeError, a.__setitem__)

Here is the call graph for this function:

def test.list_tests.CommonTest.test_slice (   self) [inherited]

Definition at line 469 of file list_tests.py.

00469 
00470     def test_slice(self):
00471         u = self.type2test("spam")
00472         u[:2] = "h"
00473         self.assertEqual(u, list("ham"))

Here is the call graph for this function:

def test.list_tests.CommonTest.test_sort (   self) [inherited]

Definition at line 421 of file list_tests.py.

00421 
00422     def test_sort(self):
00423         u = self.type2test([1, 0])
00424         u.sort()
00425         self.assertEqual(u, [0, 1])
00426 
00427         u = self.type2test([2,1,0,-1,-2])
00428         u.sort()
00429         self.assertEqual(u, self.type2test([-2,-1,0,1,2]))
00430 
00431         self.assertRaises(TypeError, u.sort, 42, 42)
00432 
00433         def revcmp(a, b):
00434             if a == b:
00435                 return 0
00436             elif a < b:
00437                 return 1
00438             else: # a > b
00439                 return -1
00440         u.sort(key=cmp_to_key(revcmp))
00441         self.assertEqual(u, self.type2test([2,1,0,-1,-2]))
00442 
00443         # The following dumps core in unpatched Python 1.5:
00444         def myComparison(x,y):
00445             xmod, ymod = x%3, y%7
00446             if xmod == ymod:
00447                 return 0
00448             elif xmod < ymod:
00449                 return -1
00450             else: # xmod > ymod
00451                 return 1
00452         z = self.type2test(range(12))
00453         z.sort(key=cmp_to_key(myComparison))
00454 
00455         self.assertRaises(TypeError, z.sort, 2)
00456 
00457         def selfmodifyingComparison(x,y):
00458             z.append(1)
00459             if x == y:
00460                 return 0
00461             elif x < y:
00462                 return -1
00463             else: # x > y
00464                 return 1
00465         self.assertRaises(ValueError, z.sort,
00466                           key=cmp_to_key(selfmodifyingComparison))
00467 
00468         self.assertRaises(TypeError, z.sort, 42, 42, 42, 42)

Here is the call graph for this function:

def test.seq_tests.CommonTest.test_subscript (   self) [inherited]

Definition at line 315 of file seq_tests.py.

00315 
00316     def test_subscript(self):
00317         a = self.type2test([10, 11])
00318         self.assertEqual(a.__getitem__(0), 10)
00319         self.assertEqual(a.__getitem__(1), 11)
00320         self.assertEqual(a.__getitem__(-2), 10)
00321         self.assertEqual(a.__getitem__(-1), 11)
00322         self.assertRaises(IndexError, a.__getitem__, -3)
00323         self.assertRaises(IndexError, a.__getitem__, 3)
00324         self.assertEqual(a.__getitem__(slice(0,1)), self.type2test([10]))
00325         self.assertEqual(a.__getitem__(slice(1,2)), self.type2test([11]))
00326         self.assertEqual(a.__getitem__(slice(0,2)), self.type2test([10, 11]))
00327         self.assertEqual(a.__getitem__(slice(0,3)), self.type2test([10, 11]))
00328         self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([]))
00329         self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0))
00330         self.assertRaises(TypeError, a.__getitem__, 'x')

Here is the call graph for this function:

Reimplemented from test.seq_tests.CommonTest.

Definition at line 40 of file test_list.py.

00040 
00041     def test_truth(self):
00042         super().test_truth()
00043         self.assertTrue(not [])
00044         self.assertTrue([42])

Here is the call graph for this function:


Member Data Documentation

Reimplemented from test.seq_tests.CommonTest.

Definition at line 5 of file test_list.py.

Definition at line 402 of file list_tests.py.


The documentation for this class was generated from the following file: