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

Tim Peters tim_one@users.sourceforge.net
Sun, 10 Mar 2002 16:24:02 -0800


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

Modified Files:
	test_largefile.py 
Log Message:
file_truncate():  provide full "large file" support on Windows, by
dropping MS's inadequate _chsize() function.  This was inspired by
SF patch 498109 ("fileobject truncate support for win32"), which I
rejected.

libstdtypes.tex:  Someone who knows should update the availability
blurb.  For example, if it's available on Linux, it would be good to
say so.

test_largefile:  Uncommented the file.truncate() tests, and reworked to
do more.  The old comment about "permission errors" in the truncation
tests under Windows was almost certainly due to that the file wasn't open
for *write* access at this point, so of course MS wouldn't let you
truncate it.  I'd be appalled if a Unixish system did.

CAUTION:  Someone should run this test on Linux (etc) too.  The
truncation part was commented out before.  Note that test_largefile isn't
run by default.


Index: test_largefile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_largefile.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** test_largefile.py	11 Dec 2001 17:57:26 -0000	1.12
--- test_largefile.py	11 Mar 2002 00:24:00 -0000	1.13
***************
*** 129,147 ****
  f.close()
  
! 
! # XXX add tests for truncate if it exists
! # XXX has truncate ever worked on Windows? specifically on WinNT I get:
! #     "IOError: [Errno 13] Permission denied"
! ##try:
! ##      newsize = size - 10
! ##      f.seek(newsize)
! ##      f.truncate()
! ##      expect(f.tell(), newsize)
! ##      newsize = newsize - 1
! ##      f.seek(0)
! ##      f.truncate(newsize)
! ##      expect(f.tell(), newsize)
! ##except AttributeError:
! ##      pass
  
  os.unlink(name)
--- 129,156 ----
  f.close()
  
! if hasattr(f, 'truncate'):
!     if test_support.verbose:
!         print 'try truncate'
!     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()
  
  os.unlink(name)