Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_userlist.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
| 10482 | 1 # Check every path through every method of UserList |
| 2 | |
| 3 from UserList import UserList | |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
4 from test import test_support, list_tests |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
5 |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
6 class UserListTest(list_tests.CommonTest): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
7 type2test = UserList |
| 10482 | 8 |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
9 def test_getslice(self): |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
10 super(UserListTest, self).test_getslice() |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
11 l = [0, 1, 2, 3, 4] |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
12 u = self.type2test(l) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
13 for i in range(-3, 6): |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
14 self.assertEqual(u[:i], l[:i]) |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
15 self.assertEqual(u[i:], l[i:]) |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
16 for j in xrange(-3, 6): |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
17 self.assertEqual(u[i:j], l[i:j]) |
| 10482 | 18 |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
19 def test_add_specials(self): |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
20 u = UserList("spam") |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
21 u2 = u + "eggs" |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
22 self.assertEqual(u2, list("spameggs")) |
| 10482 | 23 |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
24 def test_radd_specials(self): |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
25 u = UserList("eggs") |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
26 u2 = "spam" + u |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
27 self.assertEqual(u2, list("spameggs")) |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
28 u2 = u.__radd__(UserList("spam")) |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
29 self.assertEqual(u2, list("spameggs")) |
| 10482 | 30 |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
31 def test_iadd(self): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
32 super(UserListTest, self).test_iadd() |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
33 u = [0, 1] |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
34 u += UserList([0, 1]) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
35 self.assertEqual(u, [0, 1, 0, 1]) |
| 10482 | 36 |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
37 def test_mixedcmp(self): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
38 u = self.type2test([0, 1]) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
39 self.assertEqual(u, [0, 1]) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
40 self.assertNotEqual(u, [0]) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
41 self.assertNotEqual(u, [0, 2]) |
|
29510
01e925371d7c
SF #754014: list.index() should accept optional start, end arguments
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
42 |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
43 def test_mixedadd(self): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
44 u = self.type2test([0, 1]) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
45 self.assertEqual(u + [], u) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
46 self.assertEqual(u + [2], [0, 1, 2]) |
| 10482 | 47 |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
48 def test_getitemoverwriteiter(self): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
49 # Verify that __getitem__ overrides *are* recognized by __iter__ |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
50 class T(self.type2test): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
51 def __getitem__(self, key): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
52 return str(key) + '!!!' |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
29510
diff
changeset
|
53 self.assertEqual(iter(T((1,2))).next(), "0!!!") |
| 10482 | 54 |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
55 def test_main(): |
|
59783
c8c840162804
#7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58198
diff
changeset
|
56 with test_support.check_py3k_warnings( |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
45468
diff
changeset
|
57 (".+__(get|set|del)slice__ has been removed", DeprecationWarning)): |
|
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
45468
diff
changeset
|
58 test_support.run_unittest(UserListTest) |
| 10482 | 59 |
|
27868
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
60 if __name__ == "__main__": |
|
a52137b88eb3
Port test_userlist to PyUnit and add a few tests to increase code
Walter Dörwald <walter@livinglogic.de>
parents:
24364
diff
changeset
|
61 test_main() |
