コード例 #1
0
    def testTest(self):
        """Check test method"""
        """
        1) test if messageBox.warning is called
        2) open test selector widget
            2.1) cancel => do nothing
            2.2) ok =>
                2.2.1) Create TesterWidget and dock it
                2.2.2) load tests in it
                2.2.3) start running test
        """
        qwidget = mock.Mock(spec=QWidget)
        qwidget.isVisible.return_value = True
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = qwidget
        qmessageboxMock = mock.Mock(spec=QMessageBox.warning)
        with mock.patch('PyQt5.QtWidgets.QMessageBox.warning',
                        qmessageboxMock):
            testerPlugin.test()
        self.assertEqual('Tester plugin', str(qmessageboxMock.call_args[0][1]))
        self.assertEqual('A test cycle is currently being run',
                         str(qmessageboxMock.call_args[0][2]))

        # test 2.1
        dlgMock = mock.Mock()
        dlgMock.tests = None
        testselectorMock = mock.Mock(spec=qgistester.testselector.TestSelector,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        # needed to go through the first tested if condition
        testerPlugin.widget = None
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            testerPlugin.test()
        self.assertIsNone(testerPlugin.widget)

        # test 2.2 and 2.3
        self.IFACE_Mock.reset_mock
        testselectorMock.reset_mock
        dlgMock.reset_mock
        mytest = Test('some tests')
        mytest.settings = {}
        dlgMock.tests = [mytest]
        testerwidgetMock = mock.Mock(spec=qgistester.testerwidget.TesterWidget,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        # needed to go through the first tested if condition
        testerPlugin.widget = None
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            with mock.patch('qgistester.plugin.TesterWidget',
                            testerwidgetMock):
                testerPlugin.test()
        self.assertIsNotNone(testerPlugin.widget)
        self.assertIn('call.addDockWidget',
                      str(testerPlugin.iface.mock_calls[-1]))
        expected = [
            call.exec_(),
            call.exec_(),
            call.testingFinished.connect(testerPlugin.testingFinished),
            call.show(),
            call.setTests([mytest]),
            call.startTesting()
        ]
        self.assertEqual(dlgMock.mock_calls, expected)
コード例 #2
0
    def testTest(self):
        ''' check test method:
        1) test if messageBox.warning is called
        2) open test selector widget
            2.1) cancel => do nothing
            2.2) ok =>
                2.2.1) Create TesterWidget and dock it
                2.2.2) load atests in it
                2.2.3) start running test
        '''
        # test 1)
        # preconditions
        qwidget = mock.Mock(spec=QWidget)
        qwidget.isVisible.return_value = True
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = qwidget
        # do test1
        # I only test that PyQt4.QtGui.QMessageBox.warning is called in
        # the above preconditions
        qmessageboxMock = mock.Mock(spec=QMessageBox.warning)
        if isPyQt4:
            with mock.patch('PyQt4.QtGui.QMessageBox.warning', qmessageboxMock):
                testerPlugin.test()
            self.assertEqual("Tester plugin", str(qmessageboxMock.call_args[0][1]))
            self.assertEqual("A test cycle is currently being run", str(qmessageboxMock.call_args[0][2]))
        else:
            with mock.patch('PyQt5.QtWidgets.QMessageBox.warning', qmessageboxMock):
                testerPlugin.test()
            self.assertEqual("Tester plugin", str(qmessageboxMock.call_args[0][1]))
            self.assertEqual("A test cycle is currently being run", str(qmessageboxMock.call_args[0][2]))

        # test 2.1)
        # preconditions: TestSelector constructor mock return a mock simulating
        # a QDialog
        dlgMock = mock.Mock()
        dlgMock.tests = None
        testselectorMock = mock.Mock(spec=qgistester.testselector.TestSelector,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = None  # necessary to overpass first tested if
        # do test
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            testerPlugin.test()
        self.assertIsNone(testerPlugin.widget)

        # test 2.2 and 2.3
        # preconditions: TestSelector constructor mock return a mock simulating
        # a QDialog
        self.IFACE_Mock.reset_mock
        testselectorMock.reset_mock
        dlgMock.reset_mock
        mytest = Test("some tests")
        mytest.settings = {}
        dlgMock.tests = [mytest]
        testerwidgetMock = mock.Mock(spec=qgistester.testerwidget.TesterWidget,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = None  # necessary to overpass first tested if
        # do test
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            with mock.patch('qgistester.plugin.TesterWidget',
                            testerwidgetMock):
                testerPlugin.test()
        self.assertIsNotNone(testerPlugin.widget)
        self.assertIn('call.addDockWidget',
                      str(testerPlugin.iface.mock_calls[-1]))
        expected = [call.exec_(), call.exec_(), call.testingFinished.connect(testerPlugin.testingFinished),
                    call.show(), call.setTests([mytest]), call.startTesting()]
        self.assertEqual(dlgMock.mock_calls, expected)
コード例 #3
0
    def testTest(self):
        ''' check test method:
        1) test if messageBox.warning is called
        2) open test selector widget
            2.1) cancel => do nothing
            2.2) ok =>
                2.2.1) Create TesterWidget and dock it
                2.2.2) load atests in it
                2.2.3) start running test
        '''
        # test 1)
        # preconditions
        qwidget = mock.Mock(spec=QWidget)
        qwidget.isVisible.return_value = True
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = qwidget
        # do test1
        # I only test that PyQt4.QtGui.QMessageBox.warning is called in
        # the above preconditions
        qmessageboxMock = mock.Mock(spec=QMessageBox.warning)
        if isPyQt4:
            with mock.patch('PyQt4.QtGui.QMessageBox.warning', qmessageboxMock):
                testerPlugin.test()
            self.assertEqual("Tester plugin", str(qmessageboxMock.call_args[0][1]))
            self.assertEqual("A test cycle is currently being run", str(qmessageboxMock.call_args[0][2]))
        else:
            with mock.patch('PyQt5.QtWidgets.QMessageBox.warning', qmessageboxMock):
                testerPlugin.test()
            self.assertEqual("Tester plugin", str(qmessageboxMock.call_args[0][1]))
            self.assertEqual("A test cycle is currently being run", str(qmessageboxMock.call_args[0][2]))

        # test 2.1)
        # preconditions: TestSelector constructor mock return a mock simulating
        # a QDialog
        dlgMock = mock.Mock()
        dlgMock.tests = None
        testselectorMock = mock.Mock(spec=qgistester.testselector.TestSelector,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = None  # necessary to overpass first tested if
        # do test
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            testerPlugin.test()
        self.assertIsNone(testerPlugin.widget)

        # test 2.2 and 2.3
        # preconditions: TestSelector constructor mock return a mock simulating
        # a QDialog
        self.IFACE_Mock.reset_mock
        testselectorMock.reset_mock
        dlgMock.reset_mock
        mytest = Test("some tests")
        mytest.settings = {}
        dlgMock.tests = [mytest]
        testerwidgetMock = mock.Mock(spec=qgistester.testerwidget.TesterWidget,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = None  # necessary to overpass first tested if
        # do test
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            with mock.patch('qgistester.plugin.TesterWidget',
                            testerwidgetMock):
                testerPlugin.test()
        self.assertIsNotNone(testerPlugin.widget)
        self.assertIn('call.addDockWidget',
                      str(testerPlugin.iface.mock_calls[-1]))
        expected = [call.exec_(), call.exec_(), call.testingFinished.connect(testerPlugin.testingFinished),
                    call.show(), call.setTests([mytest]), call.startTesting()]
        self.assertEqual(dlgMock.mock_calls, expected)