https://github.com/python/cpython/commit/ac37b77441d628df6fa3eb41f040a7c60cb166ec
commit: ac37b77441d628df6fa3eb41f040a7c60cb166ec
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-08-19T15:22:30+03:00
summary:

gh-137044: Fix test_resource on 32-bit Linux (GH-137941)

files:
M Lib/test/test_resource.py

diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py
index f73914b9b92c83..5fd076bee38e79 100644
--- a/Lib/test/test_resource.py
+++ b/Lib/test/test_resource.py
@@ -116,33 +116,40 @@ def test_fsize_not_too_big(self):
         self.addCleanup(resource.setrlimit, resource.RLIMIT_FSIZE, (cur, max))
 
         def expected(cur):
-            return (min(cur, resource.RLIM_INFINITY), max)
+            # The glibc wrapper functions use a 64-bit rlim_t data type,
+            # even on 32-bit platforms. If a program tried to set a resource
+            # limit to a value larger than can be represented in a 32-bit
+            # unsigned long, then the glibc setrlimit() wrapper function
+            # silently converted the limit value to RLIM_INFINITY.
+            if sys.maxsize < 2**32 <= cur <= resource.RLIM_INFINITY:
+                return [(resource.RLIM_INFINITY, max), (cur, max)]
+            return [(min(cur, resource.RLIM_INFINITY), max)]
 
         resource.setrlimit(resource.RLIMIT_FSIZE, (2**31-5, max))
         self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), (2**31-5, 
max))
         resource.setrlimit(resource.RLIMIT_FSIZE, (2**31, max))
-        self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**31))
+        self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**31))
         resource.setrlimit(resource.RLIMIT_FSIZE, (2**32-5, max))
-        self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**32-5))
+        self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**32-5))
 
         try:
             resource.setrlimit(resource.RLIMIT_FSIZE, (2**32, max))
         except OverflowError:
             pass
         else:
-            self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**32))
+            self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**32))
 
             resource.setrlimit(resource.RLIMIT_FSIZE, (2**63-5, max))
-            self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**63-5))
+            self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**63-5))
             try:
                 resource.setrlimit(resource.RLIMIT_FSIZE, (2**63, max))
             except ValueError:
                 # There is a hard limit on macOS.
                 pass
             else:
-                self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**63))
+                self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**63))
                 resource.setrlimit(resource.RLIMIT_FSIZE, (2**64-5, max))
-                self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**64-5))
+                self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), 
expected(2**64-5))
 
     @unittest.skipIf(sys.platform == "vxworks",
                      "setting RLIMIT_FSIZE is not supported on VxWorks")

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to