ยปCore Development>Code coverage>Lib/test/test_userlist.py

# Python code coverage for Lib/test/test_userlist.py

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