1 | n/a | # Check every path through every method of UserList |
---|
2 | n/a | |
---|
3 | n/a | from collections import UserList |
---|
4 | n/a | from test import list_tests |
---|
5 | n/a | import unittest |
---|
6 | n/a | |
---|
7 | n/a | class UserListTest(list_tests.CommonTest): |
---|
8 | n/a | type2test = UserList |
---|
9 | n/a | |
---|
10 | n/a | def test_getslice(self): |
---|
11 | n/a | super().test_getslice() |
---|
12 | n/a | l = [0, 1, 2, 3, 4] |
---|
13 | n/a | u = self.type2test(l) |
---|
14 | n/a | for i in range(-3, 6): |
---|
15 | n/a | self.assertEqual(u[:i], l[:i]) |
---|
16 | n/a | self.assertEqual(u[i:], l[i:]) |
---|
17 | n/a | for j in range(-3, 6): |
---|
18 | n/a | self.assertEqual(u[i:j], l[i:j]) |
---|
19 | n/a | |
---|
20 | n/a | def test_add_specials(self): |
---|
21 | n/a | u = UserList("spam") |
---|
22 | n/a | u2 = u + "eggs" |
---|
23 | n/a | self.assertEqual(u2, list("spameggs")) |
---|
24 | n/a | |
---|
25 | n/a | def test_radd_specials(self): |
---|
26 | n/a | u = UserList("eggs") |
---|
27 | n/a | u2 = "spam" + u |
---|
28 | n/a | self.assertEqual(u2, list("spameggs")) |
---|
29 | n/a | u2 = u.__radd__(UserList("spam")) |
---|
30 | n/a | self.assertEqual(u2, list("spameggs")) |
---|
31 | n/a | |
---|
32 | n/a | def test_iadd(self): |
---|
33 | n/a | super().test_iadd() |
---|
34 | n/a | u = [0, 1] |
---|
35 | n/a | u += UserList([0, 1]) |
---|
36 | n/a | self.assertEqual(u, [0, 1, 0, 1]) |
---|
37 | n/a | |
---|
38 | n/a | def test_mixedcmp(self): |
---|
39 | n/a | u = self.type2test([0, 1]) |
---|
40 | n/a | self.assertEqual(u, [0, 1]) |
---|
41 | n/a | self.assertNotEqual(u, [0]) |
---|
42 | n/a | self.assertNotEqual(u, [0, 2]) |
---|
43 | n/a | |
---|
44 | n/a | def test_mixedadd(self): |
---|
45 | n/a | u = self.type2test([0, 1]) |
---|
46 | n/a | self.assertEqual(u + [], u) |
---|
47 | n/a | self.assertEqual(u + [2], [0, 1, 2]) |
---|
48 | n/a | |
---|
49 | n/a | def test_getitemoverwriteiter(self): |
---|
50 | n/a | # Verify that __getitem__ overrides *are* recognized by __iter__ |
---|
51 | n/a | class T(self.type2test): |
---|
52 | n/a | def __getitem__(self, key): |
---|
53 | n/a | return str(key) + '!!!' |
---|
54 | n/a | self.assertEqual(next(iter(T((1,2)))), "0!!!") |
---|
55 | n/a | |
---|
56 | n/a | def test_userlist_copy(self): |
---|
57 | n/a | u = self.type2test([6, 8, 1, 9, 1]) |
---|
58 | n/a | v = u.copy() |
---|
59 | n/a | self.assertEqual(u, v) |
---|
60 | n/a | self.assertEqual(type(u), type(v)) |
---|
61 | n/a | |
---|
62 | n/a | if __name__ == "__main__": |
---|
63 | n/a | unittest.main() |
---|