-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-30303: IDLE: Add _utest argument to textview #1499
Conversation
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.
At first reading, the textview.py changes are just right. The test needs some minor changes.
def _command(): | ||
self.called = True | ||
self.view = tv.view_text(self.root, 'TITLE_TEXT', 'COMMAND', _utest=self._utest) | ||
button = Button(self.root, text='BUTTON', command=_command) |
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.
Use global 'root' here and below.
@@ -96,5 +96,52 @@ def test_view_file(self): | |||
self.assertIsNone(view) | |||
|
|||
|
|||
class ButtonClickTextViewTest(unittest.TestCase): | |||
@classmethod | |||
def setUpClass(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.
I don't think this and tearDownClass are needed. The module root should work. Just pass '_utest=True' in both calls.
@@ -8,12 +8,12 @@ | |||
Coverage: 94%. | |||
''' | |||
from idlelib import textview as tv | |||
from test.support import requires | |||
from test.support import requires, findfile |
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.
See comment below about findfile.
@@ -8,12 +8,12 @@ | |||
Coverage: 94%. |
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.
After I adapt my coverage.bat to work with the git repository, I will get new value.
|
||
self.assertEqual(self.called, True) | ||
self.assertEqual(self.view.title(), 'TITLE_TEXT') | ||
self.assertEqual(self.view.textView.get('1.0', '1.end'), 'COMMAND') |
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.
Follow with 'button.destroy()'.
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'm using addCleanup
instead of directly using button.destroy
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.
Good idea.
|
||
def test_view_file_bind_with_button(self): | ||
def _command(): | ||
fn = findfile('CREDITS.txt', 'idlelib') |
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.
osp = os.path
fn =osp.abspath(osp.join(osp.dirname('file'), '..', 'CREDITS.txt'))
would be equivalent. But to make the test simpler, just pass 'file' instead of fn and adjust assert.
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 boldface __file__is the dunder name interpreted as markup. Unlike StackOverflow, there is no preview of the rendering. Let's try it with backticks __file__
.
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 the interpretation is only in quotes? 'file', "file".
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 can't reproduce the equivalent between osp and findfile. On my situation, I'm running unittest at python/cpython, so the osp.dirname('file')
will return ``, not Lib/idlelib/idle_test
.
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.
Now with quotes and backticks: backtick inner: "__file__
", outer '__file__'
.
PS I checked the markdown link below but it was insufficient.
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.
ah, I see, is __file__
, not 'file'
self.assertEqual(self.view.title(), 'TITLE_FILE') | ||
self.assertEqual(self.view.textView.get('1.0', '1.end'), | ||
'Guido van Rossum, as well as being the creator of the ' | ||
'Python language, is the') |
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.
Using file makes this file self-contained.
self.assertIn(self.view.textView.get('1.0', '1.end'), 'idlelib.textview'
If this file is edited to make this fail, then this file fails immediately.
Codecov Report
@@ Coverage Diff @@
## master #1499 +/- ##
==========================================
- Coverage 83.44% 82.68% -0.76%
==========================================
Files 1368 1432 +64
Lines 346621 353062 +6441
==========================================
+ Hits 289241 291934 +2693
- Misses 57380 61128 +3748
Continue to review full report at Codecov.
|
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 am about to push my changes back and will merge once CI allows.
self.assertEqual(self.view.textView.get('1.0', '1.end'), | ||
f.readline().strip()) | ||
self.assertEqual(self.view.textView.get('2.0', '2.end'), | ||
f.readline().strip()) |
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 like making this future proof. However, since the 2nd line is blank and Texts have a default extra \n at the end, I believe this would pass even if the textview only displayed one line. So I added an intermediate f.readline()
and changed 2s to 3s.
(cherry picked from commit ba365da)
Can I ask if a CLA was eventually verified as being signed before merging this? |
@brettcannon I asked the PR author in bpo-30303 about this. |
@louisom is my previous account, does b.p.o. support comma split (louisom, mlouielu) at the detail page? |
🐍🍒⛏🤖 Thanks @louisom for the PR, and @terryjreedy for merging it 🌮🎉.I'm working now to backport this PR to: 3.6. |
Sorry, @louisom and @terryjreedy, I could not cleanly backport this to |
The backport error is because this was backported already in #1916. (And the file has been refactored since.) I removed the label. |
No description provided.