summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mmap.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-04-04 17:09:35 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-04-04 17:09:35 (GMT)
commite099b37428ab72cf70c745e941b9767fcad8eaa3 (patch)
tree11ba876743d835964f1b6a9cb52286d39326e54d /Lib/test/test_mmap.py
parentf3abcc9d3c5c2a0bb739df2f3649ffa8b958a084 (diff)
downloadcpython-e099b37428ab72cf70c745e941b9767fcad8eaa3.zip
cpython-e099b37428ab72cf70c745e941b9767fcad8eaa3.tar.gz
cpython-e099b37428ab72cf70c745e941b9767fcad8eaa3.tar.bz2
#5391 make mmap work exclusively with bytes
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r--Lib/test/test_mmap.py46
1 files changed, 20 insertions, 26 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 99cc63f..f3e28cc 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -37,7 +37,7 @@ class MmapTests(unittest.TestCase):
# Simple sanity checks
tp = str(type(m)) # SF bug 128713: segfaulted on Linux
- self.assertEqual(m.find('foo'), PAGESIZE)
+ self.assertEqual(m.find(b'foo'), PAGESIZE)
self.assertEqual(len(m), 2*PAGESIZE)
@@ -262,38 +262,38 @@ class MmapTests(unittest.TestCase):
def test_find_end(self):
# test the new 'end' parameter works as expected
- f = open(TESTFN, 'w+')
- data = 'one two ones'
+ f = open(TESTFN, 'wb+')
+ data = b'one two ones'
n = len(data)
f.write(data)
f.flush()
m = mmap.mmap(f.fileno(), n)
f.close()
- self.assertEqual(m.find('one'), 0)
- self.assertEqual(m.find('ones'), 8)
- self.assertEqual(m.find('one', 0, -1), 0)
- self.assertEqual(m.find('one', 1), 8)
- self.assertEqual(m.find('one', 1, -1), 8)
- self.assertEqual(m.find('one', 1, -2), -1)
+ self.assertEqual(m.find(b'one'), 0)
+ self.assertEqual(m.find(b'ones'), 8)
+ self.assertEqual(m.find(b'one', 0, -1), 0)
+ self.assertEqual(m.find(b'one', 1), 8)
+ self.assertEqual(m.find(b'one', 1, -1), 8)
+ self.assertEqual(m.find(b'one', 1, -2), -1)
def test_rfind(self):
# test the new 'end' parameter works as expected
- f = open(TESTFN, 'w+')
- data = 'one two ones'
+ f = open(TESTFN, 'wb+')
+ data = b'one two ones'
n = len(data)
f.write(data)
f.flush()
m = mmap.mmap(f.fileno(), n)
f.close()
- self.assertEqual(m.rfind('one'), 8)
- self.assertEqual(m.rfind('one '), 0)
- self.assertEqual(m.rfind('one', 0, -1), 8)
- self.assertEqual(m.rfind('one', 0, -2), 0)
- self.assertEqual(m.rfind('one', 1, -1), 8)
- self.assertEqual(m.rfind('one', 1, -2), -1)
+ self.assertEqual(m.rfind(b'one'), 8)
+ self.assertEqual(m.rfind(b'one '), 0)
+ self.assertEqual(m.rfind(b'one', 0, -1), 8)
+ self.assertEqual(m.rfind(b'one', 0, -2), 0)
+ self.assertEqual(m.rfind(b'one', 1, -1), 8)
+ self.assertEqual(m.rfind(b'one', 1, -2), -1)
def test_double_close(self):
@@ -506,21 +506,15 @@ class MmapTests(unittest.TestCase):
# Test write_byte()
for i in range(len(data)):
self.assertEquals(m.tell(), i)
- m.write_byte(data[i:i+1])
+ m.write_byte(data[i])
self.assertEquals(m.tell(), i+1)
- self.assertRaises(ValueError, m.write_byte, b"x")
+ self.assertRaises(ValueError, m.write_byte, b"x"[0])
self.assertEquals(m[:], data)
# Test read_byte()
m.seek(0)
for i in range(len(data)):
self.assertEquals(m.tell(), i)
- # XXX: Disable this test for now because it's not clear
- # which type of object m.read_byte returns. Currently, it
- # returns 1-length str (unicode).
- if 0:
- self.assertEquals(m.read_byte(), data[i:i+1])
- else:
- m.read_byte()
+ self.assertEquals(m.read_byte(), data[i])
self.assertEquals(m.tell(), i+1)
self.assertRaises(ValueError, m.read_byte)
# Test read()