Thomas Wouters | 3ccec68 | 2007-08-28 15:28:19 +0000 | [diff] [blame] | 1 | """Unit tests for buffer objects. |
| 2 | |
| 3 | For now, tests just new or changed functionality. |
| 4 | |
| 5 | """ |
| 6 | |
| 7 | import unittest |
| 8 | from test import test_support |
| 9 | |
| 10 | class BufferTests(unittest.TestCase): |
| 11 | |
| 12 | def test_extended_getslice(self): |
| 13 | # Test extended slicing by comparing with list slicing. |
| 14 | s = "".join(chr(c) for c in list(range(255, -1, -1))) |
| 15 | b = buffer(s) |
| 16 | indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300) |
| 17 | for start in indices: |
| 18 | for stop in indices: |
| 19 | # Skip step 0 (invalid) |
| 20 | for step in indices[1:]: |
| 21 | self.assertEqual(b[start:stop:step], |
| 22 | s[start:stop:step]) |
| 23 | |
| 24 | |
| 25 | def test_main(): |
Florent Xicluna | 0762788 | 2010-03-21 01:14:24 +0000 | [diff] [blame] | 26 | with test_support.check_py3k_warnings(("buffer.. not supported", |
| 27 | DeprecationWarning)): |
| 28 | test_support.run_unittest(BufferTests) |
Thomas Wouters | 3ccec68 | 2007-08-28 15:28:19 +0000 | [diff] [blame] | 29 | |
| 30 | if __name__ == "__main__": |
| 31 | test_main() |