move sections
[python/dscho.git] / Lib / test / test_userlist.py
blob3b601bc955c0fbdffac689b900c7abf2708782d0
1 # Check every path through every method of UserList
3 from UserList import UserList
4 from test import test_support, list_tests
6 class UserListTest(list_tests.CommonTest):
7 type2test = UserList
9 def test_getslice(self):
10 super(UserListTest, self).test_getslice()
11 l = [0, 1, 2, 3, 4]
12 u = self.type2test(l)
13 for i in range(-3, 6):
14 self.assertEqual(u[:i], l[:i])
15 self.assertEqual(u[i:], l[i:])
16 for j in xrange(-3, 6):
17 self.assertEqual(u[i:j], l[i:j])
19 def test_add_specials(self):
20 u = UserList("spam")
21 u2 = u + "eggs"
22 self.assertEqual(u2, list("spameggs"))
24 def test_radd_specials(self):
25 u = UserList("eggs")
26 u2 = "spam" + u
27 self.assertEqual(u2, list("spameggs"))
28 u2 = u.__radd__(UserList("spam"))
29 self.assertEqual(u2, list("spameggs"))
31 def test_iadd(self):
32 super(UserListTest, self).test_iadd()
33 u = [0, 1]
34 u += UserList([0, 1])
35 self.assertEqual(u, [0, 1, 0, 1])
37 def test_mixedcmp(self):
38 u = self.type2test([0, 1])
39 self.assertEqual(u, [0, 1])
40 self.assertNotEqual(u, [0])
41 self.assertNotEqual(u, [0, 2])
43 def test_mixedadd(self):
44 u = self.type2test([0, 1])
45 self.assertEqual(u + [], u)
46 self.assertEqual(u + [2], [0, 1, 2])
48 def test_getitemoverwriteiter(self):
49 # Verify that __getitem__ overrides *are* recognized by __iter__
50 class T(self.type2test):
51 def __getitem__(self, key):
52 return str(key) + '!!!'
53 self.assertEqual(iter(T((1,2))).next(), "0!!!")
55 def test_main():
56 with test_support.check_py3k_warnings(
57 (".+__(get|set|del)slice__ has been removed", DeprecationWarning)):
58 test_support.run_unittest(UserListTest)
60 if __name__ == "__main__":
61 test_main()