Skip to content

bpo-30870: IDLE: Add configdialog fontlist unittest #2666

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 12 commits into from
Jul 14, 2017

Conversation

mlouielu
Copy link
Contributor

No description provided.

@mention-bot
Copy link

@mlouielu, thanks for your PR! By analyzing the history of the files in this pull request, we identified @terryjreedy, @csabella and @kbkaiser to be potential reviewers.

@@ -88,6 +88,7 @@ def __init__(self, parent, title='', _htest=False, _utest=False):
self.attach_var_callbacks() # Avoid callbacks during load_configs.

if not _utest:
self.grab_set()
Copy link
Member

@terryjreedy terryjreedy Jul 11, 2017

Choose a reason for hiding this comment

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

I believe at least some other dialogs have grab_set here already. Is this move also needed for event_generate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only saw it at textview that control with model argument. grab_set somehow will affect event_generate, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test_textview mock out the grab_set, hmm. Should we mock out, too?

Copy link
Member

Choose a reason for hiding this comment

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

Since it will not be called, no need. I just read the UNM Shipman doc "Widget w grabs all events for w's application. If there was another grab in force, it goes away. See Section 54, “Events” for a discussion of grabs." Seems to be related to dialog being modal. Did not see anything in Sect.54 though. I need to make sure I know about all the calls in various inits.

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.

Super. Will look at tests later.

@terryjreedy
Copy link
Member

terryjreedy commented Jul 11, 2017

Appveyor, running on Windows, and my Win 10 machine, say:

FAIL: test_key_up_down_should_change_font_and_sample (idlelib.idle_test.test_configdialog.FontTabTest)
Traceback (most recent call last):
File "C:\projects\cpython\lib\idlelib\idle_test\test_configdialog.py", line 100, in test_key_up_down_should_change_font_and_sample
self.assertNotEqual(down_font, font)
AssertionError: 'Courier New' == 'Courier New'
EDIT
These look the same to me, so this test should fail.
print('\n', [ord(c) for c in down_font], '\n', [ord(c) for c in font])
I will try to figure out why OS should make a difference, and what is going on on Windows.

@mlouielu
Copy link
Contributor Author

mlouielu commented Jul 12, 2017

@terryjreedy I think the assertion is correct, the result we want to pass is the down_font different with font, since down_font expected be another font.

@mlouielu
Copy link
Contributor Author

mlouielu commented Jul 12, 2017

After adding focus_force, it pass both on travis and appveyor.

@terryjreedy
Copy link
Member

@mlouielu I initially mis-interpreted Appveyor result before I ran test myself and realized that the failure was correct and pointed to a need for a fix. I presume focus_force created no problem on your Linux.

@terryjreedy
Copy link
Member

I have reviewed and am revising and will push for review and test. Please don't push any more commits for now.

@terryjreedy
Copy link
Member

Changes:

  1. Using verb configure for the dialog was a mistake, probably mine. Corrected.
  2. Testing events and event_handler together is necessary. Trying to test set_font_sample at the same time was my mistake. I corrected this by masking the function with an instance mock that could be queried about calls. I moved these 2 tests into a new class which describes what is to be tested.
  3. It does not matter what item on the list starts as active, so the first is as good as any. What matters is what happens after the simulated user actions.
  4. Abbreviated 'dialog.fontlist' as 'fontlist'.
  5. Setting tk font Variables has no effect on fontlist. Deleting that block had no effect.
  6. The click test did not test the effect of clicking. It passed without the simulated click. The generated button press is needed to set the anchor read in the event handler. Added a test that the click actually selected the intended item.

fontlist = dialog.fontlist
fontlist.activate(0)

# Select next item in listbox
Copy link
Contributor Author

@mlouielu mlouielu Jul 13, 2017

Choose a reason for hiding this comment

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

Need two more space for the comment. I'll fixed this.

@mlouielu
Copy link
Contributor Author

@terryjreedy Thanks for your help, this makes the test more reliable. I fix some nit point about styling. Otherwise LGTM.

fontlist.event_generate('<Button-1>', x=x+dx//2, y=y+dy//2)
fontlist.event_generate('<ButtonRelease-1>', x=x+dx//2, y=y+dy//2)
fontlist.event_generate('<Button-1>', x=x + dx // 2, y=y + dy // 2)
fontlist.event_generate('<ButtonRelease-1>', x=x + dx // 2, y=y + dy // 2)
Copy link
Member

Choose a reason for hiding this comment

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

I disagree. For an assignment statement, I would write
x = x + dx//2
Following math tradition here is allowed by pep8. When the space around '=' is deleted, as per PEP8, it looks weird, and visually deceptive, to leave space around '+'. I don't know if this is specifically addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After re-reading PEP8, I concur with your way to present x = x + dx//2, but it's weird in this situation, too.

I convert it to another way to represent:

x += dx // 2
y += dy // 2
event_generate(x=y, y=y)

I hope this will be more general in this case.

Copy link
Member

Choose a reason for hiding this comment

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

With two uses, that looks better.


@classmethod
def tearDownClass(cls):
del dialog.set_font_sample # unmask instance method
del dialog.set_font_sample # Unmask instance method
Copy link
Member

Choose a reason for hiding this comment

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

Old habits die hard. I added the '.'s.

@@ -138,7 +138,7 @@ def test_select_font_key(self):
self.assertEqual(dialog.set_font_sample.called, 2)

def test_select_font_mouse(self):
# Click on item should select that item.
"Click on item should select that item."
Copy link
Member

Choose a reason for hiding this comment

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

I tried this once and stopped when I discovered that running a file with unittest.main(verbosity=2) prints the docstrings, as in this example where I added one. Ditto for python -m test.test_idle -v.
test_font (__main__.FontTabTest) ... ok
test_set_sample (__main__.FontTabTest)
Set_font_sample also sets highlight_sample. ... ok
test_tabspace (__main__.FontTabTest) ... ok
I decided I did not like it and reverted the couple of examples.

Verbosity 1 prints a '.' for each successful test. 0 prints nothing until the end.

With the effect understood, I am willing to discuss a change, with at least Cheryl included.
In the meanwhile, please revert (you can use pencil edit upper right).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, revert this first.

@terryjreedy terryjreedy merged commit 9b622fb into python:master Jul 14, 2017
terryjreedy pushed a commit to terryjreedy/cpython that referenced this pull request Jul 14, 2017
terryjreedy added a commit that referenced this pull request Jul 14, 2017
…H-2666) (#2701)

Initial patch by Louie Lu.
(cherry picked from commit 9b622fb)
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.

4 participants