コード例 #1
0
    def test_constructor(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = ConnectDlg()
        self.assertEqual(form.device, '')
        self.assertEqual(form.host, '')
        self.assertEqual(form.port, None)

        self.assertEqual(form.result(), 0)
コード例 #2
0
    def test_constructor_createGUI_updateForm(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = ConnectDlg()

        device = "my/device/1"
        host = "myhost.de"
        port = "10005"

        form.device = device
        form.host = host
        form.port = port

        self.assertEqual(form.device, device)
        self.assertEqual(form.host, host)
        self.assertEqual(form.port, port)

        form.show()
        form.createGUI()
        self.assertTrue(not form.ui.deviceLineEdit.text().isEmpty())
        self.assertTrue(not form.ui.hostLineEdit.text().isEmpty())
        self.assertTrue(not form.ui.portLineEdit.text().isEmpty())

        self.assertTrue(form.ui.connectPushButton.isEnabled())
        self.assertTrue(form.ui.cancelPushButton.isEnabled())

        self.assertEqual(form.device, device)
        self.assertEqual(form.host, host)
        self.assertEqual(form.port, port)

        self.assertTrue(not form.ui.deviceLineEdit.text().isEmpty())
        self.assertTrue(not form.ui.hostLineEdit.text().isEmpty())
        self.assertTrue(not form.ui.portLineEdit.text().isEmpty())
        self.assertTrue(form.ui.connectPushButton.isEnabled())
        self.assertTrue(form.ui.cancelPushButton.isEnabled())

        QTest.mouseClick(form.ui.connectPushButton, Qt.LeftButton)

        self.assertEqual(form.device, device)
        self.assertEqual(form.host, host)
        self.assertEqual(form.port, int(port))

        self.assertEqual(form.result(), 1)
コード例 #3
0
    def test_constructor_createGUI_noport(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)
        form = ConnectDlg()
        self.assertEqual(form.device, '')
        self.assertEqual(form.host, '')
        self.assertEqual(form.port, None)

        form.show()
        form.createGUI()
        self.assertTrue(form.ui.deviceLineEdit.text().isEmpty())
        self.assertTrue(form.ui.hostLineEdit.text().isEmpty())
        self.assertTrue(form.ui.portLineEdit.text().isEmpty())
        self.assertTrue(not form.ui.connectPushButton.isEnabled())
        self.assertTrue(form.ui.cancelPushButton.isEnabled())

        device = "my device"
        host = "hasso.de"
        port = ""
        QTest.keyClicks(form.ui.deviceLineEdit, device)
        self.assertEqual(form.ui.deviceLineEdit.text(), device)

        self.assertTrue(form.ui.connectPushButton.isEnabled())
        self.assertTrue(form.ui.cancelPushButton.isEnabled())

        QTest.keyClicks(form.ui.hostLineEdit, host)
        self.assertEqual(form.ui.hostLineEdit.text(), host)
        QTest.keyClicks(form.ui.portLineEdit, port)
        self.assertEqual(form.ui.portLineEdit.text(), port)

        self.assertTrue(not form.ui.deviceLineEdit.text().isEmpty())
        self.assertTrue(not form.ui.hostLineEdit.text().isEmpty())
        self.assertTrue(form.ui.portLineEdit.text().isEmpty())
        self.assertTrue(form.ui.connectPushButton.isEnabled())
        self.assertTrue(form.ui.cancelPushButton.isEnabled())

        QTimer.singleShot(0, self.checkMessageBox)
        QTest.mouseClick(form.ui.connectPushButton, Qt.LeftButton)
        self.assertEqual(self.text, 'Please define the port')
        #        self.assertEqual(self.title, 'Empty port')

        #        print form.portLineEdit.hasFocus()
        #        self.assertTrue(form.portLineEdit.hasFocus())

        self.assertEqual(form.device, device.strip())
        self.assertEqual(form.host, host.strip())
        self.assertEqual(form.port, None)

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