27 from DebugClients.Python3.coverage import coverage |
27 from DebugClients.Python3.coverage import coverage |
28 |
28 |
29 import UI.PixmapCache |
29 import UI.PixmapCache |
30 |
30 |
31 import Utilities |
31 import Utilities |
|
32 |
32 |
33 |
33 class UnittestDialog(QWidget, Ui_UnittestDialog): |
34 class UnittestDialog(QWidget, Ui_UnittestDialog): |
34 """ |
35 """ |
35 Class implementing the UI to the pyunit package. |
36 Class implementing the UI to the pyunit package. |
36 |
37 |
37 @signal unittestFile(str, int, int) emitted to show the source of a unittest file |
38 @signal unittestFile(str, int, int) emitted to show the source of a unittest file |
38 """ |
39 """ |
39 unittestFile = pyqtSignal(str, int, int) |
40 unittestFile = pyqtSignal(str, int, int) |
40 |
41 |
41 def __init__(self,prog = None,dbs = None,ui = None,parent = None,name = None): |
42 def __init__(self, prog=None, dbs=None, ui=None, parent=None, name=None): |
42 """ |
43 """ |
43 Constructor |
44 Constructor |
44 |
45 |
45 @param prog filename of the program to open |
46 @param prog filename of the program to open |
46 @param dbs reference to the debug server object. It is an indication |
47 @param dbs reference to the debug server object. It is an indication |
47 whether we were called from within the eric5 IDE |
48 whether we were called from within the eric5 IDE |
48 @param ui reference to the UI object |
49 @param ui reference to the UI object |
49 @param parent parent widget of this dialog (QWidget) |
50 @param parent parent widget of this dialog (QWidget) |
50 @param name name of this dialog (string) |
51 @param name name of this dialog (string) |
51 """ |
52 """ |
52 QWidget.__init__(self,parent) |
53 QWidget.__init__(self, parent) |
53 if name: |
54 if name: |
54 self.setObjectName(name) |
55 self.setObjectName(name) |
55 self.setupUi(self) |
56 self.setupUi(self) |
56 |
57 |
57 self.startButton = self.buttonBox.addButton( |
58 self.startButton = self.buttonBox.addButton( |
148 """ |
149 """ |
149 Private slot to open a file dialog. |
150 Private slot to open a file dialog. |
150 """ |
151 """ |
151 if self.dbs: |
152 if self.dbs: |
152 py2Extensions = \ |
153 py2Extensions = \ |
153 ' '.join(["*{0}".format(ext) |
154 ' '.join(["*{0}".format(ext) |
154 for ext in self.dbs.getExtensions('Python2')]) |
155 for ext in self.dbs.getExtensions('Python2')]) |
155 py3Extensions = \ |
156 py3Extensions = \ |
156 ' '.join(["*{0}".format(ext) |
157 ' '.join(["*{0}".format(ext) |
157 for ext in self.dbs.getExtensions('Python3')]) |
158 for ext in self.dbs.getExtensions('Python3')]) |
158 filter = self.trUtf8( |
159 filter = self.trUtf8( |
159 "Python3 Files ({1});;Python2 Files ({0});;All Files (*)")\ |
160 "Python3 Files ({1});;Python2 Files ({0});;All Files (*)")\ |
160 .format(py2Extensions, py3Extensions) |
161 .format(py2Extensions, py3Extensions) |
161 else: |
162 else: |
209 if self.running: |
210 if self.running: |
210 return |
211 return |
211 |
212 |
212 prog = self.testsuiteComboBox.currentText() |
213 prog = self.testsuiteComboBox.currentText() |
213 if not prog: |
214 if not prog: |
214 E5MessageBox.critical(self, |
215 E5MessageBox.critical(self, |
215 self.trUtf8("Unittest"), |
216 self.trUtf8("Unittest"), |
216 self.trUtf8("You must enter a test suite file.")) |
217 self.trUtf8("You must enter a test suite file.")) |
217 return |
218 return |
218 |
219 |
219 # prepend the selected file to the testsuite combobox |
220 # prepend the selected file to the testsuite combobox |
220 self.insertProg(prog) |
221 self.insertProg(prog) |
256 testFunctionName, module) |
257 testFunctionName, module) |
257 except AttributeError: |
258 except AttributeError: |
258 test = unittest.defaultTestLoader.loadTestsFromModule(module) |
259 test = unittest.defaultTestLoader.loadTestsFromModule(module) |
259 except: |
260 except: |
260 exc_type, exc_value, exc_tb = sys.exc_info() |
261 exc_type, exc_value, exc_tb = sys.exc_info() |
261 E5MessageBox.critical(self, |
262 E5MessageBox.critical(self, |
262 self.trUtf8("Unittest"), |
263 self.trUtf8("Unittest"), |
263 self.trUtf8("<p>Unable to run test <b>{0}</b>.<br>{1}<br>{2}</p>") |
264 self.trUtf8("<p>Unable to run test <b>{0}</b>.<br>{1}<br>{2}</p>") |
264 .format(self.testName, str(exc_type), str(exc_value))) |
265 .format(self.testName, str(exc_type), str(exc_value))) |
265 return |
266 return |
266 |
267 |
274 else: |
275 else: |
275 mainScript = os.path.abspath(prog) |
276 mainScript = os.path.abspath(prog) |
276 else: |
277 else: |
277 mainScript = os.path.abspath(prog) |
278 mainScript = os.path.abspath(prog) |
278 cover = coverage( |
279 cover = coverage( |
279 data_file = "{0}.coverage".format(os.path.splitext(mainScript)[0])) |
280 data_file="{0}.coverage".format(os.path.splitext(mainScript)[0])) |
280 cover.use_cache(True) |
281 cover.use_cache(True) |
281 if self.coverageEraseCheckBox.isChecked(): |
282 if self.coverageEraseCheckBox.isChecked(): |
282 cover.erase() |
283 cover.erase() |
283 else: |
284 else: |
284 cover = None |
285 cover = None |
305 @param nrTests number of tests contained in the test suite (integer) |
306 @param nrTests number of tests contained in the test suite (integer) |
306 @param exc_type type of exception occured during preparation (string) |
307 @param exc_type type of exception occured during preparation (string) |
307 @param exc_value value of exception occured during preparation (string) |
308 @param exc_value value of exception occured during preparation (string) |
308 """ |
309 """ |
309 if nrTests == 0: |
310 if nrTests == 0: |
310 E5MessageBox.critical(self, |
311 E5MessageBox.critical(self, |
311 self.trUtf8("Unittest"), |
312 self.trUtf8("Unittest"), |
312 self.trUtf8("<p>Unable to run test <b>{0}</b>.<br>{1}<br>{2}</p>") |
313 self.trUtf8("<p>Unable to run test <b>{0}</b>.<br>{1}<br>{2}</p>") |
313 .format(self.testName, exc_type, exc_value)) |
314 .format(self.testName, exc_type, exc_value)) |
314 return |
315 return |
315 |
316 |
504 break |
505 break |
505 if fmatch: |
506 if fmatch: |
506 fn, ln = fmatch.group(1, 2) |
507 fn, ln = fmatch.group(1, 2) |
507 self.unittestFile.emit(fn, int(ln), 1) |
508 self.unittestFile.emit(fn, int(ln), 1) |
508 |
509 |
|
510 |
509 class QtTestResult(unittest.TestResult): |
511 class QtTestResult(unittest.TestResult): |
510 """ |
512 """ |
511 A TestResult derivative to work with a graphical GUI. |
513 A TestResult derivative to work with a graphical GUI. |
512 |
514 |
513 For more details see pyunit.py of the standard python distribution. |
515 For more details see pyunit.py of the standard python distribution. |
559 @param test Reference to the test object |
561 @param test Reference to the test object |
560 """ |
562 """ |
561 unittest.TestResult.stopTest(self, test) |
563 unittest.TestResult.stopTest(self, test) |
562 self.parent.testFinished() |
564 self.parent.testFinished() |
563 |
565 |
|
566 |
564 class UnittestWindow(QMainWindow): |
567 class UnittestWindow(QMainWindow): |
565 """ |
568 """ |
566 Main window class for the standalone dialog. |
569 Main window class for the standalone dialog. |
567 """ |
570 """ |
568 def __init__(self, prog = None, parent = None): |
571 def __init__(self, prog=None, parent=None): |
569 """ |
572 """ |
570 Constructor |
573 Constructor |
571 |
574 |
572 @param prog filename of the program to open |
575 @param prog filename of the program to open |
573 @param parent reference to the parent widget (QWidget) |
576 @param parent reference to the parent widget (QWidget) |
574 """ |
577 """ |
575 QMainWindow.__init__(self, parent) |
578 QMainWindow.__init__(self, parent) |
576 self.cw = UnittestDialog(prog = prog, parent = self) |
579 self.cw = UnittestDialog(prog=prog, parent=self) |
577 self.cw.installEventFilter(self) |
580 self.cw.installEventFilter(self) |
578 size = self.cw.size() |
581 size = self.cw.size() |
579 self.setCentralWidget(self.cw) |
582 self.setCentralWidget(self.cw) |
580 self.resize(size) |
583 self.resize(size) |
581 |
584 |