]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #28815: Skip TIPC tests if /proc/modules is not readable
authorMartin Panter <vadmium+py@gmail.com>
Sat, 24 Dec 2016 10:41:37 +0000 (10:41 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Sat, 24 Dec 2016 10:41:37 +0000 (10:41 +0000)
Based on patch by Patrila.

Lib/test/test_socket.py

index dbfcab8f6febb56125e07f904bba33bb2d294594..ea3ca28a39952cb76f99ac42fe175198d8910c62 100644 (file)
@@ -4717,9 +4717,17 @@ def isTipcAvailable():
     """
     if not hasattr(socket, "AF_TIPC"):
         return False
-    if not os.path.isfile("/proc/modules"):
-        return False
-    with open("/proc/modules") as f:
+    try:
+        f = open("/proc/modules")
+    except IOError as e:
+        # It's ok if the file does not exist, is a directory or if we
+        # have not the permission to read it. In any other case it's a
+        # real error, so raise it again.
+        if e.errno in (errno.ENOENT, errno.EISDIR, errno.EACCES):
+            return False
+        else:
+            raise
+    with f:
         for line in f:
             if line.startswith("tipc "):
                 return True