Example #1
0
 def testHideWidget(self):
     """Check that the test widget is hidden by default"""
     testerPlugin = TesterPlugin(self.IFACE_Mock)
     testerPlugin.widget = mock.Mock(spec=QWidget)
     self.assertEqual(len(testerPlugin.widget.mock_calls), 0)
     testerPlugin.hideWidget()
     self.assertEqual(len(testerPlugin.widget.mock_calls), 1)
     self.assertEqual('call.hide()',
                      str(testerPlugin.widget.mock_calls[-1]))
Example #2
0
 def testHideWidget(self):
     """check if the widget is hided."""
     # precondition
     testerPlugin = TesterPlugin(self.IFACE_Mock)
     testerPlugin.widget = mock.Mock(spec=QtGui.QWidget)
     self.assertEqual(len(testerPlugin.widget.mock_calls), 0)
     # do test
     testerPlugin.hideWidget()
     self.assertEqual(len(testerPlugin.widget.mock_calls), 1)
     self.assertEqual('call.hide()',
                      str(testerPlugin.widget.mock_calls[-1]))
 def testHideWidget(self):
     """check if the widget is hided."""
     # precondition
     testerPlugin = TesterPlugin(self.IFACE_Mock)
     testerPlugin.widget = mock.Mock(spec=QWidget)
     self.assertEqual(len(testerPlugin.widget.mock_calls), 0)
     # do test
     testerPlugin.hideWidget()
     self.assertEqual(len(testerPlugin.widget.mock_calls), 1)
     self.assertEqual('call.hide()',
                      str(testerPlugin.widget.mock_calls[-1]))
Example #4
0
 def testInitGui(self):
     """Check that the plugin create the relative action and register
     self.test linked to the action."""
     # preconditions
     testerPlugin = TesterPlugin(self.IFACE_Mock)
     self.assertNotIn('action', testerPlugin.__dict__)
     # do test
     testerPlugin.iface.reset_mock
     testerPlugin.initGui()
     self.assertIsNotNone(testerPlugin.action)
     self.assertTrue(isinstance(testerPlugin.action, QtGui.QAction))
     self.assertTrue(testerPlugin.action.receivers(
                     QtCore.SIGNAL('triggered()')) == 1)
     self.assertIn("call.addPluginToMenu(u'Tester'",
                   str(testerPlugin.iface.mock_calls[-1]))
Example #5
0
    def testInitGui(self):
        """Check that the plugin UI initialised correctly"""
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        self.assertNotIn('action', testerPlugin.__dict__)

        testerPlugin.iface.reset_mock()
        testerPlugin.initGui()
        self.assertIsNotNone(testerPlugin.action)
        self.assertTrue(isinstance(testerPlugin.action, QAction))
        self.assertEqual(
            testerPlugin.action.receivers(testerPlugin.action.triggered), 1)
        # number of calls to addPluginToMenu should be equal to the number of actions in the plugin menu
        self.assertEqual(
            sum(
                map(lambda x: 'addPluginToMenu' in x,
                    testerPlugin.iface.mock_calls)), 3)
Example #6
0
 def setUpClass(cls):
     """Test setUp method."""
     utils.setUpEnv()
     # create qgis application stub
     # do not need to call exitQgis()
     cls.QGIS_APP, cls.CANVAS, cls.IFACE, cls.PARENT = get_qgis_app()
     # create the instance to test
     cls.testerPlugin = TesterPlugin(cls.IFACE)
Example #7
0
    def testInit(self):
        """Check that the plugin is loaded correctly"""
        self.IFACE_Mock.reset_mock()
        self.testerPlugin = TesterPlugin(self.IFACE_Mock)
        self.assertEqual(len(self.IFACE_Mock.mock_calls), 1)
        stringToFind = 'call.initializationCompleted.connect(<bound method TesterPlugin.hideWidget of <qgistester.plugin.TesterPlugin'
        self.assertIn(stringToFind, str(self.IFACE_Mock.mock_calls[-1]))

        self.assertEqual(self.IFACE_Mock, self.testerPlugin.iface)
        self.assertIsNone(self.testerPlugin.widget)
Example #8
0
    def testInit(self):
        """check if plugin is loaded and present in qgis loaded plugins."""
        # create the instance to test
        self.IFACE_Mock.reset_mock()
        self.testerPlugin = TesterPlugin(self.IFACE_Mock)
        self.assertEqual(len(self.IFACE_Mock.mock_calls), 1)
        stringToFind = 'call.initializationCompleted.connect(<bound method TesterPlugin.hideWidget of <qgistester.plugin.TesterPlugin'
        self.assertIn(stringToFind, str(self.IFACE_Mock.mock_calls[-1]))

        self.assertEqual(self.IFACE_Mock, self.testerPlugin.iface)
        self.assertEqual(self.testerPlugin.widget, None)
Example #9
0
    def testUnload(self):
        """Check that the plugin unloaded correctly"""
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        action = QAction('Start testing', self.IFACE_Mock.mainWindow())
        actionHelp = QAction('Help', self.IFACE_Mock.mainWindow())
        actionAbout = QAction('About…', self.IFACE_Mock.mainWindow())
        testerPlugin.action = action
        testerPlugin.actionHelp = actionHelp
        testerPlugin.actionAbout = actionAbout
        testerPlugin.widget = mock.MagicMock(QWidget)

        self.IFACE_Mock.reset_mock()
        testerPlugin.unload()
        self.assertEqual(len(self.IFACE_Mock.mock_calls), 3)
        self.assertNotIn('widget', testerPlugin.__dict__)
    def testInitGui(self):
        """Check that the plugin create the relative action and register
        self.test linked to the action."""
        # preconditions
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        self.assertNotIn('action', testerPlugin.__dict__)
        # do test
        testerPlugin.iface.reset_mock
        testerPlugin.initGui()
        self.assertIsNotNone(testerPlugin.action)
        self.assertTrue(isinstance(testerPlugin.action, QAction))
        if isPyQt4:
            self.assertTrue(testerPlugin.action.receivers(
                            SIGNAL('triggered()')) == 1)
        else:
            self.assertTrue(testerPlugin.action.receivers(
                            testerPlugin.action.triggered) == 1)

        if isPyQt4:
            self.assertIn("call.addPluginToMenu(u'Tester'",
                          str(testerPlugin.iface.mock_calls[-1]))
        else:
            self.assertIn("call.addPluginToMenu('Tester'",
                          str(testerPlugin.iface.mock_calls[-1]))
    def testUnload(self):
        """check if plugin unload is correctly executed. That means, menu
        remove is called and deleted relative QAction."""
        # preconditions
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        action = QAction("Start testing", self.IFACE_Mock.mainWindow())
        testerPlugin.action = action
        # do test 1) widget is None
        self.IFACE_Mock.reset_mock()
        testerPlugin.unload()
        if isPyQt4:
            self.assertIn("call.removePluginMenu(u'Tester'",
                          str(self.IFACE_Mock.mock_calls[-1]))
        else:
            self.assertIn("call.removePluginMenu('Tester'",
                          str(self.IFACE_Mock.mock_calls[-1]))

        self.assertNotIn('action', testerPlugin.__dict__)
        self.assertIn('widget', testerPlugin.__dict__)

        # preconditions
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        action = QAction("Start testing", self.IFACE_Mock.mainWindow())
        testerPlugin.action = action
        # do test 2) widget is available
        self.IFACE_Mock.reset_mock()
        testerPlugin.widget = mock.MagicMock(QWidget)
        testerPlugin.unload()
        if isPyQt4:
            self.assertIn("call.removePluginMenu(u'Tester'",
                          str(self.IFACE_Mock.mock_calls[0]))
        else:
            self.assertIn("call.removePluginMenu('Tester'",
                          str(self.IFACE_Mock.mock_calls[0]))

        self.assertNotIn('action', testerPlugin.__dict__)
        self.assertNotIn('widget', testerPlugin.__dict__)
Example #12
0
def classFactory(iface):
    from qgistester.plugin import TesterPlugin
    return TesterPlugin(iface)
Example #13
0
    def testUnload(self):
        """check if plugin unload is correctly executed. That means, menu
        remove is called and deleted relative QAction."""
        # preconditions
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        action = QtGui.QAction("Start testing", self.IFACE_Mock.mainWindow())
        testerPlugin.action = action
        # do test 1) widget is None
        self.IFACE_Mock.reset_mock()
        testerPlugin.unload()
        self.assertIn("call.removePluginMenu(u'Tester'",
                      str(self.IFACE_Mock.mock_calls[-1]))
        self.assertNotIn('action', testerPlugin.__dict__)
        self.assertIn('widget', testerPlugin.__dict__)

        # preconditions
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        action = QtGui.QAction("Start testing", self.IFACE_Mock.mainWindow())
        testerPlugin.action = action
        # do test 2) widget is available
        self.IFACE_Mock.reset_mock()
        testerPlugin.widget = mock.MagicMock(QtGui.QWidget)
        testerPlugin.unload()
        self.assertIn("call.removePluginMenu(u'Tester'",
                      str(self.IFACE_Mock.mock_calls[0]))
        self.assertNotIn('action', testerPlugin.__dict__)
        self.assertNotIn('widget', testerPlugin.__dict__)
Example #14
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=QtGui.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=QtGui.QMessageBox)
        with mock.patch('PyQt4.QtGui.QMessageBox', qmessageboxMock):
            testerPlugin.test()
        self.assertIn("call.warning", str(qmessageboxMock.mock_calls[-1]))

        # 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
        dlgMock.tests = 'some tests'
        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.show(),
                    call.setTests('some tests'), call.startTesting()]
        self.assertEqual(dlgMock.mock_calls, expected)
    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)
Example #16
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)