aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_pathlib.py
diff options
context:
space:
mode:
authorPrzemysław Spodymek <przemyslaw@spodymek.com>2018-08-27 23:33:45 +0200
committerSteve Dower <steve.dower@microsoft.com>2018-08-27 14:33:45 -0700
commit216b745eafa7cd4a683a8405dcfbd7f5567f504c (patch)
treea7c4bdd4ddc248117e23cebb7602802fcafb6b45 /Lib/test/test_pathlib.py
parent7ef1697be54a74314d5214d9ba0580d4e620694c (diff)
downloadcpython-216b745eafa7cd4a683a8405dcfbd7f5567f504c.tar.gz
cpython-216b745eafa7cd4a683a8405dcfbd7f5567f504c.zip
bpo-33635: Handling Bad file descriptor in Path.is_file and related. (GH-8542)
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rw-r--r--Lib/test/test_pathlib.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index ae7c75deb0e..e436db995ce 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1,6 +1,7 @@
import collections.abc
import io
import os
+import sys
import errno
import pathlib
import pickle
@@ -2176,6 +2177,29 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
self.assertEqual(p6.expanduser(), p6)
self.assertRaises(RuntimeError, p7.expanduser)
+ @unittest.skipIf(sys.platform != "darwin",
+ "Bad file descriptor in /dev/fd affects only macOS")
+ def test_handling_bad_descriptor(self):
+ try:
+ file_descriptors = list(pathlib.Path('/dev/fd').rglob("*"))[3:]
+ if not file_descriptors:
+ self.skipTest("no file descriptors - issue was not reproduced")
+ # Checking all file descriptors because there is no guarantee
+ # which one will fail.
+ for f in file_descriptors:
+ f.exists()
+ f.is_dir()
+ f.is_file()
+ f.is_symlink()
+ f.is_block_device()
+ f.is_char_device()
+ f.is_fifo()
+ f.is_socket()
+ except OSError as e:
+ if e.errno == errno.EBADF:
+ self.fail("Bad file descriptor not handled.")
+ raise
+
@only_nt
class WindowsPathTest(_BasePathTest, unittest.TestCase):