diff options
author | Charles-François Natali <neologix@free.fr> | 2011-06-08 17:18:14 (GMT) |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2011-06-08 17:18:14 (GMT) |
commit | 4dd453c6aab315954f19bf0b2f1541c2b37d8e34 (patch) | |
tree | 6123dfbe0ffc22f81ca942e357e128f36216ab29 /Lib/test/test_mmap.py | |
parent | dd696496605883a44da983ad81e55a01e996a004 (diff) | |
download | cpython-4dd453c6aab315954f19bf0b2f1541c2b37d8e34.zip cpython-4dd453c6aab315954f19bf0b2f1541c2b37d8e34.tar.gz cpython-4dd453c6aab315954f19bf0b2f1541c2b37d8e34.tar.bz2 |
Issue #12021: Make mmap's read() method argument optional. Patch by Petri
Lehtinen.
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r-- | Lib/test/test_mmap.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 712378b..4bbb19b 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -417,6 +417,35 @@ class MmapTests(unittest.TestCase): m[x] = b self.assertEqual(m[x], b) + def test_read_all(self): + m = mmap.mmap(-1, 16) + self.addCleanup(m.close) + + # With no parameters, or None or a negative argument, reads all + m.write(bytes(range(16))) + m.seek(0) + self.assertEqual(m.read(), bytes(range(16))) + m.seek(8) + self.assertEqual(m.read(), bytes(range(8, 16))) + m.seek(16) + self.assertEqual(m.read(), b'') + m.seek(3) + self.assertEqual(m.read(None), bytes(range(3, 16))) + m.seek(4) + self.assertEqual(m.read(-1), bytes(range(4, 16))) + m.seek(5) + self.assertEqual(m.read(-2), bytes(range(5, 16))) + m.seek(9) + self.assertEqual(m.read(-42), bytes(range(9, 16))) + + def test_read_invalid_arg(self): + m = mmap.mmap(-1, 16) + self.addCleanup(m.close) + + self.assertRaises(TypeError, m.read, 'foo') + self.assertRaises(TypeError, m.read, 5.5) + self.assertRaises(TypeError, m.read, [1, 2, 3]) + def test_extended_getslice(self): # Test extended slicing by comparing with list slicing. s = bytes(reversed(range(256))) |