Exemplo n.º 1
0
    def test_reset_nozero(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.ui = Ui_NodeDlg()
        form.ui.applyPushButton = QPushButton(form)
        form.show()
        self.assertEqual(form.connectExternalActions(), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])

        vw = TestView()
        ri = vw.model().rootIndex
        di = vw.model().index(0, 0, ri)
        n = self.__rnd.randint(0, vw.nkids - 1)
        cn = self.__rnd.randint(1, 2)
        ki = vw.model().index(n, cn, di)

        vw.myindex = ki
        vw.model().connect(
            vw.model(),
            SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"),
            vw.dataChanged)
        form.view = vw

        form.reset()
        self.assertEqual(vw.sindex.row(), vw.currentIndex().row())
        self.assertEqual(vw.sindex.column(), 0)
        self.assertEqual(vw.sindex.parent(), vw.currentIndex().parent())
        self.assertEqual(vw.eindex, vw.sindex)

        self.assertEqual(form.result(), 0)
Exemplo n.º 2
0
    def test_constructor(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.show()
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])
        self.assertEqual(form.ui, None)
        self.assertEqual(form.externalApply, None)
        self.assertEqual(form.externalDSLink, None)
        self.assertEqual(form.dsLabel, 'datasources')

        self.assertEqual(form.result(), 0)
Exemplo n.º 3
0
    def test_connect_actions_with_action_link_and_apply_button(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.ui = Ui_NodeDlg()
        form.ui.applyPushButton = QPushButton(form)
        form.ui.linkDSPushButton = QPushButton(form)
        form.show()
        self.assertEqual(
            form.connectExternalActions(self.myAction,
                                        externalDSLink=self.myAction2), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])
        self.assertTrue(isinstance(form.ui, Ui_NodeDlg))
        self.assertEqual(form.externalApply, self.myAction)
        self.assertEqual(form.externalDSLink, self.myAction2)
        self.performed = False
        self.performed2 = False

        QTest.mouseClick(form.ui.applyPushButton, Qt.LeftButton)
        self.assertEqual(self.performed, True)
        self.assertEqual(self.performed2, False)
        QTest.mouseClick(form.ui.linkDSPushButton, Qt.LeftButton)
        self.assertEqual(self.performed, True)
        self.assertEqual(self.performed2, True)

        self.assertEqual(form.result(), 0)
Exemplo n.º 4
0
    def test_replaceText_noview(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.ui = Ui_NodeDlg()
        form.ui.applyPushButton = QPushButton(form)
        form.show()
        self.assertEqual(form.connectExternalActions(), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])

        vw = TestView()

        ri = vw.model().rootIndex
        di = vw.model().index(0, 0, ri)
        n = self.__rnd.randint(0, vw.nkids - 1)
        ki = vw.model().index(n, 0, di)

        vw.myindex = ki

        vw.model().connect(
            vw.model(),
            SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"),
            vw.dataChanged)
        #        form.view = vw
        form.view = None

        form.node = vw.qdn

        ks = di.internalPointer()
        self.assertEqual(ks.node.childNodes().count(), vw.nkids)
        form.replaceText(di)

        ks = di.internalPointer()
        self.assertEqual(ks.node.childNodes().count(), vw.nkids)
Exemplo n.º 5
0
    def test_connect_actions_with_action(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.show()
        self.assertEqual(form.connectExternalActions(self.myAction), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])
        self.assertEqual(form.ui, None)
        self.assertEqual(form.externalApply, None)

        self.assertEqual(form.result(), 0)
Exemplo n.º 6
0
    def test_connect_actions_with_button(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.ui = Ui_NodeDlg()
        form.ui.applyPushButton = QPushButton(form)
        form.ui.linkDSPushButton = QPushButton(form)
        form.show()
        self.assertEqual(form.connectExternalActions(), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])
        self.assertTrue(isinstance(form.ui, Ui_NodeDlg))
        self.assertEqual(form.externalApply, None)
        self.assertEqual(form.externalDSLink, None)

        self.assertEqual(form.result(), 0)
Exemplo n.º 7
0
    def test_appendElement(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.ui = Ui_NodeDlg()
        form.ui.applyPushButton = QPushButton(form)
        form.show()
        self.assertEqual(form.connectExternalActions(), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])

        vw = TestView()

        ri = vw.model().rootIndex
        di = vw.model().index(0, 0, ri)
        n = self.__rnd.randint(0, vw.nkids - 1)
        ki = vw.model().index(n, 0, di)

        vw.myindex = ki

        inkd = vw.doc.createElement("insertedkid")

        vw.model().connect(
            vw.model(),
            SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"),
            vw.dataChanged)
        form.view = vw

        form.node = vw.qdn

        self.assertTrue(not form.appendElement(inkd, QModelIndex()))

        self.assertTrue(vw.model().rowCount(), vw.nkids)
        self.assertTrue(form.appendElement(inkd, di))

        self.assertTrue(vw.model().rowCount(), vw.nkids + 1)

        ci = di.internalPointer()

        for k in range(vw.nkids):
            ks = ci.child(k)
            self.assertTrue(isinstance(ks, ComponentItem))
            self.assertTrue(isinstance(ks.parent, ComponentItem))
            self.assertEqual(ks.childNumber(), k)
            self.assertEqual(ks.node, vw.kds[k])
            self.assertEqual(ks.parent.node, vw.qdn)
            self.assertEqual(ks.node.nodeName(), "kid%s" % k)
            self.assertEqual(ks.parent, ci)
            self.assertTrue(isinstance(ks.child(0), ComponentItem))
            self.assertTrue(isinstance(ks.child(0).parent, ComponentItem))
            self.assertEqual(ks.child(0).childNumber(), 0)
            self.assertEqual(ks.child(0).node, vw.tkds[k])
            self.assertEqual(ks.child(0).parent.node, ks.node)
            self.assertEqual(ks.child(0).node.nodeName(), "#text")
            self.assertEqual(
                ks.child(0).node.toText().data(), '\nText\n %s\n' % k)
            self.assertEqual(ks.child(0).parent, ks)

        k = vw.nkids
        ks = ci.child(k)

        self.assertTrue(isinstance(ks, ComponentItem))
        self.assertTrue(isinstance(ks.parent, ComponentItem))
        self.assertEqual(ks.childNumber(), k)
        self.assertEqual(ks.node, inkd)
        self.assertEqual(ks.parent.node, vw.qdn)
        self.assertEqual(ks.node.nodeName(), "insertedkid")
        self.assertEqual(ks.parent, ci)

        vw.testModel = None

        inkd2 = vw.doc.createElement("insertedkid")
        self.assertTrue(not form.appendElement(inkd2, di))
        ci = di.internalPointer()

        form.view = None

        self.assertTrue(not form.appendElement(ki.internalPointer().node, di))

        self.assertEqual(form.result(), 0)
Exemplo n.º 8
0
    def test_removeElement(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.ui = Ui_NodeDlg()
        form.ui.applyPushButton = QPushButton(form)
        form.show()
        self.assertEqual(form.connectExternalActions(), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])

        vw = TestView()

        ri = vw.model().rootIndex
        di = vw.model().index(0, 0, ri)
        n = self.__rnd.randint(0, vw.nkids - 1)
        ki = vw.model().index(n, 0, di)

        vw.myindex = ki

        vw.model().connect(
            vw.model(),
            SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"),
            vw.dataChanged)
        form.view = vw

        dts = TestTools()
        self.dts = dts
        form.node = vw.qdn

        ci = di.internalPointer()

        for k in range(vw.nkids):
            ks = ci.child(k)
            self.assertTrue(isinstance(ks, ComponentItem))
            self.assertTrue(isinstance(ks.parent, ComponentItem))
            self.assertEqual(ks.childNumber(), k)
            self.assertEqual(ks.node, vw.kds[k])
            self.assertEqual(ks.parent.node, vw.qdn)
            self.assertEqual(ks.node.nodeName(), "kid%s" % k)
            self.assertEqual(ks.parent, ci)
            self.assertTrue(isinstance(ks.child(0), ComponentItem))
            self.assertTrue(isinstance(ks.child(0).parent, ComponentItem))
            self.assertEqual(ks.child(0).childNumber(), 0)
            self.assertEqual(ks.child(0).node, vw.tkds[k])
            self.assertEqual(ks.child(0).parent.node, ks.node)
            self.assertEqual(ks.child(0).node.nodeName(), "#text")
            self.assertEqual(
                ks.child(0).node.toText().data(), '\nText\n %s\n' % k)
            self.assertEqual(ks.child(0).parent, ks)

        form.removeElement(ki.internalPointer().node, di)

        for kk in range(vw.nkids):
            if kk < n or kk > n:
                k = kk if kk < n else kk - 1
                ks = ci.child(k)
                self.assertTrue(isinstance(ks, ComponentItem))
                self.assertTrue(isinstance(ks.parent, ComponentItem))
                self.assertEqual(ks.childNumber(), k)
                self.assertEqual(ks.node.nodeName(), "kid%s" % kk)
                self.assertEqual(ks.node, vw.kds[kk])
                self.assertEqual(ks.parent.node, vw.qdn)
                self.assertEqual(ks.parent, ci)
                self.assertTrue(isinstance(ks.child(0), ComponentItem))
                self.assertTrue(isinstance(ks.child(0).parent, ComponentItem))
                self.assertEqual(ks.child(0).childNumber(), 0)
                self.assertEqual(ks.child(0).node, vw.tkds[kk])
                self.assertEqual(ks.child(0).parent.node, ks.node)
                self.assertEqual(ks.child(0).node.nodeName(), "#text")
                self.assertEqual(
                    ks.child(0).node.toText().data(), '\nText\n %s\n' % kk)
                self.assertEqual(ks.child(0).parent, ks)
Exemplo n.º 9
0
    def test_replaceText(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = NodeDlg()
        form.ui = Ui_NodeDlg()
        form.ui.applyPushButton = QPushButton(form)
        form.show()
        self.assertEqual(form.connectExternalActions(), None)
        self.assertEqual(form.node, None)
        self.assertEqual(form.root, None)
        self.assertEqual(form.view, None)
        self.assertEqual(form.subItems, [])

        vw = TestView()

        ri = vw.model().rootIndex
        di = vw.model().index(0, 0, ri)
        n = self.__rnd.randint(0, vw.nkids - 1)
        ki = vw.model().index(n, 0, di)

        vw.myindex = ki

        vw.model().connect(
            vw.model(),
            SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"),
            vw.dataChanged)
        form.view = vw

        form.node = vw.qdn

        root = vw.model().rootIndex.internalPointer().node
        form.replaceText(di)

        ks = di.internalPointer()
        self.assertEqual(ks.node.childNodes().count(), vw.nkids)

        self.assertTrue(isinstance(ks, ComponentItem))
        self.assertTrue(isinstance(ks.parent, ComponentItem))
        self.assertEqual(ks.node, vw.qdn)
        self.assertEqual(ks.parent.node, vw.doc)
        self.assertEqual(ks.parent, ri.internalPointer())
        self.assertEqual(ks.parent.node, ri.internalPointer().node)
        self.assertEqual(ks.node.childNodes().count(), vw.nkids)

        #        self.assertEqual(dts.stack[0],"replaceText")
        #        self.assertEqual(dts.stack[1],vw.qdn)
        #        self.assertEqual(dts.stack[2],di)
        #        self.assertEqual(dts.stack[3],vw.model())
        #        self.assertEqual(dts.stack[4],None)
        ci = di.internalPointer()

        text = "My Supper Text"
        form.replaceText(di, text)

        self.assertTrue(isinstance(ks, ComponentItem))
        self.assertTrue(isinstance(ks.parent, ComponentItem))
        self.assertEqual(ks.node, vw.qdn)
        self.assertEqual(ks.parent.node, vw.doc)
        self.assertEqual(ks.parent, ri.internalPointer())
        self.assertEqual(ks.parent.node, ri.internalPointer().node)
        self.assertEqual(ks.node.childNodes().count(), vw.nkids + 1)
        ts = ci.child(vw.nkids)
        self.assertEqual(ts.node.nodeName(), "#text")
        self.assertEqual(ts.node.toText().data(), text)
        self.assertEqual(ts.parent, ks)

        self.assertEqual(form.result(), 0)