[Python-checkins] CVS: python/dist/src/Lib/test test_largefile.py,NONE,1.1 regrtest.py,1.21,1.22

Trent Mick python-dev@python.org
Fri, 11 Aug 2000 12:03:01 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv29798/Lib/test

Modified Files:
	regrtest.py 
Added Files:
	test_largefile.py 
Log Message:
Add largefile support for Linux64 and WIn64. Add test_largefile and some minor
change to regrtest.py to allow optional running of test_largefile ('cause it's
slow on Win64).

This closes patches:
http://sourceforge.net/patch/index.php?func=detailpatch&patch_id=100510&group_id=5470
and
http://sourceforge.net/patch/index.php?func=detailpatch&patch_id=100511&group_id=5470




--- NEW FILE ---
#!python

#----------------------------------------------------------------------
# test largefile support on system where this makes sense
#
#XXX how to only run this when support is there
#XXX how to only optionally run this, it will take along time
#----------------------------------------------------------------------

import test_support
import os, struct, stat, sys


# only run if the current system support large files
f = open(test_support.TESTFN, 'w')
try:
	# 2**31 == 2147483648
	f.seek(2147483649L)
except OverflowError:
	raise test_support.TestSkipped, "platform does not have largefile support"
else:
	f.close()


# create >2GB file (2GB = 2147483648 bytes)
size = 2500000000L
name = test_support.TESTFN


# on Windows this test comsumes large resources:
#  it takes a long time to build the >2GB file and takes >2GB of disk space
# therefore test_support.use_large_resources must be defined to run this test
if sys.platform[:3] == 'win' and not test_support.use_large_resources:
	raise test_support.TestSkipped, \
		"test requires %s bytes and a long time to run" % str(size)



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:
			print 'yes'


# test that each file function works as expected for a large (i.e. >2GB, do
# we have to check >4GB) files

if test_support.verbose:
	print 'create large file via seek (may be sparse file) ...'
f = open(name, 'w')
f.seek(size)
f.write('a')
f.flush()
expect(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
if test_support.verbose:
	print 'check file size with os.fstat'
f.close()
if test_support.verbose:
	print 'check file size with os.stat'
expect(os.stat(name)[stat.ST_SIZE], size+1)

if test_support.verbose:
	print 'play around with seek() and read() with the built largefile'
f = open(name, 'r')
expect(f.tell(), 0)
expect(f.read(1), '\000')
expect(f.tell(), 1)
f.seek(0)
expect(f.tell(), 0)
f.seek(0, 0)
expect(f.tell(), 0)
f.seek(42)
expect(f.tell(), 42)
f.seek(42, 0)
expect(f.tell(), 42)
f.seek(42, 1)
expect(f.tell(), 84)
f.seek(0, 1)
expect(f.tell(), 84)
f.seek(0, 2) # seek from the end
expect(f.tell(), size + 1 + 0)
f.seek(-10, 2)
expect(f.tell(), size + 1 - 10)
f.seek(-size-1, 2)
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.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)
expect(os.lseek(f.fileno(), 42, 1), 84)
expect(os.lseek(f.fileno(), 0, 1), 84)
expect(os.lseek(f.fileno(), 0, 2), size+1+0)
expect(os.lseek(f.fileno(), -10, 2), size+1-10)
expect(os.lseek(f.fileno(), -size-1, 2), 0)
expect(os.lseek(f.fileno(), size, 0), size)
expect(f.read(1), 'a') # the 'a' that was written at the end of the file above
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)


Index: regrtest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/regrtest.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** regrtest.py	2000/08/04 13:17:51	1.21
--- regrtest.py	2000/08/11 19:02:58	1.22
***************
*** 16,19 ****
--- 16,20 ----
  -r: random    -- randomize test execution order
  -l: leakdebug -- if cycle garbage collection is enabled, run with DEBUG_LEAK
+ --have-resources   -- run tests that require large resources (time/space)
  
  If non-option arguments are present, they are names for tests to run,
***************
*** 41,45 ****
  
  def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
!          exclude=0, single=0, randomize=0, leakdebug=0):
      """Execute a test suite.
  
--- 42,47 ----
  
  def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
!          exclude=0, single=0, randomize=0, leakdebug=0,
!          use_large_resources=0):
      """Execute a test suite.
  
***************
*** 66,70 ****
      
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl')
      except getopt.error, msg:
          print msg
--- 68,72 ----
      
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl', ['have-resources'])
      except getopt.error, msg:
          print msg
***************
*** 79,82 ****
--- 81,85 ----
          if o == '-r': randomize = 1
          if o == '-l': leakdebug = 1
+         if o == '--have-resources': use_large_resources = 1
      if generate and verbose:
          print "-g and -v don't go together!"
***************
*** 122,130 ****
          random.shuffle(tests)
      test_support.verbose = verbose      # Tell tests to be moderately quiet
      save_modules = sys.modules.keys()
      for test in tests:
          if not quiet:
              print test
!         ok = runtest(test, generate, verbose, testdir)
          if ok > 0:
              good.append(test)
--- 125,134 ----
          random.shuffle(tests)
      test_support.verbose = verbose      # Tell tests to be moderately quiet
+     test_support.use_large_resources = use_large_resources
      save_modules = sys.modules.keys()
      for test in tests:
          if not quiet:
              print test
!         ok = runtest(test, generate, verbose, quiet, testdir)
          if ok > 0:
              good.append(test)
***************
*** 132,138 ****
              bad.append(test)
          else:
-             if not quiet:
-                 print "test", test,
-                 print "skipped -- an optional feature could not be imported"
              skipped.append(test)
          # Unload the newly imported modules (best effort finalization)
--- 136,139 ----
***************
*** 195,199 ****
      return stdtests + tests
  
! def runtest(test, generate, verbose, testdir = None):
      """Run a single test.
      test -- the name of the test
--- 196,200 ----
      return stdtests + tests
  
! def runtest(test, generate, verbose, quiet, testdir = None):
      """Run a single test.
      test -- the name of the test
***************
*** 201,204 ****
--- 202,206 ----
      and comparing it to a previously created output file
      verbose -- if true, print more messages
+     quiet -- if true, don't print 'skipped' messages (probably redundant)
      testdir -- test directory
      """
***************
*** 229,232 ****
--- 231,237 ----
              sys.stdout = save_stdout
      except (ImportError, test_support.TestSkipped), msg:
+         if not quiet:
+             print "test", test,
+             print "skipped -- ", msg
          return -1
      except KeyboardInterrupt, v: