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 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 testInit(self): """check if __init__ is correctly executed.""" tr = TestResult('fake_test') self.assertEqual(tr.test, 'fake_test') self.assertEqual(tr.status, tr.SKIPPED) self.assertEqual(tr.errorStep, None) self.assertEqual(tr.errorMessage, None)
def testAddTestResult(self): """test if a test is added in the results array.""" r = Report() test = mock.Mock() tr = TestResult(test) r.addTestResult(tr) self.assertEqual(r.results[0], tr) self.assertTrue(len(r.results) == 1)
def test__str___(self): """test __str__ that convert a status in readamble string.""" t = Test('Test that skipped is set') t.addStep('Skipped', lambda: False) tr = TestResult(t) self.assertEqual( u"%s" % tr, 'Test name: -Test that skipped is set\nTest result:Test skipped')
def test__str___(self): """Test __str__ method""" t = Test('Test that was skipped') t.addStep('Skipped', lambda: False) tr = TestResult(t) self.assertEqual( '{}'.format(tr), 'Test name: -Test that was skipped\nTest result:Test skipped')
def testAddTestResult(self): """Test if a test is added to the results array""" r = Report() test = mock.Mock() tr = TestResult(test) r.addTestResult(tr) self.assertEqual(r.results[0], tr) self.assertEqual(len(r.results), 1)
def testSkipped(self): """check if the skipped is correctly set.""" t = Test('Test that skipped is set') t.addStep('Skipped', lambda: False) tr = TestResult(t) tr.skipped() self.assertEqual(tr.status, tr.SKIPPED) self.assertIsNone(tr.errorStep) self.assertIsNone(tr.errorMessage, 'PASSED')
def testFailed(self): """check if the fail flag is correctly set.""" t = Test('Test that fail is set') t.addStep('Fail', lambda: False) tr = TestResult(t) tr.failed('fake_step', 'FAILED') self.assertEqual(tr.status, tr.FAILED) self.assertEqual(tr.errorStep, 'fake_step') self.assertEqual(tr.errorMessage, 'FAILED')
def testPassed(self): """Check if the passed flag is correctly set""" t = Test('Test that passed') t.addStep('Passed', lambda: False) tr = TestResult(t) tr.passed() self.assertEqual(tr.status, tr.PASSED) self.assertIsNone(tr.errorStep) self.assertIsNone(tr.errorMessage)
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 runner(cls, suite): test = list(suite)[0] utw = UnitTestWrapper(test) report = Report() result = TestResult(test) step = utw.steps[0] try: step.function() result.passed() except Exception, e: result.failed(test, str(e))
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: QApplication.restoreOverrideCursor() self.testingFinished.emit() self.setVisible(False)
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 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())