[Python-checkins] CVS: python/dist/src/Lib/test test_mmap.py,1.19,1.20
Tim Peters
tim_one@users.sourceforge.net
Thu, 07 Mar 2002 21:43:34 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv13773/python/Lib/test
Modified Files:
test_mmap.py
Log Message:
SF bug 515943: searching for data with \0 in mmap.
mmap_find_method(): this obtained the string to find via s#, but it
ignored its length, acting as if it were \0-terminated instead.
Someone please run on Linux too (the extended test_mmap works on Windows).
Bugfix candidate.
Index: test_mmap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_mmap.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** test_mmap.py 13 Nov 2001 23:39:47 -0000 1.19
--- test_mmap.py 8 Mar 2002 05:43:32 -0000 1.20
***************
*** 245,248 ****
--- 245,273 ----
pass
+ # Do a tougher .find() test. SF bug 515943 pointed out that, in 2.2,
+ # searching for data with embedded \0 bytes didn't work.
+ f = open(TESTFN, 'w+')
+
+ try: # unlink TESTFN no matter what
+ data = 'aabaac\x00deef\x00\x00aa\x00'
+ n = len(data)
+ f.write(data)
+ m = mmap.mmap(f.fileno(), n)
+ f.close()
+
+ for start in range(n+1):
+ for finish in range(start, n+1):
+ slice = data[start : finish]
+ vereq(m.find(slice), data.find(slice))
+ vereq(m.find(slice + 'x'), -1)
+
+ finally:
+ try:
+ os.unlink(TESTFN)
+ except OSError:
+ pass
+
+
+
print ' Test passed'