PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/test/test_userlist.py

http://unladen-swallow.googlecode.com/
Python | 59 lines | 46 code | 11 blank | 2 comment | 5 complexity | f731408dfd9290e2417cfda844840561 MD5 | raw file
 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    test_support.run_unittest(UserListTest)
57
58if __name__ == "__main__":
59    test_main()