From b8c0230a27443b65c23c666ad87ed905ec606663 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Thu, 6 Sep 2001 01:17:45 +0000 Subject: [PATCH] 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. --- Lib/test/test_largefile.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index 3f3b8f16fc0..b2bec1fa9f7 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)