changeset 86635:513da56d28de

test_resource should not assume all attributes are available when they are individually controlled by #ifdef statements in the extension code.
author Brett Cannon <brett@python.org>
date Fri, 25 Oct 2013 15:45:25 -0400
parents f3d50720dee0
children 315bf54f5419
files Lib/test/test_resource.py
diffstat 1 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/test/test_resource.py	Fri Oct 25 15:39:02 2013 -0400
+++ b/Lib/test/test_resource.py	Fri Oct 25 15:45:25 2013 -0400
@@ -1,3 +1,4 @@
+import contextlib
 import sys
 import os
 import unittest
@@ -133,12 +134,9 @@
 
     @unittest.skipUnless(sys.platform == 'linux', 'test requires Linux')
     def test_linux_constants(self):
-        self.assertIsInstance(resource.RLIMIT_MSGQUEUE, int)
-        self.assertIsInstance(resource.RLIMIT_NICE, int)
-        self.assertIsInstance(resource.RLIMIT_RTPRIO, int)
-        self.assertIsInstance(resource.RLIMIT_RTTIME, int)
-        self.assertIsInstance(resource.RLIMIT_SIGPENDING, int)
-
+        for attr in ['MSGQUEUE', 'NICE', 'RTPRIO', 'RTTIME', 'SIGPENDING']:
+            with contextlib.suppress(AttributeError):
+                self.assertIsInstance(getattr(resource, 'RLIMIT_' + attr), int)
 
     @unittest.skipUnless(hasattr(resource, 'prlimit'), 'no prlimit')
     @support.requires_linux_version(2, 6, 36)