Back to index

python3.2  3.2.2
Public Member Functions
test.test_slice.SliceTest Class Reference

List of all members.

Public Member Functions

def test_constructor
def test_repr
def test_hash
def test_cmp
def test_members
def test_indices
def test_setslice_without_getslice
def test_pickle

Detailed Description

Definition at line 9 of file test_slice.py.


Member Function Documentation

Definition at line 23 of file test_slice.py.

00023 
00024     def test_cmp(self):
00025         s1 = slice(1, 2, 3)
00026         s2 = slice(1, 2, 3)
00027         s3 = slice(1, 2, 4)
00028         self.assertEqual(s1, s2)
00029         self.assertNotEqual(s1, s3)
00030         self.assertNotEqual(s1, None)
00031         self.assertNotEqual(s1, (1, 2, 3))
00032         self.assertNotEqual(s1, "")
00033 
00034         class Exc(Exception):
00035             pass
00036 
00037         class BadCmp(object):
00038             def __eq__(self, other):
00039                 raise Exc
00040 
00041         s1 = slice(BadCmp())
00042         s2 = slice(BadCmp())
00043         self.assertEqual(s1, s1)
00044         self.assertRaises(Exc, lambda: s1 == s2)
00045 
00046         s1 = slice(1, BadCmp())
00047         s2 = slice(1, BadCmp())
00048         self.assertEqual(s1, s1)
00049         self.assertRaises(Exc, lambda: s1 == s2)
00050 
00051         s1 = slice(1, 2, BadCmp())
00052         s2 = slice(1, 2, BadCmp())
00053         self.assertEqual(s1, s1)
00054         self.assertRaises(Exc, lambda: s1 == s2)

Here is the call graph for this function:

Definition at line 11 of file test_slice.py.

00011 
00012     def test_constructor(self):
00013         self.assertRaises(TypeError, slice)
00014         self.assertRaises(TypeError, slice, 1, 2, 3, 4)

Here is the call graph for this function:

Definition at line 18 of file test_slice.py.

00018 
00019     def test_hash(self):
00020         # Verify clearing of SF bug #800796
00021         self.assertRaises(TypeError, hash, slice(5))
00022         self.assertRaises(TypeError, slice(5).__hash__)

Here is the call graph for this function:

Definition at line 78 of file test_slice.py.

00078 
00079     def test_indices(self):
00080         self.assertEqual(slice(None           ).indices(10), (0, 10,  1))
00081         self.assertEqual(slice(None,  None,  2).indices(10), (0, 10,  2))
00082         self.assertEqual(slice(1,     None,  2).indices(10), (1, 10,  2))
00083         self.assertEqual(slice(None,  None, -1).indices(10), (9, -1, -1))
00084         self.assertEqual(slice(None,  None, -2).indices(10), (9, -1, -2))
00085         self.assertEqual(slice(3,     None, -2).indices(10), (3, -1, -2))
00086         # issue 3004 tests
00087         self.assertEqual(slice(None, -9).indices(10), (0, 1, 1))
00088         self.assertEqual(slice(None, -10).indices(10), (0, 0, 1))
00089         self.assertEqual(slice(None, -11).indices(10), (0, 0, 1))
00090         self.assertEqual(slice(None, -10, -1).indices(10), (9, 0, -1))
00091         self.assertEqual(slice(None, -11, -1).indices(10), (9, -1, -1))
00092         self.assertEqual(slice(None, -12, -1).indices(10), (9, -1, -1))
00093         self.assertEqual(slice(None, 9).indices(10), (0, 9, 1))
00094         self.assertEqual(slice(None, 10).indices(10), (0, 10, 1))
00095         self.assertEqual(slice(None, 11).indices(10), (0, 10, 1))
00096         self.assertEqual(slice(None, 8, -1).indices(10), (9, 8, -1))
00097         self.assertEqual(slice(None, 9, -1).indices(10), (9, 9, -1))
00098         self.assertEqual(slice(None, 10, -1).indices(10), (9, 9, -1))
00099 
00100         self.assertEqual(
00101             slice(-100,  100     ).indices(10),
00102             slice(None).indices(10)
00103         )
00104         self.assertEqual(
00105             slice(100,  -100,  -1).indices(10),
00106             slice(None, None, -1).indices(10)
00107         )
00108         self.assertEqual(slice(-100, 100, 2).indices(10), (0, 10,  2))
00109 
00110         self.assertEqual(list(range(10))[::sys.maxsize - 1], [0])
00111 
00112         self.assertRaises(OverflowError, slice(None).indices, 1<<100)

Here is the call graph for this function:

Definition at line 55 of file test_slice.py.

00055 
00056     def test_members(self):
00057         s = slice(1)
00058         self.assertEqual(s.start, None)
00059         self.assertEqual(s.stop, 1)
00060         self.assertEqual(s.step, None)
00061 
00062         s = slice(1, 2)
00063         self.assertEqual(s.start, 1)
00064         self.assertEqual(s.stop, 2)
00065         self.assertEqual(s.step, None)
00066 
00067         s = slice(1, 2, 3)
00068         self.assertEqual(s.start, 1)
00069         self.assertEqual(s.stop, 2)
00070         self.assertEqual(s.step, 3)
00071 
00072         class AnyClass:
00073             pass
00074 
00075         obj = AnyClass()
00076         s = slice(obj)
00077         self.assertTrue(s.stop is obj)

Here is the call graph for this function:

Definition at line 123 of file test_slice.py.

00123 
00124     def test_pickle(self):
00125         s = slice(10, 20, 3)
00126         for protocol in (0,1,2):
00127             t = loads(dumps(s, protocol))
00128             self.assertEqual(s, t)
00129             self.assertEqual(s.indices(15), t.indices(15))
00130             self.assertNotEqual(id(s), id(t))

Here is the call graph for this function:

Definition at line 15 of file test_slice.py.

00015 
00016     def test_repr(self):
00017         self.assertEqual(repr(slice(1, 2, 3)), "slice(1, 2, 3)")

Here is the call graph for this function:

Definition at line 113 of file test_slice.py.

00113 
00114     def test_setslice_without_getslice(self):
00115         tmp = []
00116         class X(object):
00117             def __setitem__(self, i, k):
00118                 tmp.append((i, k))
00119 
00120         x = X()
00121         x[1:2] = 42
00122         self.assertEqual(tmp, [(slice(1, 2), 42)])

Here is the call graph for this function:


The documentation for this class was generated from the following file: