diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2008-01-19 18:18:41 +0000 |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2008-01-19 18:18:41 +0000 |
commit | 5c60bfcfbf2dd50cc40210771fdc8d2cfc20cdad (patch) | |
tree | 906959917e2562717aa503edee65d6462a6d5682 /Lib/test/test_mmap.py | |
parent | 4be0bc642e89939d9d9bf2559d92eafe9f0a0933 (diff) | |
download | cpython-git-5c60bfcfbf2dd50cc40210771fdc8d2cfc20cdad.tar.gz |
Patch #976880: add mmap .rfind() method, and 'end' paramter to .find().
Contributed by John Lenton.
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r-- | Lib/test/test_mmap.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index b4f85fceef..8cc8dedb73 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -255,6 +255,42 @@ class MmapTests(unittest.TestCase): self.assertEqual(m.find(slice + 'x'), -1) m.close() + def test_find_end(self): + # test the new 'end' parameter works as expected + f = open(TESTFN, 'w+') + data = '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) + + + def test_rfind(self): + # test the new 'end' parameter works as expected + f = open(TESTFN, 'w+') + data = '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) + + def test_double_close(self): # make sure a double close doesn't crash on Solaris (Bug# 665913) f = open(TESTFN, 'w+') |