Esempio n. 1
0
    def test_get_all_objects(self, stubs, monkeypatch):
        # pylint: disable=unused-variable
        widgets = [self.Object('Widget 1'), self.Object('Widget 2')]
        app = stubs.FakeQApplication(all_widgets=widgets)
        monkeypatch.setattr(debug, 'QApplication', app)

        root = QObject()
        o1 = self.Object('Object 1', root)
        o2 = self.Object('Object 2', o1)
        o3 = self.Object('Object 3', root)

        expected = textwrap.dedent("""
            Qt widgets - 2 objects:
                <Widget 1>
                <Widget 2>

            Qt objects - 3 objects:
                <Object 1>
                    <Object 2>
                <Object 3>

            global object registry - 0 objects:
        """).rstrip('\n')

        assert debug.get_all_objects(start_obj=root) == expected
Esempio n. 2
0
    def test_get_all_objects(self, stubs, monkeypatch):
        # pylint: disable=unused-variable
        widgets = [self.Object('Widget 1'), self.Object('Widget 2')]
        app = stubs.FakeQApplication(all_widgets=widgets)
        monkeypatch.setattr(debug, 'QApplication', app)

        root = QObject()
        o1 = self.Object('Object 1', root)
        o2 = self.Object('Object 2', o1)
        o3 = self.Object('Object 3', root)

        expected = textwrap.dedent("""
            Qt widgets - 2 objects:
                <Widget 1>
                <Widget 2>

            Qt objects - 3 objects:
                <Object 1>
                    <Object 2>
                <Object 3>

            global object registry - 0 objects:
        """).rstrip('\n')

        assert debug.get_all_objects(start_obj=root) == expected
Esempio n. 3
0
 def report(self):
     """Report a bug in qutebrowser."""
     pages = self._recover_pages()
     cmd_history = objreg.get("command-history")[-5:]
     objects = debug.get_all_objects()
     self._crash_dialog = crashdialog.ReportDialog(pages, cmd_history, objects)
     self._crash_dialog.show()
Esempio n. 4
0
 def report(self):
     """Report a bug in qutebrowser."""
     pages = self._recover_pages()
     cmd_history = objreg.get('command-history')[-5:]
     objects = debug.get_all_objects()
     self._crash_dialog = crashdialog.ReportDialog(pages, cmd_history,
                                                   objects)
     self._crash_dialog.show()
Esempio n. 5
0
    def report(self, info=None, contact=None):
        """Report a bug in qutebrowser.

        Args:
            info: Information about the bug report. If given, no report dialog
                  shows up.
            contact: Contact information for the report.
        """
        pages = self._recover_pages()
        cmd_history = objreg.get('command-history')[-5:]
        all_objects = debug.get_all_objects()

        self._crash_dialog = crashdialog.ReportDialog(pages, cmd_history,
                                                      all_objects)

        if info is None:
            self._crash_dialog.show()
        else:
            self._crash_dialog.report(info=info, contact=contact)
Esempio n. 6
0
    def _get_exception_info(self):
        """Get info needed for the exception hook/dialog.

        Return:
            An ExceptionInfo namedtuple.
        """
        try:
            pages = self._recover_pages(forgiving=True)
        except Exception:
            log.destroy.exception("Error while recovering pages")
            pages = []

        try:
            cmd_history = objreg.get('command-history')[-5:]
        except Exception:
            log.destroy.exception("Error while getting history: {}")
            cmd_history = []

        try:
            objects = debug.get_all_objects()
        except Exception:
            log.destroy.exception("Error while getting objects")
            objects = ""
        return ExceptionInfo(pages, cmd_history, objects)
Esempio n. 7
0
    def _get_exception_info(self):
        """Get info needed for the exception hook/dialog.

        Return:
            An ExceptionInfo object.
        """
        try:
            pages = self._recover_pages(forgiving=True)
        except Exception as e:
            log.destroy.exception("Error while recovering pages: {}".format(e))
            pages = []

        try:
            cmd_history = objreg.get('command-history')[-5:]
        except Exception as e:
            log.destroy.exception("Error while getting history: {}".format(e))
            cmd_history = []

        try:
            objects = debug.get_all_objects()
        except Exception:
            log.destroy.exception("Error while getting objects")
            objects = ""
        return ExceptionInfo(pages, cmd_history, objects)
Esempio n. 8
0
 def test_get_all_objects_qapp(self):
     objects = debug.get_all_objects()
     event_dispatcher = '<PyQt5.QtCore.QAbstractEventDispatcher object at'
     session_manager = '<PyQt5.QtGui.QSessionManager object at'
     assert event_dispatcher in objects or session_manager in objects
Esempio n. 9
0
def debug_all_objects():
    """Print a list of  all objects to the debug log."""
    s = debug.get_all_objects()
    log.misc.debug(s)
Esempio n. 10
0
def debug_all_objects():
    """Print a list of  all objects to the debug log."""
    s = debug.get_all_objects()
    log.misc.debug(s)
Esempio n. 11
0
 def test_get_all_objects_qapp(self):
     objects = debug.get_all_objects()
     event_dispatcher = '<PyQt5.QtCore.QAbstractEventDispatcher object at'
     session_manager = '<PyQt5.QtGui.QSessionManager object at'
     assert event_dispatcher in objects or session_manager in objects
Esempio n. 12
0
 def test_get_all_objects_qapp(self, qapp, monkeypatch):
     monkeypatch.setattr(objects, 'qapp', qapp)
     objs = debug.get_all_objects()
     event_dispatcher = '<PyQt5.QtCore.QAbstractEventDispatcher object at'
     session_manager = '<PyQt5.QtGui.QSessionManager object at'
     assert event_dispatcher in objs or session_manager in objs
Esempio n. 13
0
    def exception_hook(self, exctype, excvalue, tb):  # noqa
        """Handle uncaught python exceptions.

        It'll try very hard to write all open tabs to a file, and then exit
        gracefully.
        """
        exc = (exctype, excvalue, tb)
        qapp = QApplication.instance()

        if not self._quitter.quit_status['crash']:
            log.misc.error("ARGH, there was an exception while the crash "
                           "dialog is already shown:", exc_info=exc)
            return

        log.misc.error("Uncaught exception", exc_info=exc)

        is_ignored_exception = (exctype is bdb.BdbQuit or
                                not issubclass(exctype, Exception))

        if self._args.pdb_postmortem:
            pdb.post_mortem(tb)

        if (is_ignored_exception or self._args.no_crash_dialog or
                self._args.pdb_postmortem):
            # pdb exit, KeyboardInterrupt, ...
            status = 0 if is_ignored_exception else 2
            try:
                qapp.shutdown(status)
                return
            except Exception:
                log.init.exception("Error while shutting down")
                qapp.quit()
                return

        self._quitter.quit_status['crash'] = False

        try:
            pages = self._recover_pages(forgiving=True)
        except Exception:
            log.destroy.exception("Error while recovering pages")
            pages = []

        try:
            cmd_history = objreg.get('command-history')[-5:]
        except Exception:
            log.destroy.exception("Error while getting history: {}")
            cmd_history = []

        try:
            objects = debug.get_all_objects()
        except Exception:
            log.destroy.exception("Error while getting objects")
            objects = ""

        try:
            objreg.get('ipc-server').ignored = True
        except Exception:
            log.destroy.exception("Error while ignoring ipc")

        try:
            self._app.lastWindowClosed.disconnect(
                self._quitter.on_last_window_closed)
        except TypeError:
            log.destroy.exception("Error while preventing shutdown")
        self._app.closeAllWindows()
        self._crash_dialog = crashdialog.ExceptionCrashDialog(
            self._args.debug, pages, cmd_history, exc, objects)
        ret = self._crash_dialog.exec_()
        if ret == QDialog.Accepted:  # restore
            self._quitter.restart(pages)

        # We might risk a segfault here, but that's better than continuing to
        # run in some undefined state, so we only do the most needed shutdown
        # here.
        qInstallMessageHandler(None)
        self.destroy_crashlogfile()
        sys.exit(1)