diff options
| author | Thomas Wouters <thomas@python.org> | 2006-12-19 08:30:14 +0000 | 
|---|---|---|
| committer | Thomas Wouters <thomas@python.org> | 2006-12-19 08:30:14 +0000 | 
| commit | 376446dd4e30006c4d4ad09b4cbda8b07e9ce23a (patch) | |
| tree | da322d17594d2894ca4f56d0ad4c917c46ca3f31 /Lib/test | |
| parent | 5672904eff085ddda588e9c281bc554466bd1110 (diff) | |
| download | cpython-git-376446dd4e30006c4d4ad09b4cbda8b07e9ce23a.tar.gz | |
Implement extended slicing in bytes objects.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_bytes.py | 31 | 
1 files changed, 31 insertions, 0 deletions
| diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 210f08ca73..be959353fd 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -163,6 +163,17 @@ class BytesTest(unittest.TestCase):          self.assertEqual(b[-5:100], by("world"))          self.assertEqual(b[-100:5], by("Hello")) +    def test_extended_getslice(self): +        # Test extended slicing by comparing with list slicing. +        L = list(range(255)) +        b = bytes(L) +        indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100) +        for start in indices: +            for stop in indices: +                # Skip step 0 (invalid) +                for step in indices[1:]: +                    self.assertEqual(b[start:stop:step], bytes(L[start:stop:step])) +              def test_regexps(self):          def by(s):              return bytes(map(ord, s)) @@ -239,6 +250,26 @@ class BytesTest(unittest.TestCase):          b[3:0] = [42, 42, 42]          self.assertEqual(b, bytes([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9])) +    def test_extended_set_del_slice(self): +        indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300) +        for start in indices: +            for stop in indices: +                # Skip invalid step 0 +                for step in indices[1:]: +                    L = list(range(255)) +                    b = bytes(L) +                    # Make sure we have a slice of exactly the right length, +                    # but with different data. +                    data = L[start:stop:step] +                    data.reverse() +                    L[start:stop:step] = data +                    b[start:stop:step] = data +                    self.assertEquals(b, bytes(L)) +                     +                    del L[start:stop:step] +                    del b[start:stop:step] +                    self.assertEquals(b, bytes(L)) +      def test_setslice_trap(self):          # This test verifies that we correctly handle assigning self          # to a slice of self (the old Lambert Meertens trap). | 
