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

Tim Peters tim_one@users.sourceforge.net
Mon, 11 Mar 2002 19:04:46 -0800


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

Modified Files:
	test_largefile.py 
Log Message:
Change Windows file.truncate() to (a) restore the original file position,
and (b) stop trying to prevent file growth.

Beef up the file.truncate() docs.

Change test_largefile.py to stop assuming that f.truncate() moves the
file pointer to the truncation point, and to verify instead that it leaves
the file position alone.  Remove the test for what happens when a
specified size exceeds the original file size (it's ill-defined, according
to the Single Unix Spec).


Index: test_largefile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_largefile.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** test_largefile.py	11 Mar 2002 00:24:00 -0000	1.13
--- test_largefile.py	12 Mar 2002 03:04:44 -0000	1.14
***************
*** 134,155 ****
      f = open(name, 'r+b')
      f.seek(0, 2)
!     expect(f.tell(), size+1)
      # Cut it back via seek + truncate with no argument.
      newsize = size - 10
      f.seek(newsize)
      f.truncate()
!     expect(f.tell(), newsize)
!     # Ensure that truncate(bigger than true size) doesn't grow the file.
!     f.truncate(size)
!     expect(f.tell(), newsize)
      # Ensure that truncate(smaller than true size) shrinks the file.
      newsize -= 1
!     f.seek(0)
      f.truncate(newsize)
!     expect(f.tell(), newsize)
      # cut it waaaaay back
-     f.truncate(1)
      f.seek(0)
!     expect(len(f.read()), 1)
      f.close()
  
--- 134,161 ----
      f = open(name, 'r+b')
      f.seek(0, 2)
!     expect(f.tell(), size+1)    # else we've lost track of the true size
      # Cut it back via seek + truncate with no argument.
      newsize = size - 10
      f.seek(newsize)
      f.truncate()
!     expect(f.tell(), newsize)   # else pointer moved
!     f.seek(0, 2)
!     expect(f.tell(), newsize)   # else wasn't truncated
      # Ensure that truncate(smaller than true size) shrinks the file.
      newsize -= 1
!     f.seek(42)
      f.truncate(newsize)
!     expect(f.tell(), 42)        # else pointer moved
!     f.seek(0, 2)
!     expect(f.tell(), newsize)   # else wasn't truncated
! 
!     # XXX truncate(larger than true size) is ill-defined across platforms
! 
      # cut it waaaaay back
      f.seek(0)
!     f.truncate(1)
!     expect(f.tell(), 0)         # else pointer moved
!     expect(len(f.read()), 1)    # else wasn't truncated
! 
      f.close()