New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_socket fails if /proc/modules is existent but not readable #73001
Comments
Dear Python developers The test_socket test fails if /proc/modules is existent but not readable by the user (this is for example the case with the grsecurity patchset of the kernel). The method reading /proc/modules is isTipcAvailable(), which is not a test but a guard for other tests. Attached a proposed test. Feel free to remove the EISDIR in case you feel uncomfortable and want a it be a "real" error. Kind regards Here is the inline version of the patch; it's also attached. diff -r 876bee0bd0ba Lib/test/test_socket.py
--- a/Lib/test/test_socket.py Sat Nov 26 14:04:40 2016 -0800
+++ b/Lib/test/test_socket.py Sun Nov 27 17:00:55 2016 +0100
@@ -4779,12 +4779,21 @@
"""
if not hasattr(socket, "AF_TIPC"):
return False
- if not os.path.isfile("/proc/modules"):
- return False
- with open("/proc/modules") as f:
- for line in f:
- if line.startswith("tipc "):
- return True
+ 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 (ENOENT, EISDIR, EACCES):
+ return False
+ else:
+ raise
+ else:
+ with f:
+ for line in f:
+ if line.startswith("tipc "):
+ return True
return False @unittest.skipUnless(isTipcAvailable(), |
This seems reasonable in general. Did you test this exact patch Patrila? It looks to me like you need to change ENOENT → errno.ENOENT, etc. |
Oops, sorry that was the draft version of the patch. |
New changeset 7889d7a771c7 by Martin Panter in branch '3.5': New changeset 48b9d9cdfe3b by Martin Panter in branch '3.6': New changeset 7ceacac48cd2 by Martin Panter in branch 'default': New changeset 41a99a2a7198 by Martin Panter in branch '2.7': |
Wouldn't be more pythonic to catch (FileNotFoundError, IsADirectoryError, PermissionError) instead of checking errno? |
That would be possible in Python 3, not Python 2 though. |
@martin Panter: Thanks for your support and merging. |
New changeset 5a417e160b34 by Martin Panter in branch '3.5': New changeset 401e70317976 by Martin Panter in branch '3.6': New changeset 82fb37281954 by Martin Panter in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: