gh-111835: Add seekable method to mmap.mmap (gh-111852)

This commit is contained in:
Donghee Na 2023-11-09 11:13:35 +00:00 committed by GitHub
parent 30ec968bef
commit 6046aec377
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 12 deletions

View file

@ -93,11 +93,12 @@ class MmapTests(unittest.TestCase):
self.assertEqual(end, PAGESIZE + 6)
# test seeking around (try to overflow the seek implementation)
m.seek(0,0)
self.assertTrue(m.seekable())
self.assertEqual(m.seek(0, 0), 0)
self.assertEqual(m.tell(), 0)
m.seek(42,1)
self.assertEqual(m.seek(42, 1), 42)
self.assertEqual(m.tell(), 42)
m.seek(0,2)
self.assertEqual(m.seek(0, 2), len(m))
self.assertEqual(m.tell(), len(m))
# Try to seek to negative position...
@ -162,7 +163,7 @@ class MmapTests(unittest.TestCase):
# Ensuring that readonly mmap can't be write() to
try:
m.seek(0,0)
m.seek(0, 0)
m.write(b'abc')
except TypeError:
pass
@ -171,7 +172,7 @@ class MmapTests(unittest.TestCase):
# Ensuring that readonly mmap can't be write_byte() to
try:
m.seek(0,0)
m.seek(0, 0)
m.write_byte(b'd')
except TypeError:
pass