Back to index

python3.2  3.2.2
Public Member Functions
test.test_resource.ResourceTest Class Reference

List of all members.

Public Member Functions

def test_args
def test_fsize_ismax
def test_fsize_enforced
def test_fsize_toobig
def test_getrusage

Detailed Description

Definition at line 9 of file test_resource.py.


Member Function Documentation

Definition at line 11 of file test_resource.py.

00011 
00012     def test_args(self):
00013         self.assertRaises(TypeError, resource.getrlimit)
00014         self.assertRaises(TypeError, resource.getrlimit, 42, 42)
00015         self.assertRaises(TypeError, resource.setrlimit)
00016         self.assertRaises(TypeError, resource.setrlimit, 42, 42, 42)

Here is the call graph for this function:

Definition at line 31 of file test_resource.py.

00031 
00032     def test_fsize_enforced(self):
00033         try:
00034             (cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
00035         except AttributeError:
00036             pass
00037         else:
00038             # Check to see what happens when the RLIMIT_FSIZE is small.  Some
00039             # versions of Python were terminated by an uncaught SIGXFSZ, but
00040             # pythonrun.c has been fixed to ignore that exception.  If so, the
00041             # write() should return EFBIG when the limit is exceeded.
00042 
00043             # At least one platform has an unlimited RLIMIT_FSIZE and attempts
00044             # to change it raise ValueError instead.
00045             try:
00046                 try:
00047                     resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
00048                     limit_set = True
00049                 except ValueError:
00050                     limit_set = False
00051                 f = open(support.TESTFN, "wb")
00052                 try:
00053                     f.write(b"X" * 1024)
00054                     try:
00055                         f.write(b"Y")
00056                         f.flush()
00057                         # On some systems (e.g., Ubuntu on hppa) the flush()
00058                         # doesn't always cause the exception, but the close()
00059                         # does eventually.  Try flushing several times in
00060                         # an attempt to ensure the file is really synced and
00061                         # the exception raised.
00062                         for i in range(5):
00063                             time.sleep(.1)
00064                             f.flush()
00065                     except IOError:
00066                         if not limit_set:
00067                             raise
00068                     if limit_set:
00069                         # Close will attempt to flush the byte we wrote
00070                         # Restore limit first to avoid getting a spurious error
00071                         resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
00072                 finally:
00073                     f.close()
00074             finally:
00075                 if limit_set:
00076                     resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
00077                 support.unlink(support.TESTFN)

Definition at line 17 of file test_resource.py.

00017 
00018     def test_fsize_ismax(self):
00019         try:
00020             (cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
00021         except AttributeError:
00022             pass
00023         else:
00024             # RLIMIT_FSIZE should be RLIM_INFINITY, which will be a really big
00025             # number on a platform with large file support.  On these platforms,
00026             # we need to test that the get/setrlimit functions properly convert
00027             # the number to a C long long and that the conversion doesn't raise
00028             # an error.
00029             self.assertEqual(resource.RLIM_INFINITY, max)
00030             resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))

Here is the call graph for this function:

Definition at line 78 of file test_resource.py.

00078 
00079     def test_fsize_toobig(self):
00080         # Be sure that setrlimit is checking for really large values
00081         too_big = 10**50
00082         try:
00083             (cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
00084         except AttributeError:
00085             pass
00086         else:
00087             try:
00088                 resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
00089             except (OverflowError, ValueError):
00090                 pass
00091             try:
00092                 resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big))
00093             except (OverflowError, ValueError):
00094                 pass

Definition at line 95 of file test_resource.py.

00095 
00096     def test_getrusage(self):
00097         self.assertRaises(TypeError, resource.getrusage)
00098         self.assertRaises(TypeError, resource.getrusage, 42, 42)
00099         usageself = resource.getrusage(resource.RUSAGE_SELF)
00100         usagechildren = resource.getrusage(resource.RUSAGE_CHILDREN)
00101         # May not be available on all systems.
00102         try:
00103             usageboth = resource.getrusage(resource.RUSAGE_BOTH)
00104         except (ValueError, AttributeError):
00105             pass
00106         try:
00107             usage_thread = resource.getrusage(resource.RUSAGE_THREAD)
00108         except (ValueError, AttributeError):
00109             pass

Here is the call graph for this function:


The documentation for this class was generated from the following file: