summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-07 21:13:46 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-07 21:13:46 (GMT)
commita2ad5c3ad1bbf6d2088ff3ab2eb3bba51d096cc2 (patch)
tree097dbbd7fe661b0da5e496ee972f0c6df5a35842 /Lib
parent0e82fd1f78a9ae07c16b1f57a0f39bc56f798b30 (diff)
downloadcpython-a2ad5c3ad1bbf6d2088ff3ab2eb3bba51d096cc2.zip
cpython-a2ad5c3ad1bbf6d2088ff3ab2eb3bba51d096cc2.tar.gz
cpython-a2ad5c3ad1bbf6d2088ff3ab2eb3bba51d096cc2.tar.bz2
Issue #15972: Fix error messages when os functions expecting a file name or
file descriptor receive the incorrect type.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_posix.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index f4e8aba..26d5570 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -358,12 +358,28 @@ class PosixTester(unittest.TestCase):
try:
self.assertTrue(posix.fstat(fp.fileno()))
self.assertTrue(posix.stat(fp.fileno()))
+
+ self.assertRaisesRegex(TypeError,
+ 'should be string, bytes or integer, not',
+ posix.stat, float(fp.fileno()))
finally:
fp.close()
def test_stat(self):
if hasattr(posix, 'stat'):
self.assertTrue(posix.stat(support.TESTFN))
+ self.assertTrue(posix.stat(os.fsencode(support.TESTFN)))
+ self.assertTrue(posix.stat(bytearray(os.fsencode(support.TESTFN))))
+
+ self.assertRaisesRegex(TypeError,
+ 'can\'t specify None for path argument',
+ posix.stat, None)
+ self.assertRaisesRegex(TypeError,
+ 'should be string, bytes or integer, not',
+ posix.stat, list(support.TESTFN))
+ self.assertRaisesRegex(TypeError,
+ 'should be string, bytes or integer, not',
+ posix.stat, list(os.fsencode(support.TESTFN)))
@unittest.skipUnless(hasattr(posix, 'mkfifo'), "don't have mkfifo()")
def test_mkfifo(self):
@@ -714,6 +730,14 @@ class PosixTester(unittest.TestCase):
s1 = posix.stat(support.TESTFN)
s2 = posix.stat(support.TESTFN, dir_fd=f)
self.assertEqual(s1, s2)
+ s2 = posix.stat(support.TESTFN, dir_fd=None)
+ self.assertEqual(s1, s2)
+ self.assertRaisesRegex(TypeError, 'should be integer, not',
+ posix.stat, support.TESTFN, dir_fd=posix.getcwd())
+ self.assertRaisesRegex(TypeError, 'should be integer, not',
+ posix.stat, support.TESTFN, dir_fd=float(f))
+ self.assertRaises(OverflowError,
+ posix.stat, support.TESTFN, dir_fd=10**20)
finally:
posix.close(f)