def test_notification_display(mock_show, severity, monkeypatch): """Test that NapariQtNotification can present a Notification event. NOTE: in napari.utils._tests.test_notification_manager, we already test that the notification manager successfully overrides sys.excepthook, and warnings.showwarning... and that it emits an event which is an instance of napari.utils.notifications.Notification. in `get_app()`, we connect `notification_manager.notification_ready` to `NapariQtNotification.show_notification`, so all we have to test here is that show_notification is capable of receiving various event types. (we don't need to test that ) """ from napari.utils.settings import SETTINGS monkeypatch.delenv('NAPARI_CATCH_ERRORS', raising=False) monkeypatch.setattr(SETTINGS.application, 'gui_notification_level', 'info') notif = Notification('hi', severity, actions=[('click', lambda x: None)]) NapariQtNotification.show_notification(notif) if NotificationSeverity(severity) >= NotificationSeverity.INFO: mock_show.assert_called_once() else: mock_show.assert_not_called() dialog = NapariQtNotification.from_notification(notif) assert not dialog.property('expanded') dialog.toggle_expansion() assert dialog.property('expanded') dialog.toggle_expansion() assert not dialog.property('expanded') dialog.close()
def test_notification_error(mock_show, monkeypatch): from napari.utils.settings import SETTINGS monkeypatch.delenv('NAPARI_CATCH_ERRORS', raising=False) monkeypatch.setattr(SETTINGS.application, 'gui_notification_level', 'info') try: raise ValueError('error!') except ValueError as e: notif = ErrorNotification(e) dialog = NapariQtNotification.from_notification(notif) bttn = dialog.row2_widget.findChild(QPushButton) assert bttn.text() == 'View Traceback' mock_show.assert_not_called() bttn.click() mock_show.assert_called_once()
def test_notification_error(mock_show, monkeypatch, clean_current): from napari.settings import get_settings settings = get_settings() monkeypatch.delenv('NAPARI_CATCH_ERRORS', raising=False) monkeypatch.setattr( settings.application, 'gui_notification_level', NotificationSeverity.INFO, ) try: raise ValueError('error!') except ValueError as e: notif = ErrorNotification(e) dialog = NapariQtNotification.from_notification(notif) bttn = dialog.row2_widget.findChild(QPushButton) assert bttn.text() == 'View Traceback' mock_show.assert_not_called() bttn.click() mock_show.assert_called_once()
def test_notification_display(mock_show, severity): """Test that NapariQtNotification can present a Notification event. NOTE: in napari.utils._tests.test_notification_manager, we already test that the notification manager successfully overrides sys.excepthook, and warnings.showwarning... and that it emits an event which is an instance of napari.utils.notifications.Notification. in `get_app()`, we connect `notification_manager.notification_ready` to `NapariQtNotification.show_notification`, so all we have to test here is that show_notification is capable of receiving various event types. (we don't need to test that ) """ notif = Notification('hi', severity, actions=[('click', lambda x: None)]) NapariQtNotification.show_notification(notif) mock_show.assert_called_once() dialog = NapariQtNotification.from_notification(notif) assert not dialog.property('expanded') dialog.toggle_expansion() assert dialog.property('expanded') dialog.toggle_expansion() assert not dialog.property('expanded') dialog.close()