Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_slice.py @ 65035:87f4b32905df 2.7
Cosmetic fix to use print function.
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Fri, 01 Oct 2010 10:48:47 +0000 |
| parents | c8c840162804 |
| children | 614c84670c63 |
| rev | line source |
|---|---|
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
diff
changeset
|
1 # tests for slice objects; in particular the indices method. |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
diff
changeset
|
2 |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
3 import unittest |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
4 from test import test_support |
|
41436
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
5 from cPickle import loads, dumps |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
6 |
|
26035
6ed2e23aae45
Some days, I think my comment of
Michael W. Hudson <mwh@python.net>
parents:
24674
diff
changeset
|
7 import sys |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
diff
changeset
|
8 |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
9 class SliceTest(unittest.TestCase): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
10 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
11 def test_constructor(self): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
12 self.assertRaises(TypeError, slice) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
13 self.assertRaises(TypeError, slice, 1, 2, 3, 4) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
14 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
15 def test_repr(self): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
16 self.assertEqual(repr(slice(1, 2, 3)), "slice(1, 2, 3)") |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
17 |
|
30332
6b84802c9524
SF bug #800796: Difference between hash() and __hash__()
Raymond Hettinger <python@rcn.com>
parents:
30277
diff
changeset
|
18 def test_hash(self): |
|
6b84802c9524
SF bug #800796: Difference between hash() and __hash__()
Raymond Hettinger <python@rcn.com>
parents:
30277
diff
changeset
|
19 # Verify clearing of SF bug #800796 |
|
6b84802c9524
SF bug #800796: Difference between hash() and __hash__()
Raymond Hettinger <python@rcn.com>
parents:
30277
diff
changeset
|
20 self.assertRaises(TypeError, hash, slice(5)) |
|
6b84802c9524
SF bug #800796: Difference between hash() and __hash__()
Raymond Hettinger <python@rcn.com>
parents:
30277
diff
changeset
|
21 self.assertRaises(TypeError, slice(5).__hash__) |
|
6b84802c9524
SF bug #800796: Difference between hash() and __hash__()
Raymond Hettinger <python@rcn.com>
parents:
30277
diff
changeset
|
22 |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
23 def test_cmp(self): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
24 s1 = slice(1, 2, 3) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
25 s2 = slice(1, 2, 3) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
26 s3 = slice(1, 2, 4) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
27 self.assertEqual(s1, s2) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
28 self.assertNotEqual(s1, s3) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
29 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
30 class Exc(Exception): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
31 pass |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
32 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
33 class BadCmp(object): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
34 def __eq__(self, other): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
35 raise Exc |
|
48213
7527da2b05e8
Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents:
47781
diff
changeset
|
36 __hash__ = None # Silence Py3k warning |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
37 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
38 s1 = slice(BadCmp()) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
39 s2 = slice(BadCmp()) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
40 self.assertRaises(Exc, cmp, s1, s2) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
41 self.assertEqual(s1, s1) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
42 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
43 s1 = slice(1, BadCmp()) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
44 s2 = slice(1, BadCmp()) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
45 self.assertEqual(s1, s1) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
46 self.assertRaises(Exc, cmp, s1, s2) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
47 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
48 s1 = slice(1, 2, BadCmp()) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
49 s2 = slice(1, 2, BadCmp()) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
50 self.assertEqual(s1, s1) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
51 self.assertRaises(Exc, cmp, s1, s2) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
52 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
53 def test_members(self): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
54 s = slice(1) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
55 self.assertEqual(s.start, None) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
56 self.assertEqual(s.stop, 1) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
57 self.assertEqual(s.step, None) |
|
26035
6ed2e23aae45
Some days, I think my comment of
Michael W. Hudson <mwh@python.net>
parents:
24674
diff
changeset
|
58 |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
59 s = slice(1, 2) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
60 self.assertEqual(s.start, 1) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
61 self.assertEqual(s.stop, 2) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
62 self.assertEqual(s.step, None) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
63 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
64 s = slice(1, 2, 3) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
65 self.assertEqual(s.start, 1) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
66 self.assertEqual(s.stop, 2) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
67 self.assertEqual(s.step, 3) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
68 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
69 class AnyClass: |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
70 pass |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
71 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
72 obj = AnyClass() |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
73 s = slice(obj) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
48213
diff
changeset
|
74 self.assertTrue(s.stop is obj) |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
75 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
76 def test_indices(self): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
77 self.assertEqual(slice(None ).indices(10), (0, 10, 1)) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
78 self.assertEqual(slice(None, None, 2).indices(10), (0, 10, 2)) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
79 self.assertEqual(slice(1, None, 2).indices(10), (1, 10, 2)) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
80 self.assertEqual(slice(None, None, -1).indices(10), (9, -1, -1)) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
81 self.assertEqual(slice(None, None, -2).indices(10), (9, -1, -2)) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
82 self.assertEqual(slice(3, None, -2).indices(10), (3, -1, -2)) |
|
47781
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
83 # issue 3004 tests |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
84 self.assertEqual(slice(None, -9).indices(10), (0, 1, 1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
85 self.assertEqual(slice(None, -10).indices(10), (0, 0, 1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
86 self.assertEqual(slice(None, -11).indices(10), (0, 0, 1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
87 self.assertEqual(slice(None, -10, -1).indices(10), (9, 0, -1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
88 self.assertEqual(slice(None, -11, -1).indices(10), (9, -1, -1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
89 self.assertEqual(slice(None, -12, -1).indices(10), (9, -1, -1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
90 self.assertEqual(slice(None, 9).indices(10), (0, 9, 1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
91 self.assertEqual(slice(None, 10).indices(10), (0, 10, 1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
92 self.assertEqual(slice(None, 11).indices(10), (0, 10, 1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
93 self.assertEqual(slice(None, 8, -1).indices(10), (9, 8, -1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
94 self.assertEqual(slice(None, 9, -1).indices(10), (9, 9, -1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
95 self.assertEqual(slice(None, 10, -1).indices(10), (9, 9, -1)) |
|
d1a46350b047
Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
Mark Dickinson <dickinsm@gmail.com>
parents:
41436
diff
changeset
|
96 |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
97 self.assertEqual( |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
98 slice(-100, 100 ).indices(10), |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
99 slice(None).indices(10) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
100 ) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
101 self.assertEqual( |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
102 slice(100, -100, -1).indices(10), |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
103 slice(None, None, -1).indices(10) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
104 ) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
105 self.assertEqual(slice(-100L, 100L, 2L).indices(10), (0, 10, 2)) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
106 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
107 self.assertEqual(range(10)[::sys.maxint - 1], [0]) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
108 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
109 self.assertRaises(OverflowError, slice(None).indices, 1L<<100) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
110 |
|
41013
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
111 def test_setslice_without_getslice(self): |
|
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
112 tmp = [] |
|
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
113 class X(object): |
|
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
114 def __setslice__(self, i, j, k): |
|
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
115 tmp.append((i, j, k)) |
|
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
116 |
|
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
117 x = X() |
|
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
|
118 with test_support.check_py3k_warnings(): |
|
c8c840162804
#7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58198
diff
changeset
|
119 x[1:2] = 42 |
|
41013
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
120 self.assertEquals(tmp, [(1, 2, 42)]) |
|
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
121 |
|
41436
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
122 def test_pickle(self): |
|
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
123 s = slice(10, 20, 3) |
|
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
124 for protocol in (0,1,2): |
|
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
125 t = loads(dumps(s, protocol)) |
|
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
126 self.assertEqual(s, t) |
|
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
127 self.assertEqual(s.indices(15), t.indices(15)) |
|
0dfa2a564076
SF 1191699: Make slices picklable
Raymond Hettinger <python@rcn.com>
parents:
41013
diff
changeset
|
128 self.assertNotEqual(id(s), id(t)) |
|
41013
48254739159f
A test case for the fix in #1674228.
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
129 |
|
30277
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
130 def test_main(): |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
131 test_support.run_unittest(SliceTest) |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
132 |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
133 if __name__ == "__main__": |
|
66ba0e0ec202
SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents:
26035
diff
changeset
|
134 test_main() |
