Skip to content

bpo-32831: IDLE: Add docstrings and tests for codecontext #5638

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

Merged
merged 6 commits into from
May 19, 2018

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Feb 12, 2018

@terryjreedy
Copy link
Member

terryjreedy commented May 17, 2018

I have updated to current upstream. Tests pass. I am reviewing and making minor changes.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the changes I made (mostly to the two longest docstrings), I think this is ready to merge. You can look at my changes first, and do a last check, but I want to merge in a day or two so this gets into 3.7.0rc1.

editor. It is initialized to None to not display the code context
and it is toggled via <<toggle-code-context>>. If code context is
not suitable for an editor window, then unbind the text from
<<toggle-code-context>>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the part about unbinding because it happens in the editor, not here. I have, however, thought about whether binding for some features should be in the feature init.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about whether binding for some features should be in the feature init.

I tried this and it worked, but I think it should be its own issue since it's more than just code cleanup.

eq(cc.info, [(0, -1, '', False)])
eq(cc.topvisible, 1)
self.root.tk.call('after', 'info', self.cc.t1)
self.root.tk.call('after', 'info', self.cc.t2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to remember some discussion with Serhiy about after info, but not the outcome. Checking that the 2nd component of the tuple is 'timer' works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The after_info PR is still open. But Serhiy had said that I wouldn't be able to use it for these tests anyway because that project couldn't be backported to 3.6. As far as that PR, I had asked him some questions on the bug tracker that he hasn't gotten to yet. I've been thinking of making the changes that I asked about just to see if it would be straight forward or not.


def test_del(self):
self.root.tk.call('after', 'info', self.cc.t1)
self.root.tk.call('after', 'info', self.cc.t2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Looking at the commit history, it appears that I had originally mocked the after calls and then removed the mock later. I don't remember exactly, but I think I was having trouble writing these tests because the after events still existed, even after this test suite was finished. But, once I figured it out, I think these lines could have been removed. I'm working on a patch now to address some of the other code cleanup comments and I'll remove these lines as part of that.

def setUpClass(cls):
requires('gui')
root = cls.root = Tk()
frame = cls.frame = Frame(root)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize screen flashing, I always add root.withdraw() unless the test requires visible widgets for simulated user actions.

@@ -0,0 +1,345 @@
"""Test idlelib.codecontext.

Coverage: 100%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get 99% when checking that branches are taken both ways. The condition for the following is never false.
194 elif self.topvisible > new_topvisible: # scroll up
As written, it never can be, since == and < have already been excluded.
I changed elif to else.

def getspacesfirstword(s, c=re.compile(r"^(\s*)(\w*)")):
"Extract the beginning whitespace and first word from s."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do a code cleanup pass, get_spaces_firstword and replace s with codeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including this in the code cleanup PR.

@@ -95,11 +125,10 @@ def toggle_code_context_event(self, event=None):
return "break"

def get_line_info(self, linenum):
"""Get the line indent value, text, and any block start keyword
"""Return tuple of (line indent value, text, and block start keyword).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we removed self and added codeline as a parameter, this would become a helper function and testable without the cc fixture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including this in the code cleanup PR.

'keys': config.IdleUserConfParser(''),
'extensions': config.IdleUserConfParser(''),
}
code_sample = """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without \ at the end, I did not initially see that the code actually starts on line 2, which made the tests more confusing. A added \ and a blank line so the sample visibly start with a blank.

@terryjreedy
Copy link
Member

Given that the CI bots have become merge roadblocks, I don't want to touch this unless a change is non-trivial.

@terryjreedy terryjreedy merged commit 654038d into python:master May 19, 2018
@miss-islington
Copy link
Contributor

Thanks @csabella for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 19, 2018
)

(cherry picked from commit 654038d)

Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
@bedevere-bot
Copy link

GH-6988 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 19, 2018
)

(cherry picked from commit 654038d)

Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
@bedevere-bot
Copy link

GH-6989 is a backport of this pull request to the 3.6 branch.

miss-islington added a commit that referenced this pull request May 19, 2018
(cherry picked from commit 654038d)

Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
miss-islington added a commit that referenced this pull request May 19, 2018
(cherry picked from commit 654038d)

Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
@csabella csabella deleted the codecontext branch May 19, 2018 21:22
@csabella
Copy link
Contributor Author

@terryjreedy, thanks for the merge. Sorry I didn't get to address your questions before you committed the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants