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 |
Senthil Kumaran | 3ddc435 | 2010-01-08 18:41:40 +0000 | [diff] [blame^] | 9 | import warnings |
Thomas Wouters | 3ccec68 | 2007-08-28 15:28:19 +0000 | [diff] [blame] | 10 | |
| 11 | class BufferTests(unittest.TestCase): |
| 12 | |
| 13 | def test_extended_getslice(self): |
| 14 | # Test extended slicing by comparing with list slicing. |
| 15 | s = "".join(chr(c) for c in list(range(255, -1, -1))) |
| 16 | b = buffer(s) |
| 17 | indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300) |
| 18 | for start in indices: |
| 19 | for stop in indices: |
| 20 | # Skip step 0 (invalid) |
| 21 | for step in indices[1:]: |
| 22 | self.assertEqual(b[start:stop:step], |
| 23 | s[start:stop:step]) |
| 24 | |
| 25 | |
| 26 | def test_main(): |
Senthil Kumaran | 3ddc435 | 2010-01-08 18:41:40 +0000 | [diff] [blame^] | 27 | with warnings.catch_warnings(): |
| 28 | # Silence Py3k warning |
| 29 | warnings.filterwarnings("ignore", "buffer.. not supported", |
| 30 | DeprecationWarning) |
| 31 | test_support.run_unittest(BufferTests) |
Thomas Wouters | 3ccec68 | 2007-08-28 15:28:19 +0000 | [diff] [blame] | 32 | |
| 33 | if __name__ == "__main__": |
| 34 | test_main() |