0001 # Check every path through every method of UserList 0002 0003 from UserList import UserList 0004 import unittest 0005 from test import test_support, list_tests 0006 0007 class UserListTest(list_tests.CommonTest): 0008 type2test = UserList 0009 0010 def test_getslice(self): 0011 super(UserListTest, self).test_getslice() 0012 l = [0, 1, 2, 3, 4] 0013 u = self.type2test(l) 0014 for i in range(-3, 6): 0015 self.assertEqual(u[:i], l[:i]) 0016 self.assertEqual(u[i:], l[i:]) 0017 for j in xrange(-3, 6): 0018 self.assertEqual(u[i:j], l[i:j]) 0019 0020 def test_add_specials(self): 0021 u = UserList("spam") 0022 u2 = u + "eggs" 0023 self.assertEqual(u2, list("spameggs")) 0024 0025 def test_radd_specials(self): 0026 u = UserList("eggs") 0027 u2 = "spam" + u 0028 self.assertEqual(u2, list("spameggs")) 0029 u2 = u.__radd__(UserList("spam")) 0030 self.assertEqual(u2, list("spameggs")) 0031 0032 def test_iadd(self): 0033 super(UserListTest, self).test_iadd() 0034 u = [0, 1] 0035 u += UserList([0, 1]) 0036 self.assertEqual(u, [0, 1, 0, 1]) 0037 0038 def test_mixedcmp(self): 0039 u = self.type2test([0, 1]) 0040 self.assertEqual(u, [0, 1]) 0041 self.assertNotEqual(u, [0]) 0042 self.assertNotEqual(u, [0, 2]) 0043 0044 def test_mixedadd(self): 0045 u = self.type2test([0, 1]) 0046 self.assertEqual(u + [], u) 0047 self.assertEqual(u + [2], [0, 1, 2]) 0048 0049 def test_getitemoverwriteiter(self): 0050 # Verify that __getitem__ overrides *are* recognized by __iter__ 0051 class T(self.type2test): 0052 def __getitem__(self, key): 0053 return str(key) + '!!!' 0054 self.assertEqual(iter(T((1,2))).next(), "0!!!") 0055 0056 def test_main(): 0057 test_support.run_unittest(UserListTest) 0058 0059 if __name__ == "__main__": 0060 test_main() 0061
Generated by PyXR 0.9.4