[Python-checkins] python/dist/src/Lib/test test_resource.py,1.2,1.3

jlt63@users.sourceforge.net jlt63@users.sourceforge.net
Thu, 12 Dec 2002 10:13:39 -0800


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

Modified Files:
	test_resource.py 
Log Message:
Patch #551960: Add check for setrlimit() support

test_resource calls resource.setrlimit() to change the file size limits.
This fails on Cygwin, which supports setrlimit() and getrlimit(), just not
changing that particular setting. (The same would apply to any other
platform that has those functions but not that particular feature.)

Since getrlimit() works and setrlimit() can be used for other reasons, a
check for ValueError was added to that part of the test. 


Index: test_resource.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_resource.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_resource.py	23 Jul 2002 19:04:00 -0000	1.2
--- test_resource.py	12 Dec 2002 18:13:36 -0000	1.3
***************
*** 23,28 ****
  # write() should return EFBIG when the limit is exceeded.
  
  try:
!     resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
      f = open(TESTFN, "wb")
      f.write("X" * 1024)
--- 23,35 ----
  # write() should return EFBIG when the limit is exceeded.
  
+ # At least one platform has an unlimited RLIMIT_FSIZE and attempts to
+ # change it raise ValueError instead.
+ 
  try:
!     try:
!         resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
!         limit_set = 1
!     except ValueError:
!         limit_set = 0
      f = open(TESTFN, "wb")
      f.write("X" * 1024)
***************
*** 31,35 ****
          f.flush()
      except IOError:
!         pass
      f.close()
      os.unlink(TESTFN)
--- 38,43 ----
          f.flush()
      except IOError:
!         if not limit_set:
!             raise
      f.close()
      os.unlink(TESTFN)
***************
*** 41,48 ****
  try:
      resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
! except OverflowError:
      pass
  try:
      resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big))
! except OverflowError:
      pass
--- 49,56 ----
  try:
      resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
! except (OverflowError, ValueError):
      pass
  try:
      resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big))
! except (OverflowError, ValueError):
      pass