Skip to content
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

manually set the text format to plain text in error #1546

Merged
merged 7 commits into from
Mar 24, 2021

Conversation

aaronayres35
Copy link
Contributor

@aaronayres35 aaronayres35 commented Mar 19, 2021

fixes #1543

Note I am observing a segfault when I set the slider to 0 in the example given in the issue and then close the information dialog (this occurs both with and without the changes of this PR)
Im not sure why we weren't previously using information from the pyface.api here (see: https://github.com/enthought/pyface/blob/65813858730a61f25618e98669bcc5347d44935a/pyface/message_dialog.py#L15-L43)

In any case, now in order to call setTextFormat we would not be ably to use pyface directly anyway / we can no longer call the static function QtGui.QMessageBox.information.

This is what I currently see if I set the slider to 0.0:
Screen Shot 2021-03-19 at 3 19 51 PM

As opposed to this from before:

Screen Shot 2021-03-19 at 3 21 01 PM

I am unsure why 2 dialogs show up (this is probably a separate bug?)

A test for this would likely require UITester + ModalDialogTester to look at the displayed text in the created modal dialog. I will investigate this now

@aaronayres35
Copy link
Contributor Author

I have the bones set up for a test, but the test hits the segfault I describe above. This will likely need some other fix

@aaronayres35 aaronayres35 changed the title manually set the text format to plain text in error [WIP] manually set the text format to plain text in error Mar 19, 2021
@rahulporuri
Copy link
Contributor

Note I am observing a segfault when I set the slider to 0 in the example given in the issue and then close the information dialog (this occurs both with and without the changes of this PR)

I'm not seeing this on windows with pyqt5. What toolkit are you seeing that behavior with? And if the segfault is persistent, there is something horrible going on so that needs a separate issue.

@rahulporuri
Copy link
Contributor

Im not sure why we weren't previously using information from the pyface.api here (see: https://github.com/enthought/pyface/blob/65813858730a61f25618e98669bcc5347d44935a/pyface/message_dialog.py#L15-L43)

I honestly dont know why I bothered but I dug into the code to realize that pyface.api.information isnt used here simply because it was added in 2008 (enthought/pyface@7aa4fb9) whereas this module was added in 2007 (266a874#diff-e282d9e0c90155c775f3886e3bd7b8d7d4f9f2a9d1b2ca7f64547d7c8a898646).

It looks like we might actually be able to replace the QMessageBox with a call to information.

@rahulporuri
Copy link
Contributor

I am unsure why 2 dialogs show up (this is probably a separate bug?)

I'm not seeing this either. Your fix works for me on windows with python 3.6 and pyqt5 and I just see the one dialog with the correct/expected text.

@aaronayres35
Copy link
Contributor Author

Im not sure why we weren't previously using information from the pyface.api here (see: https://github.com/enthought/pyface/blob/65813858730a61f25618e98669bcc5347d44935a/pyface/message_dialog.py#L15-L43)

I honestly dont know why I bothered but I dug into the code to realize that pyface.api.information isnt used here simply because it was added in 2008 (enthought/pyface@7aa4fb9) whereas this module was added in 2007 (266a874#diff-e282d9e0c90155c775f3886e3bd7b8d7d4f9f2a9d1b2ca7f64547d7c8a898646).

It looks like we might actually be able to replace the QMessageBox with a call to information.

We cant easily use information or MessageDialog form pyface as we need direct access to the control that gets created in _create_control, which is not called until the dialog is open. But we want to set the text format before the dialog gets opened. This should be an option in pyface and I will open a separate PR there to allow specifying the text formatting option in information / MessageDialog

@aaronayres35
Copy link
Contributor Author

I am unsure why 2 dialogs show up (this is probably a separate bug?)

I'm not seeing this either. Your fix works for me on windows with python 3.6 and pyqt5 and I just see the one dialog with the correct/expected text.

I tried locally with Ubuntu and pyqt5 and everything is exactly as I would expect. It seems to be a macos specific thing

On macOS, I git cleaned and create a fresh edm env and ran an example on master. I still see 2 dialogs and the segfault when trying to close one of them. I believe there is a bug here (potentially at the qt level) with macOS that is unrelated to the changes made in this PR. I will open an issue, but I am unsure what to do with this PR for the test

@aaronayres35
Copy link
Contributor Author

I pushed hoping to see if the macOS CI would have the same issue I was seeing. Unfortunately, the appveyor build has no logs (although it did fail).

Seemingly orthogonally, the Ubuntu pyside2 GH action is failing on a completely different test (????):

est_base_url_changed (traitsui.tests.editors.test_html_editor.TestHTMLEditor) ... Command '['edm', 'run', '-e', 'traitsui-test-3.6-pyside2', '--', 'python', '-W', 'default', '-m', 'coverage', 'run', '-p', '-m', 'unittest', 'discover', '-v', 'traitsui']' returned non-zero exit status 252.
/usr/bin/bash /home/runner/work/_actions/GabrielBB/xvfb-action/v1/cleanup.sh
No xvfb processes to kill
Error: The process '/usr/bin/xvfb-run' failed with exit code 1

Comment on lines 921 to 970
def test_editor_error_msg(self):
from pyface.toolkit import toolkit_object
from pyface.qt import QtGui
from traits.api import HasTraits, Range

from traitsui.testing.api import (
KeyClick, KeySequence, Textbox, UITester
)

ModalDialogTester = toolkit_object(
"util.modal_dialog_tester:ModalDialogTester"
)

class Foo(HasTraits):
x = Range(low=0.0, high=1.0, value=0.5, exclude_low=True)

foo = Foo()
tester = UITester()
with tester.create_ui(foo) as ui:

x_range = tester.find_by_name(ui, "x")
x_range_textbox = x_range.locate(Textbox())

for _ in range(3):
x_range_textbox.perform(KeyClick('Backspace'))

x_range_textbox.perform(KeySequence('0.0'))

def trigger_error():
x_range_textbox.perform(KeyClick('Enter'))

def check_and_close(mdtester):
try:
with mdtester.capture_error():
self.assertTrue(
mdtester.has_widget(
text="The 'x' trait of a Foo instance must be "
"0.0 < a floating point number <= 1.0, "
"but a value of 0.0 <class 'float'> was "
"specified.",
type_=QtGui.QMessageBox,
)
)
finally:
mdtester.close(accept=True)
self.assertTrue(mdtester.dialog_was_opened)

mdtester = ModalDialogTester(trigger_error)
mdtester.open_and_run(check_and_close)
self.assertTrue(mdtester.dialog_was_opened)
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 level of complexity for this test now seems to far exceed what it is trying to test :/
Perhaps the test could be trivia and just reach into Qt and make sure the textFormat property gets set? Like I do in enthought/pyface#907
This test will still require ModalDialogTester as the error method on editor does not return anything. It will only be accessible via triggering the dialog to pop up. I could replace the assert statement with
self.assertEqual(mdtester.get_dialog_widget().textFormat(), QtCore.Qt.PlainText) but that doesn't really feel any better

The macOS weirdness I am seeing feels like an orthogonal problem, and I am still very unclear on what the cause is.

Copy link
Member

Choose a reason for hiding this comment

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

The macOS weirdness I am seeing feels like an orthogonal problem, and I am still very unclear on what the cause is.

Yes. Definitely something strange going on here.

@jwiggins
Copy link
Member

Checking the text of the dialog in the test seems OK to me (or is that not working consistently?).

I think the bigger issue is the Qt-specific nature of the test code. I know we're not running Wx CI jobs, but it still feels a bit wrong to have a bunch of local imports and Qt specific code in a single test. Do you plan to remove the local imports before merging this?

@aaronayres35
Copy link
Contributor Author

Checking the text of the dialog in the test seems OK to me (or is that not working consistently?).

I think the bigger issue is the Qt-specific nature of the test code. I know we're not running Wx CI jobs, but it still feels a bit wrong to have a bunch of local imports and Qt specific code in a single test. Do you plan to remove the local imports before merging this?

Yeah I will clean up the imports and specify the test requires Qt specifically before merging.
But currently there is something bad happening on OSX. If you run the example are you seeing the double dialogs / possible segfault when you try to close them locally?

@jwiggins
Copy link
Member

Yes, the example from the issue causes a segfault when I run it on macOS. I believe that's a separate issue.

@aaronayres35
Copy link
Contributor Author

Yes, the example from the issue causes a segfault when I run it on macOS. I believe that's a separate issue.

Thank you very much for confirming that! I think I will just skip this test on OSX on CI then and open a separate issue

@aaronayres35
Copy link
Contributor Author

CI is still failing on Ubuntu/Pyside2 in a seemingly unrelated test...
I am unable to reproduce the test failure locally (on both OSX and Ubuntu)

When I run the relevant test module thought I do see the following:
"Release of profile requested but WebEnginePage still not deleted. Expect troubles !"

@jwiggins
Copy link
Member

Given all the crazy failures you're seeing, now might be a good time to add PYTHONFAULTHANDLER=1 to the test environment.

Copy link
Member

@jwiggins jwiggins left a comment

Choose a reason for hiding this comment

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

Changes look OK. Anything left here?

@aaronayres35
Copy link
Contributor Author

Changes look OK. Anything left here?

I think we are good to go? I am confused why the test_base_url_changed (traitsui.tests.editors.test_html_editor.TestHTMLEditor) test failure occurred and also confused why it suddenly went away... 🤔
It had occurred in multiple previous CI runs and somehow has disappeared now without any attempt at a fix

@jwiggins
Copy link
Member

Oooh boy. Intermittent failures are the best, huh?

We should probably just leave an issue and move on.

@aaronayres35
Copy link
Contributor Author

Oooh boy. Intermittent failures are the best, huh?

We should probably just leave an issue and move on.

I've opened #1551

@aaronayres35 aaronayres35 changed the title [WIP] manually set the text format to plain text in error manually set the text format to plain text in error Mar 24, 2021
@aaronayres35 aaronayres35 merged commit 62033f5 into master Mar 24, 2021
@aaronayres35 aaronayres35 deleted the fix/1543-hidden-error-msg-parts branch March 24, 2021 13:21
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.

Hidden error message parts in Qt
3 participants