Kaydet (Commit) b8c0230a authored tarafından Tim Peters's avatar Tim Peters

Dubious assumptions:

1. That seeking beyond the end of a file increases the size of a file.
2. That files so extended are magically filled with null bytes.

I find no support for either in the C std, and #2 in particular turns out
not to be true on Win32 (you apparently see whatever trash happened to be
on disk).  Left #1 intact, but changed the test to check only bytes it
explicitly wrote.  Also fiddled the "expected" vs "got" failure reports
to consistently use repr (%r) -- they weren't readable otherwise.
üst 6e13a562
......@@ -42,12 +42,12 @@ if sys.platform[:3] == 'win':
def expect(got_this, expect_this):
if test_support.verbose:
print '%s =?= %s ...' % (`got_this`, `expect_this`),
print '%r =?= %r ...' % (got_this, expect_this),
if got_this != expect_this:
if test_support.verbose:
print 'no'
raise test_support.TestFailed, 'got %s, but expected %s' %\
(str(got_this), str(expect_this))
raise test_support.TestFailed, 'got %r, but expected %r' %\
(got_this, expect_this)
else:
if test_support.verbose:
print 'yes'
......@@ -59,6 +59,8 @@ def expect(got_this, expect_this):
if test_support.verbose:
print 'create large file via seek (may be sparse file) ...'
f = open(name, 'wb')
f.write('z')
f.seek(0)
f.seek(size)
f.write('a')
f.flush()
......@@ -74,7 +76,7 @@ if test_support.verbose:
print 'play around with seek() and read() with the built largefile'
f = open(name, 'rb')
expect(f.tell(), 0)
expect(f.read(1), '\000')
expect(f.read(1), 'z')
expect(f.tell(), 1)
f.seek(0)
expect(f.tell(), 0)
......@@ -97,11 +99,14 @@ expect(f.tell(), 0)
f.seek(size)
expect(f.tell(), size)
expect(f.read(1), 'a') # the 'a' that was written at the end of the file above
f.seek(-size-1, 1)
expect(f.read(1), 'z')
expect(f.tell(), 1)
f.close()
if test_support.verbose:
print 'play around with os.lseek() with the built largefile'
f = open(name, 'r')
f = open(name, 'rb')
expect(os.lseek(f.fileno(), 0, 0), 0)
expect(os.lseek(f.fileno(), 42, 0), 42)
expect(os.lseek(f.fileno(), 42, 1), 84)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment