diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-06 01:17:45 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-06 01:17:45 (GMT) |
commit | b8c0230a27443b65c23c666ad87ed905ec606663 (patch) | |
tree | ca368c6b16dfa4c54fc79b9e03752182ba1b1275 /Lib/test | |
parent | 6e13a562ae01a962612ca76f9afcc7211240236e (diff) | |
download | cpython-b8c0230a27443b65c23c666ad87ed905ec606663.zip cpython-b8c0230a27443b65c23c666ad87ed905ec606663.tar.gz cpython-b8c0230a27443b65c23c666ad87ed905ec606663.tar.bz2 |
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.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_largefile.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index 3f3b8f1..b2bec1f 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -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) |