]> granicus.if.org Git - python/commitdiff
Make resource tests more robust.
authorChristian Heimes <christian@cheimes.de>
Tue, 22 Oct 2013 09:45:30 +0000 (11:45 +0200)
committerChristian Heimes <christian@cheimes.de>
Tue, 22 Oct 2013 09:45:30 +0000 (11:45 +0200)
Lib/test/test_resource.py

index 950f4778be4fc70e84d58e9c33acff72b052aeae..239d8d5e8d8c7acb69712e68fc7373323a103b6e 100644 (file)
@@ -1,4 +1,5 @@
 import sys
+import os
 import unittest
 from test import support
 import time
@@ -142,13 +143,15 @@ class ResourceTest(unittest.TestCase):
     @unittest.skipUnless(hasattr(resource, 'prlimit'), 'no prlimit')
     def test_prlimit(self):
         self.assertRaises(TypeError, resource.prlimit)
-        self.assertRaises(PermissionError, resource.prlimit,
-                          1, resource.RLIMIT_AS)
+        if os.geteuid() != 0:
+            self.assertRaises(PermissionError, resource.prlimit,
+                              1, resource.RLIMIT_AS)
         self.assertRaises(ProcessLookupError, resource.prlimit,
                           -1, resource.RLIMIT_AS)
-        self.assertEqual(resource.prlimit(0, resource.RLIMIT_AS), (-1, -1))
-        self.assertEqual(resource.prlimit(0, resource.RLIMIT_AS, (-1, -1)),
-                         (-1, -1))
+        limit = resource.getrlimit(resource.RLIMIT_AS)
+        self.assertEqual(resource.prlimit(0, resource.RLIMIT_AS), limit)
+        self.assertEqual(resource.prlimit(0, resource.RLIMIT_AS, limit),
+                         limit)
 
 
 def test_main(verbose=None):