-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Description
The test for empty strings in calls to pydoc.apropos() uses a chmod call that seems non-sensical:
cpython/Lib/test/test_pydoc/test_pydoc.py
Lines 1303 to 1318 in 7ec1fab
| @os_helper.skip_unless_working_chmod | |
| def test_apropos_empty_doc(self): | |
| pkgdir = os.path.join(TESTFN, 'walkpkg') | |
| os.mkdir(pkgdir) | |
| self.addCleanup(rmtree, pkgdir) | |
| init_path = os.path.join(pkgdir, '__init__.py') | |
| with open(init_path, 'w') as fobj: | |
| fobj.write("foo = 1") | |
| current_mode = stat.S_IMODE(os.stat(pkgdir).st_mode) | |
| try: | |
| os.chmod(pkgdir, current_mode & ~stat.S_IEXEC) | |
| with self.restrict_walk_packages(path=[TESTFN]), captured_stdout() as stdout: | |
| pydoc.apropos('') | |
| self.assertIn('walkpkg', stdout.getvalue()) | |
| finally: | |
| os.chmod(pkgdir, current_mode) |
(Line 1313 in particular)
This test was added as part of resolving #65747. Part of the triage of that issue included the observation that the problem could be reproduced by removing execute permissions from a directory. However, this appears to be unrelated to the reported problem.
By removing the x permission from the directory, the module is converted into a namespace package - at which point, it can't have a docstring. However, you can also validate this by... having a module without a docstring. Which the current test implements.
Adding to the confusion - the test only removes user execute permissions. Group and Global execute permissions are retained. The original report removed all execute permissions, not just user execute permissions; so the test isn't reproducing the triage example. The only explanation I can find for this is that the buildbots run with a umask of 0o77, which means removing user execute permissions is effectively equivalent to chmod a-x... but it won't be for anyone who isn't running under buildbot.
This was discovered in the process of developing #136740. This did reveal a bug in Emscripten's implementation of readdir() - but the actual test itself doesn't make any sense to me (or @hoodmane).