[Python-checkins] CVS: python/dist/src/Lib/test test_largefile.py,1.7,1.8

Tim Peters tim_one@users.sourceforge.net
Wed, 05 Sep 2001 18:17:47 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv27576/python/Lib/test

Modified Files:
	test_largefile.py 
Log Message:
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.


Index: test_largefile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_largefile.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_largefile.py	2001/09/06 00:32:15	1.7
--- test_largefile.py	2001/09/06 01:17:45	1.8
***************
*** 43,52 ****
  def expect(got_this, expect_this):
      if test_support.verbose:
!         print '%s =?= %s ...' % (`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))
      else:
          if test_support.verbose:
--- 43,52 ----
  def expect(got_this, expect_this):
      if test_support.verbose:
!         print '%r =?= %r ...' % (got_this, expect_this),
      if got_this != expect_this:
          if test_support.verbose:
              print 'no'
!         raise test_support.TestFailed, 'got %r, but expected %r' %\
!               (got_this, expect_this)
      else:
          if test_support.verbose:
***************
*** 60,63 ****
--- 60,65 ----
      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')
***************
*** 75,79 ****
  f = open(name, 'rb')
  expect(f.tell(), 0)
! expect(f.read(1), '\000')
  expect(f.tell(), 1)
  f.seek(0)
--- 77,81 ----
  f = open(name, 'rb')
  expect(f.tell(), 0)
! expect(f.read(1), 'z')
  expect(f.tell(), 1)
  f.seek(0)
***************
*** 98,106 ****
  expect(f.tell(), size)
  expect(f.read(1), 'a') # the 'a' that was written at the end of the file above
  f.close()
  
  if test_support.verbose:
      print 'play around with os.lseek() with the built largefile'
! f = open(name, 'r')
  expect(os.lseek(f.fileno(), 0, 0), 0)
  expect(os.lseek(f.fileno(), 42, 0), 42)
--- 100,111 ----
  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, 'rb')
  expect(os.lseek(f.fileno(), 0, 0), 0)
  expect(os.lseek(f.fileno(), 42, 0), 42)