summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-04 17:19:13 (GMT)
committerGitHub <noreply@github.com>2024-06-04 17:19:13 (GMT)
commit2acbdc23ad4dd14b3b6ad22e06d6477dc57b0530 (patch)
treed328533c9795692917834ac3421481ba9c8d4574 /Lib
parent54023a63ccd273776f8b411cb904b1f88fc1e231 (diff)
downloadcpython-2acbdc23ad4dd14b3b6ad22e06d6477dc57b0530.zip
cpython-2acbdc23ad4dd14b3b6ad22e06d6477dc57b0530.tar.gz
cpython-2acbdc23ad4dd14b3b6ad22e06d6477dc57b0530.tar.bz2
[3.13] gh-89928: Fix integer conversion of device numbers (GH-31794) (GH-120053)
Fix os.major(), os.minor() and os.makedev(). Support device numbers larger than 2**63-1. Support non-existent device number (NODEV). (cherry picked from commit 7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_posix.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 7e5f04c..908354c 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -704,7 +704,8 @@ class PosixTester(unittest.TestCase):
self.assertEqual(posix.major(dev), major)
self.assertRaises(TypeError, posix.major, float(dev))
self.assertRaises(TypeError, posix.major)
- self.assertRaises((ValueError, OverflowError), posix.major, -1)
+ for x in -2, 2**64, -2**63-1:
+ self.assertRaises((ValueError, OverflowError), posix.major, x)
minor = posix.minor(dev)
self.assertIsInstance(minor, int)
@@ -712,13 +713,23 @@ class PosixTester(unittest.TestCase):
self.assertEqual(posix.minor(dev), minor)
self.assertRaises(TypeError, posix.minor, float(dev))
self.assertRaises(TypeError, posix.minor)
- self.assertRaises((ValueError, OverflowError), posix.minor, -1)
+ for x in -2, 2**64, -2**63-1:
+ self.assertRaises((ValueError, OverflowError), posix.minor, x)
self.assertEqual(posix.makedev(major, minor), dev)
self.assertRaises(TypeError, posix.makedev, float(major), minor)
self.assertRaises(TypeError, posix.makedev, major, float(minor))
self.assertRaises(TypeError, posix.makedev, major)
self.assertRaises(TypeError, posix.makedev)
+ for x in -2, 2**32, 2**64, -2**63-1:
+ self.assertRaises((ValueError, OverflowError), posix.makedev, x, minor)
+ self.assertRaises((ValueError, OverflowError), posix.makedev, major, x)
+
+ if sys.platform == 'linux':
+ NODEV = -1
+ self.assertEqual(posix.major(NODEV), NODEV)
+ self.assertEqual(posix.minor(NODEV), NODEV)
+ self.assertEqual(posix.makedev(NODEV, NODEV), NODEV)
def _test_all_chown_common(self, chown_func, first_param, stat_func):
"""Common code for chown, fchown and lchown tests."""