mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Additional tests for seek() method, written by Trent Mick
This commit is contained in:
parent
70d2742fce
commit
cf70ea633f
2 changed files with 36 additions and 1 deletions
Binary file not shown.
|
@ -58,7 +58,42 @@ def test_both():
|
|||
|
||||
assert start == PAGESIZE
|
||||
assert end == PAGESIZE + 6
|
||||
|
||||
|
||||
# test seeking around (try to overflow the seek implementation)
|
||||
m.seek(0,0)
|
||||
print ' Seek to zeroth byte'
|
||||
assert m.tell() == 0
|
||||
m.seek(42,1)
|
||||
print ' Seek to 42nd byte'
|
||||
assert m.tell() == 42
|
||||
m.seek(0,2)
|
||||
print ' Seek to last byte'
|
||||
assert m.tell() == len(m)
|
||||
|
||||
print ' Try to seek to negative position...'
|
||||
try:
|
||||
m.seek(-1)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
assert 0, 'expected a ValueError but did not get it'
|
||||
|
||||
print ' Try to seek beyond end of mmap...'
|
||||
try:
|
||||
m.seek(1,2)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
assert 0, 'expected a ValueError but did not get it'
|
||||
|
||||
print ' Try to seek to negative position...'
|
||||
try:
|
||||
m.seek(-len(m)-1,2)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
assert 0, 'expected a ValueError but did not get it'
|
||||
|
||||
m.close()
|
||||
os.unlink("foo")
|
||||
print ' Test passed'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue