• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Check every path through every method of UserList
2
3from UserList import UserList
4from test import test_support, list_tests
5
6class UserListTest(list_tests.CommonTest):
7    type2test = UserList
8
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])
18
19    def test_add_specials(self):
20        u = UserList("spam")
21        u2 = u + "eggs"
22        self.assertEqual(u2, list("spameggs"))
23
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"))
30
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])
36
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])
42
43    def test_mixedadd(self):
44        u = self.type2test([0, 1])
45        self.assertEqual(u + [], u)
46        self.assertEqual(u + [2], [0, 1, 2])
47
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!!!")
54
55def test_main():
56    with test_support.check_py3k_warnings(
57            (".+__(get|set|del)slice__ has been removed", DeprecationWarning)):
58        test_support.run_unittest(UserListTest)
59
60if __name__ == "__main__":
61    test_main()
62