Пример #1
0
    def test_begin_move_rows(self):
        srcparent = object()
        srcindex1 = object()
        srcindex2 = object()
        destparent = object()
        destindex = object()

        self.adaptor.begin_move_rows(srcparent, srcindex1, srcindex2,
                                     destparent, destindex)

        calls = list(self.base.mock_calls)
        self.assertSequenceEqual(calls, [
            unittest.mock.call.model.beginMoveRows(Qt.QModelIndex(),
                                                   srcindex1, srcindex2,
                                                   Qt.QModelIndex(), destindex)
        ])
Пример #2
0
    def test_begin_remove_rows(self):
        null = object()
        index1 = object()
        index2 = object()

        self.adaptor.begin_remove_rows(null, index1, index2)

        calls = list(self.base.mock_calls)
        self.assertSequenceEqual(calls, [
            unittest.mock.call.model.beginRemoveRows(Qt.QModelIndex(), index1,
                                                     index2)
        ])
Пример #3
0
    def test_rowsAboutToBeRemoved_is_handled(self):
        base = unittest.mock.Mock()

        with contextlib.ExitStack() as stack:
            stack.enter_context(
                unittest.mock.patch.object(self.model,
                                           "beginRemoveRows",
                                           new=base.beginRemoveRows))

            stack.enter_context(
                unittest.mock.patch.object(self.model,
                                           "endRemoveRows",
                                           new=base.endRemoveRows))

            self.model2.rowsAboutToBeRemoved(Qt.QModelIndex(), 0, 2)
            self.model2.rowsRemoved()

        self.assertSequenceEqual(base.mock_calls, [
            unittest.mock.call.beginRemoveRows(Qt.QModelIndex(), 2, 4),
            unittest.mock.call.endRemoveRows()
        ])
        self.assertEqual(3, self.model.rowCount())
Пример #4
0
    def test_rowsAboutToBeInserted_is_handled(self):
        base = unittest.mock.Mock()

        with contextlib.ExitStack() as stack:
            stack.enter_context(
                unittest.mock.patch.object(self.model,
                                           "beginInsertRows",
                                           new=base.beginInsertRows))

            stack.enter_context(
                unittest.mock.patch.object(self.model,
                                           "endInsertRows",
                                           new=base.endInsertRows))

            self.model2.rowsAboutToBeInserted(Qt.QModelIndex(), 1, 3)
            self.model2.rowCount.return_value = 6
            self.model2.rowsInserted()

        self.assertSequenceEqual(base.mock_calls, [
            unittest.mock.call.beginInsertRows(Qt.QModelIndex(), 3, 5),
            unittest.mock.call.endInsertRows()
        ])
        self.assertEqual(9, self.model.rowCount())
Пример #5
0
 def setUp(self):
     self.logger = unittest.mock.Mock(spec=logging.Logger)
     self.profile = Qt.QWebEngineProfile()
     self.account_jid = aioxmpp.JID.fromstr("*****@*****.**")
     self.conversation_jid = aioxmpp.JID.fromstr("*****@*****.**")
     self.page = conversation.MessageViewPage(
         self.profile,
         logging.getLogger(
             ".".join([__name__, type(self).__qualname__])
         ),
         self.account_jid,
         self.conversation_jid,
     )
     run_coroutine(self.page.ready_event.wait())
Пример #6
0
def main():
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument("-V",
                        "--version",
                        action="store_true",
                        default=False,
                        help="Show version information and exit.")

    args = parser.parse_args()

    if args.version:
        print_version()
        sys.exit(0)

    app = Qt.QApplication(sys.argv)

    Qt.QResource.registerResource("resources.rcc")

    icon = Qt.QIcon()
    icon.addFile(":/icons/16x16/trayicon.png")
    icon.addFile(":/icons/24x24/trayicon.png")
    icon.addFile(":/icons/32x32/trayicon.png")

    app.setApplicationName("jabbercat")
    app.setApplicationDisplayName("JabberCat")
    app.setWindowIcon(icon)
    app.setQuitOnLastWindowClosed(False)

    import jabbercat.main

    logging.basicConfig(
        level=logging.DEBUG,
        format="%(asctime)-15s %(levelname)s:%(name)s: %(message)s")
    logging.getLogger("quamash").setLevel(logging.INFO)
    logging.getLogger("aioxmpp").setLevel(logging.DEBUG)
    logging.getLogger("aioxmpp.XMLStream").setLevel(logging.DEBUG)

    locale = Qt.QLocale.system().name()
    qttr = Qt.QTranslator(parent=app)
    if not qttr.load(
            "qt_" + locale,
            Qt.QLibraryInfo.location(Qt.QLibraryInfo.TranslationsPath)):
        logging.warning("failed to load Qt translations for %s", locale)
    else:
        app.installTranslator(qttr)

    qttr = Qt.QTranslator(parent=app)
    if not qttr.load("qttranslations/jabbercat_" + locale):
        logging.warning("failed to load JabberCat translations for %s", locale)
    else:
        app.installTranslator(qttr)

    asyncio.set_event_loop(quamash.QEventLoop(app=app))
    loop = asyncio.get_event_loop()
    main = jabbercat.main.QtMain(loop)
    try:
        returncode = loop.run_until_complete(main.run())
    finally:
        loop.close()
        # try very hard to evict parts from memory
        import gc
        gc.collect()
        del main
        gc.collect()
        del app
        asyncio.set_event_loop(None)
        del loop
        gc.collect()

    sys.exit(returncode)
Пример #7
0
 def test_rowCount_returns_length_for_invalid_index(self):
     self.assertEqual(self.model.rowCount(Qt.QModelIndex()),
                      len(self.items))
Пример #8
0
def setup_package():
    global app
    app = Qt.QApplication(sys.argv[:1])
Пример #9
0
def setup_package():
    global app, loop
    app = Qt.QApplication(sys.argv[:1])
    Qt.QResource.registerResource("resources.rcc")
    loop = quamash.QEventLoop(app=app)
    asyncio.set_event_loop(loop)