bpo-36405: IDLE - Restore __main__ and add tests#12518
bpo-36405: IDLE - Restore __main__ and add tests#12518
Conversation
Fix error in commit 2b75155 noticed by Serhiy Storchaka.
| small, large = self.autocomplete.fetch_completions( | ||
| '', ac.COMPLETE_ATTRIBUTES) | ||
| self.assertLess(len(small), len(large)) | ||
| self.assertTrue('AutoComplete' not in small or # See issue 36405. |
There was a problem hiding this comment.
I dislike complex expressions in assertTrue() because it gives little information when the test is failed and it is easy to make an error that makes the test be always passed.
If I understand the problem correctly, this could be written as:
if __main__ is idlelib.autocomplete:
self.assertIn('testing_in_autocomplete', small)
else:
self.assertNotIn('AutoComplete', small)There was a problem hiding this comment.
I agree about disliking what is a bit of a kludge. However, even when autocomplete.py is run, main and idlelib.autocomplete (ac) are different and unequal module instances, with different names ('main' and 'idlelib.autocomplete'), different types for builtins (module and dict), and unique attributes (annotations and cached). What are equal if and only if both modules derived from the same file are the __file__s. Test code added to test_autocomplete.
print(__main__, ac, __main__ is ac)
print(type(__main__.__builtins__), type(ac.__builtins__))
print(dir(__main__))
print(dir(ac))
print(__main__.__file__, ac.__file__)The goal is to detect whether the merged dict is main.dict (right) or autocomplete globals() (wrong). When the test is run with autocomplete as main, they are the same, so there is nothing to test. We must either skip 'AutoComplete not in small' or add something to make the resulting expression true. I did the latter, but former will be nicer. The following works.
if __main__.__file__ != ac.__file__:
self.assertNotIn('AutoComplete', small)Thank you for the hint of where to look.
|
@terryjreedy: Please replace |
|
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
|
GH-12526 is a backport of this pull request to the 3.7 branch. |
Fix error in commit 2b75155 noticed by Serhiy Storchaka. (cherry picked from commit 0fe4513) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Fix error in commit 2b75155 noticed by Serhiy Storchaka.
https://bugs.python.org/issue36405