blob: ac89e05598e16f25724bc502e5965fbb144b7565 [file] [log] [blame]
Thomas Wouters3ccec682007-08-28 15:28:19 +00001"""Unit tests for buffer objects.
2
3For now, tests just new or changed functionality.
4
5"""
6
7import unittest
8from test import test_support
Senthil Kumaran3ddc4352010-01-08 18:41:40 +00009import warnings
Thomas Wouters3ccec682007-08-28 15:28:19 +000010
11class 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
26def test_main():
Senthil Kumaran3ddc4352010-01-08 18:41:40 +000027 with warnings.catch_warnings():
28 # Silence Py3k warning
29 warnings.filterwarnings("ignore", "buffer.. not supported",
30 DeprecationWarning)
31 test_support.run_unittest(BufferTests)
Thomas Wouters3ccec682007-08-28 15:28:19 +000032
33if __name__ == "__main__":
34 test_main()