-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-30617: IDLE: docstrings and unittest for outwin.py #2046
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
Conversation
@csabella, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kbkaiser, @rhettinger and @terryjreedy to be potential reviewers. |
Lib/idlelib/idle_test/test_outwin.py
Outdated
from idlelib import filelist | ||
from idlelib import outwin | ||
from test.support import requires | ||
requires('gui') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a duplicate requires('gui')
since you have do it inside the setUpClass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, if we are trying to add docstring or unittest, we should only add docstring and unittest, and not need to move other code, for example, the _file_line_helper
and others.
Otherwise, it will be a refactor, and should be mention in the commit message (and title). If the refactoring is a must, I will prefer to split it into to two PR.
And the string quote should be consist. If we choice to use '
, it will all be '
in the new code.
|
||
from idlelib.editor import EditorWindow | ||
from idlelib import iomenu | ||
|
||
|
||
class OutputWindow(EditorWindow): | ||
file_line_pats = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why move out the internal parts? We can access these by OutputWindow.file_line_pats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the _file_line_helper and these values to the module level per Terry's suggestion on the bug tracker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csabella dh, I saw it. I think it should be another issue to deal with these codes changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it would have been better in certain respects to start with a pure docstring patch, then tests of code as is, then a code fix-up and movement patch. This is more or less what we did with configdialog. This would be at least 2, maybe 3 issues. However, I have reviewed it as it is.
Nothng to do.
Lib/idlelib/idle_test/test_outwin.py
Outdated
self.assertEqual(self.window.top.title(), "Output") | ||
|
||
def test_ispythonsource(self): | ||
self.assertFalse(self.window.ispythonsource("test.py")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add another filename to test, and the docstring that explicit says this will only return False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
@mlouielu I haven't made a separate PR yet, but I've made the other changes you suggested. I also added deletes for the mocks. One thing I wanted to ask is if you could help with the errors I'm getting when running the tests (warning: callback failed in WindowList <class '_tkinter.TclError'> : invalid command name ".!menu.windows"). I don't know enough to understand where to look to figure this out or what to change. Would you have any suggestions on what I can look at or how I can trace it? Thanks! |
2f964a4
to
4adf076
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The major issue is the test failure when the entire suite is run, which I will discuss separately.
cls.text = w.text = Text(root) | ||
|
||
@classmethod | ||
def tearDownClass(cls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on bpo-31284, msg 300912, adding cls.window.close()
stops the error message on Windows.
Done.
Lib/idlelib/outwin.py
Outdated
def ispythonsource(self, filename): | ||
"Control colorization of Python source." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Python source is only part of output: do not colorize."
delete comment.
Done.
Lib/idlelib/outwin.py
Outdated
return "Output" | ||
|
||
def maybesave(self): | ||
"Customize EditorWindow to not display save file messagebox." | ||
# Override base class method -- don't ask any questions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete comment - replaced by docstring.
Done.
Lib/idlelib/outwin.py
Outdated
("Go to file/line", "<<goto-file-line>>", None), | ||
] | ||
Provide file flush functionality for the window. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condense to "No flushing needed as write() directly writes to widget."
Done.
Lib/idlelib/outwin.py
Outdated
except TypeError: | ||
return None | ||
self.flist.gotofileline(filename, lineno) | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By PEP8, the returns were fine as they were. " Either all return statements in a function should return an expression, or none of them should." and none of them did.
Done.
|
||
from idlelib.editor import EditorWindow | ||
from idlelib import iomenu | ||
|
||
|
||
class OutputWindow(EditorWindow): | ||
file_line_pats = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it would have been better in certain respects to start with a pure docstring patch, then tests of code as is, then a code fix-up and movement patch. This is more or less what we did with configdialog. This would be at least 2, maybe 3 issues. However, I have reviewed it as it is.
Nothng to do.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
Lib/idlelib/idle_test/test_outwin.py
Outdated
|
||
w.flist = mock.Mock() | ||
gfl = w.flist.gotofileline = Func() | ||
showerror = outwin.messagebox.showerror = Mbox_func() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you patch the real module, the original showerror function must be saved and restored. I would rather put
showerror = messagebox.showerror
in Outwin (and change the later use to self.showerror), and then patch the instance for the test with `w.showerror = Mbox_func().
Done.
The problem in not with the messagebox import in outwin.py, as it persists with the import disabled. (This causes a later error when the above does not occur.) The test passes with line 269 commented out. Line 271
I believe that the problem is that we twice mocked askyesno in test_configdialog by replacing it and then deleting it. It is the same error as I reported above for showerrer here. The fix should save and restore. It can be a short PR for bpo-30780. Added: I opened new issue bpo-31287. I fixed issue by localizing askyesno to classes and then masking with instance attribute in tests. Did same for outwin and showerror. |
News blurb also needed |
The update includes the fix from bpo-31287 that fixes the GUI test failure (no messagebox.askyesno). I added a new file. Unfortunately, it causes Appveyor to not run. Closing and opening did not either. A regular patch will trigger Appveyor. Unless you post a patch first, I am going to make the fairly simple changes I requested. |
…H-2046) Move some data and functions from the class to module level. Patch by Cheryl Sabella. (cherry picked from commit 998f496)
Sorry, I was trying to figure out the whole thing with why Thanks for making the other changes. |
The configdialog test replaced the original askyesno function in the messagebox module with a Mock and then deleted the mock. Some test imported editor before that, and editor imported the same module object. By the time outwin imported editor, the messagebox module referenced by editor was deficient. Test_idle is run in one process. What puzzled me is that when outwin imported messagebox, it was not the same module object. (It had a different id().) I did not try to work out why. Python imports, with caching in sys.modules, is a tricky business sometimes. |
Thanks for explaining. I played around some more (using mock.patch) and I think I have a better understanding of this. There's a line in the mock.patch documentation, under the |
Move some data and functions from the class to module level. Patch by Cheryl Sabella.
https://bugs.python.org/issue30617