def testInit(self): """Check if __init__ is correctly executed""" r = Report() # r.results is empty dlg = ReportDialog(r) expectedColorList = [ Qt.green, Qt.red, Qt.gray, Qt.magenta, QColor(237, 189, 129) ] self.assertEqual(dlg.resultColor, expectedColorList) self.assertEqual(dlg.resultsTree.topLevelItemCount(), 0) self.assertEqual( dlg.resultsTree.receivers(dlg.resultsTree.itemClicked), 1) self.assertEqual( dlg.resultsTree.receivers( dlg.resultsTree.customContextMenuRequested), 1) self.assertEqual(dlg.buttonBox.receivers(dlg.buttonBox.rejected), 1) r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) self.assertEqual(dlg.resultsTree.topLevelItemCount(), 1) self.assertTrue(dlg.resultsTree.topLevelItem(0).isExpanded()) self.assertEqual(dlg.resultsTree.topLevelItem(0).childCount(), 3) self.assertEqual( dlg.resultsTree.topLevelItem(0).child(0).text(0), 'Functional test') self.assertEqual( dlg.resultsTree.topLevelItem(0).child(1).text(0), 'Test that fails') self.assertEqual( dlg.resultsTree.topLevelItem(0).child(2).text(0), 'Test that passes')
def testShowPopupMenu(self): """check if a menu popup is opened if issue url is present.""" # test1 # preconditions r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget dlg.resultsTree.topLevelItem(0).child(1).setSelected( True) # select 'Test that fails' that does NOT have url # do test point = QPoint(0, 0) qmenuMock = mock.Mock(spec=QMenu) qactionMock = mock.Mock(spec=QAction) if isPyQt4: with mock.patch('PyQt4.QtGui.QMenu', qmenuMock): with mock.patch('PyQt4.QtGui.QAction', qactionMock): dlg.showPopupMenu(point) else: with mock.patch('PyQt5.QtWidgets.QMenu', qmenuMock): with mock.patch('PyQt5.QtWidgets.QAction', qactionMock): dlg.showPopupMenu(point) self.assertTrue(qmenuMock.mock_calls == []) self.assertTrue(qactionMock.mock_calls == []) # test2 # preconditions r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget dlg.resultsTree.topLevelItem(0).child(0).setSelected( True) # select 'Functional tests' that does have url # do test point = QPoint(0, 0) qmenuMock = mock.Mock(spec=QMenu) qactionMock = mock.Mock(spec=QAction) with mock.patch('qgistester.reportdialog.QMenu', qmenuMock): with mock.patch('qgistester.reportdialog.QAction', qactionMock): self.assertEqual( dlg.resultsTree.selectedItems()[0].result.test.issueUrl, 'http://www.example.com') dlg.showPopupMenu(point) self.assertIn('call()', str(qmenuMock.mock_calls[0])) self.assertIn('call().addAction', str(qmenuMock.mock_calls[1])) if isPyQt4: self.assertIn('call().exec_(PyQt4.QtCore.QPoint())', str(qmenuMock.mock_calls[2])) else: self.assertIn('call().exec_(PyQt5.QtCore.QPoint())', str(qmenuMock.mock_calls[2])) self.assertIn("call('Open issue page', None)", str(qactionMock.mock_calls[0])) self.assertIn("call().triggered.connect", str(qactionMock.mock_calls[1]))
def runNextTest(self): if self.currentTestResult: self.report.addTestResult(self.currentTestResult) if self.currentTest < len(self.tests): test = self.tests[self.currentTest] self.labelCurrentTest.setText("Current test: %s-%s" % (test.group.upper(), test.name)) self.currentTestResult = TestResult(test) self.currentTestStep = 0 self.runNextStep() else: self.setVisible(False) dlg = ReportDialog(self.report) dlg.exec_()
def testOkPressed(self): """Check that the widget is closed when OK clicked""" r = Report() dlg = ReportDialog(r) dlg.show() self.assertTrue(dlg.isVisible()) dlg.close() self.assertFalse(dlg.isVisible())
def testInit(self): """check if __init__ is correctly executed.""" # test1 # preconditions r = Report() # => r.results is empty # do test dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget expectedColorList = [Qt.green, Qt.red, Qt.gray] self.assertTrue(dlg.resultColor == expectedColorList) self.assertTrue(dlg.resultsTree.topLevelItemCount() == 0) if isPyQt4: self.assertTrue( dlg.resultsTree.receivers( SIGNAL('itemClicked(QTreeWidgetItem *, int)')) == 1) self.assertTrue( dlg.resultsTree.receivers( SIGNAL('customContextMenuRequested(const QPoint &)')) == 1) self.assertTrue(dlg.buttonBox.receivers(SIGNAL('rejected()')) == 1) else: self.assertTrue( dlg.resultsTree.receivers(dlg.resultsTree.itemClicked) == 1) self.assertTrue( dlg.resultsTree.receivers( dlg.resultsTree.customContextMenuRequested) == 1) self.assertTrue( dlg.buttonBox.receivers(dlg.buttonBox.rejected) == 1) # test2 # preconditions: populate with tests results r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) # do test dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget self.assertTrue(dlg.resultsTree.topLevelItemCount() == 1) self.assertTrue(dlg.resultsTree.topLevelItem(0).isExpanded()) self.assertTrue(dlg.resultsTree.topLevelItem(0).childCount() == 3) self.assertTrue( dlg.resultsTree.topLevelItem(0).child(0).text(0) == 'Functional test') self.assertTrue( dlg.resultsTree.topLevelItem(0).child(1).text(0) == 'Test that fails') self.assertTrue( dlg.resultsTree.topLevelItem(0).child(2).text(0) == 'Test that passes')
def testOkPressed(self): """test the widget is closed.""" # preconditions r = Report() dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget dlg.show() # do test self.assertTrue(dlg.isVisible()) dlg.close() self.assertFalse(dlg.isVisible())
def testItemClicked(self): """test the result is set to the clicked value.""" # preconditions r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget # do test1 self.assertTrue(dlg.resultText.toPlainText() == "") dlg.itemClicked() self.assertTrue(dlg.resultText.toPlainText() == "") # do test 2 currentItem = dlg.resultsTree.topLevelItem(0).child(0) dlg.resultsTree.setCurrentItem(currentItem) dlg.itemClicked() self.assertIn("Test name: -Functional test", dlg.resultText.toPlainText()) self.assertIn("Test result:Test skipped", dlg.resultText.toPlainText())
def testShowPopupMenu(self): """check if a menu popup is opened if issue url is present.""" # test1 # preconditions r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget dlg.resultsTree.topLevelItem(0).child(1).setSelected(True) # select 'Test that fails' that does NOT have url # do test point = QPoint(0, 0) qmenuMock = mock.Mock(spec=QMenu) qactionMock = mock.Mock(spec=QAction) if isPyQt4: with mock.patch("PyQt4.QtGui.QMenu", qmenuMock): with mock.patch("PyQt4.QtGui.QAction", qactionMock): dlg.showPopupMenu(point) else: with mock.patch("PyQt5.QtWidgets.QMenu", qmenuMock): with mock.patch("PyQt5.QtWidgets.QAction", qactionMock): dlg.showPopupMenu(point) self.assertTrue(qmenuMock.mock_calls == []) self.assertTrue(qactionMock.mock_calls == []) # test2 # preconditions r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget dlg.resultsTree.topLevelItem(0).child(0).setSelected(True) # select 'Functional tests' that does have url # do test point = QPoint(0, 0) qmenuMock = mock.Mock(spec=QMenu) qactionMock = mock.Mock(spec=QAction) with mock.patch("qgistester.reportdialog.QMenu", qmenuMock): with mock.patch("qgistester.reportdialog.QAction", qactionMock): self.assertEqual(dlg.resultsTree.selectedItems()[0].result.test.issueUrl, "http://www.example.com") dlg.showPopupMenu(point) self.assertIn("call()", str(qmenuMock.mock_calls[0])) self.assertIn("call().addAction", str(qmenuMock.mock_calls[1])) if isPyQt4: self.assertIn("call().exec_(PyQt4.QtCore.QPoint())", str(qmenuMock.mock_calls[2])) else: self.assertIn("call().exec_(PyQt5.QtCore.QPoint())", str(qmenuMock.mock_calls[2])) self.assertIn("call('Open issue page', None)", str(qactionMock.mock_calls[0])) self.assertIn("call().triggered.connect", str(qactionMock.mock_calls[1]))
def testShowPopupMenu(self): """Check if a context menu is opened when issue url is present""" # check with 'Test that fails' item which does NOT have an url r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) dlg.resultsTree.topLevelItem(0).child(1).setSelected(True) point = QPoint(0, 0) qmenuMock = mock.Mock(spec=QMenu) qactionMock = mock.Mock(spec=QAction) with mock.patch('PyQt5.QtWidgets.QMenu', qmenuMock): with mock.patch('PyQt5.QtWidgets.QAction', qactionMock): dlg.showPopupMenu(point) self.assertEqual(qmenuMock.mock_calls, []) self.assertEqual(qactionMock.mock_calls, []) # check with 'Functional tests' that does have an url r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) dlg.resultsTree.topLevelItem(0).child(0).setSelected(True) point = QPoint(0, 0) qmenuMock = mock.Mock(spec=QMenu) qactionMock = mock.Mock(spec=QAction) with mock.patch('qgistester.reportdialog.QMenu', qmenuMock): with mock.patch('qgistester.reportdialog.QAction', qactionMock): self.assertEqual( dlg.resultsTree.selectedItems()[0].result.test.issueUrl, 'http://www.example.com') dlg.showPopupMenu(point) self.assertIn('call()', str(qmenuMock.mock_calls[0])) self.assertIn('call().addAction', str(qmenuMock.mock_calls[1])) self.assertIn('call().exec_(PyQt5.QtCore.QPoint())', str(qmenuMock.mock_calls[2])) self.assertIn("call('Open issue page', None)", str(qactionMock.mock_calls[0])) self.assertIn("call().triggered.connect", str(qactionMock.mock_calls[1]))
def testItemClicked(self): """Test that result is set to the clicked value""" r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) self.assertEqual(dlg.resultText.toPlainText(), '') dlg.itemClicked() self.assertEqual(dlg.resultText.toPlainText(), '') currentItem = dlg.resultsTree.topLevelItem(0).child(0) dlg.resultsTree.setCurrentItem(currentItem) dlg.itemClicked() self.assertIn('Test name: -Functional test', dlg.resultText.toPlainText()) self.assertIn('Test result:Test skipped', dlg.resultText.toPlainText())
def testItemClicked(self): """test the result is set to the clicked value.""" # preconditions r = Report() for test in self.allTests: tr = TestResult(test) r.addTestResult(tr) dlg = ReportDialog(r) # dlg.resultsTree is a QTreeWidget # do test1 self.assertTrue(dlg.resultText.toPlainText() == '') dlg.itemClicked() self.assertTrue(dlg.resultText.toPlainText() == '') # do test 2 currentItem = dlg.resultsTree.topLevelItem(0).child(0) dlg.resultsTree.setCurrentItem(currentItem) dlg.itemClicked() self.assertIn('Test name: -Functional test', dlg.resultText.toPlainText()) self.assertIn('Test result:Test skipped', dlg.resultText.toPlainText())
def getReportDialog(self): """Wrapper for easy mocking""" self.reportDialog = ReportDialog(self.report) return self.reportDialog