annotate Lib/test/test_slice.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 9fe76c26ea9f
children 9214f8440c44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 44160
diff changeset
4 from test import support
42322
3e33215c66ed Getting rid of cPickle. Mmm, feels good!
Guido van Rossum <guido@python.org>
parents: 41642
diff changeset
5 from pickle 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)
42955
30511068d3d4 Fix buglet in sliceobjects, they were not returning Py_NotImplemented when
Thomas Wouters <thomas@python.org>
parents: 42322
diff changeset
29 self.assertNotEqual(s1, None)
30511068d3d4 Fix buglet in sliceobjects, they were not returning Py_NotImplemented when
Thomas Wouters <thomas@python.org>
parents: 42322
diff changeset
30 self.assertNotEqual(s1, (1, 2, 3))
30511068d3d4 Fix buglet in sliceobjects, they were not returning Py_NotImplemented when
Thomas Wouters <thomas@python.org>
parents: 42322
diff changeset
31 self.assertNotEqual(s1, "")
30277
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 Exc(Exception):
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
34 pass
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
35
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
36 class BadCmp(object):
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
37 def __eq__(self, other):
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
38 raise Exc
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
39
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
40 s1 = slice(BadCmp())
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
41 s2 = slice(BadCmp())
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
42 self.assertEqual(s1, s1)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 30332
diff changeset
43 self.assertRaises(Exc, lambda: s1 == s2)
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
44
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
45 s1 = slice(1, BadCmp())
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
46 s2 = slice(1, BadCmp())
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
47 self.assertEqual(s1, s1)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 30332
diff changeset
48 self.assertRaises(Exc, lambda: s1 == s2)
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
49
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
50 s1 = slice(1, 2, BadCmp())
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
51 s2 = slice(1, 2, BadCmp())
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
52 self.assertEqual(s1, s1)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 30332
diff changeset
53 self.assertRaises(Exc, lambda: s1 == s2)
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
54
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
55 def test_members(self):
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
56 s = slice(1)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
57 self.assertEqual(s.start, None)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
58 self.assertEqual(s.stop, 1)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
59 self.assertEqual(s.step, None)
26035
6ed2e23aae45 Some days, I think my comment of
Michael W. Hudson <mwh@python.net>
parents: 24674
diff changeset
60
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
61 s = slice(1, 2)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
62 self.assertEqual(s.start, 1)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
63 self.assertEqual(s.stop, 2)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
64 self.assertEqual(s.step, None)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
65
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
66 s = slice(1, 2, 3)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
67 self.assertEqual(s.start, 1)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
68 self.assertEqual(s.stop, 2)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
69 self.assertEqual(s.step, 3)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
70
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
71 class AnyClass:
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
72 pass
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
73
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
74 obj = AnyClass()
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
75 s = slice(obj)
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48407
diff changeset
76 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
77
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
78 def test_indices(self):
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
79 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
80 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
81 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
82 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
83 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
84 self.assertEqual(slice(3, None, -2).indices(10), (3, -1, -2))
48407
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
85 # issue 3004 tests
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
86 self.assertEqual(slice(None, -9).indices(10), (0, 1, 1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
87 self.assertEqual(slice(None, -10).indices(10), (0, 0, 1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
88 self.assertEqual(slice(None, -11).indices(10), (0, 0, 1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
89 self.assertEqual(slice(None, -10, -1).indices(10), (9, 0, -1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
90 self.assertEqual(slice(None, -11, -1).indices(10), (9, -1, -1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
91 self.assertEqual(slice(None, -12, -1).indices(10), (9, -1, -1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
92 self.assertEqual(slice(None, 9).indices(10), (0, 9, 1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
93 self.assertEqual(slice(None, 10).indices(10), (0, 10, 1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
94 self.assertEqual(slice(None, 11).indices(10), (0, 10, 1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
95 self.assertEqual(slice(None, 8, -1).indices(10), (9, 8, -1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
96 self.assertEqual(slice(None, 9, -1).indices(10), (9, 9, -1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
97 self.assertEqual(slice(None, 10, -1).indices(10), (9, 9, -1))
e22deaeb6c1b Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
98
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
99 self.assertEqual(
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
100 slice(-100, 100 ).indices(10),
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
101 slice(None).indices(10)
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
102 )
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
103 self.assertEqual(
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
104 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
105 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
106 )
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 39644
diff changeset
107 self.assertEqual(slice(-100, 100, 2).indices(10), (0, 10, 2))
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
108
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43100
diff changeset
109 self.assertEqual(list(range(10))[::sys.maxsize - 1], [0])
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
110
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 39644
diff changeset
111 self.assertRaises(OverflowError, slice(None).indices, 1<<100)
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
112
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
113 def test_setslice_without_getslice(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
114 tmp = []
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
115 class X(object):
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42955
diff changeset
116 def __setitem__(self, i, k):
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42955
diff changeset
117 tmp.append((i, k))
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
118
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
119 x = X()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
120 x[1:2] = 42
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55593
diff changeset
121 self.assertEqual(tmp, [(slice(1, 2), 42)])
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
122
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
123 def test_pickle(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
124 s = slice(10, 20, 3)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
125 for protocol in (0,1,2):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
126 t = loads(dumps(s, protocol))
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
127 self.assertEqual(s, t)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
128 self.assertEqual(s.indices(15), t.indices(15))
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
129 self.assertNotEqual(id(s), id(t))
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
130
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
131 def test_main():
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 44160
diff changeset
132 support.run_unittest(SliceTest)
30277
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
133
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
134 if __name__ == "__main__":
66ba0e0ec202 SF patch #736962: Port tests to unittest (Part 2)
Raymond Hettinger <python@rcn.com>
parents: 26035
diff changeset
135 test_main()