DataViews/PyCoverageDialog.py

changeset 2986
cd4e2cab7eb2
parent 2826
22c39062c274
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
2985:177b1858245f 2986:cd4e2cab7eb2
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import pyqtSlot, Qt 12 from PyQt4.QtCore import pyqtSlot, Qt
13 from PyQt4.QtGui import QDialog, QDialogButtonBox, QMenu, QHeaderView, QTreeWidgetItem, \ 13 from PyQt4.QtGui import QDialog, QDialogButtonBox, QMenu, QHeaderView, \
14 QApplication, QProgressDialog 14 QTreeWidgetItem, QApplication, QProgressDialog
15 15
16 from E5Gui import E5MessageBox 16 from E5Gui import E5MessageBox
17 from E5Gui.E5Application import e5App 17 from E5Gui.E5Application import e5App
18 18
19 from .Ui_PyCoverageDialog import Ui_PyCoverageDialog 19 from .Ui_PyCoverageDialog import Ui_PyCoverageDialog
37 self.setupUi(self) 37 self.setupUi(self)
38 38
39 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 39 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
40 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 40 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
41 41
42 self.summaryList.headerItem().setText(self.summaryList.columnCount(), "") 42 self.summaryList.headerItem().setText(
43 self.summaryList.columnCount(), "")
43 self.resultList.headerItem().setText(self.resultList.columnCount(), "") 44 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
44 45
45 self.cancelled = False 46 self.cancelled = False
46 self.path = '.' 47 self.path = '.'
47 self.reload = False 48 self.reload = False
59 self.__menu.addAction(self.trUtf8('Delete annotated files'), 60 self.__menu.addAction(self.trUtf8('Delete annotated files'),
60 self.__deleteAnnotated) 61 self.__deleteAnnotated)
61 self.__menu.addSeparator() 62 self.__menu.addSeparator()
62 self.__menu.addAction(self.trUtf8('Erase Coverage Info'), self.__erase) 63 self.__menu.addAction(self.trUtf8('Erase Coverage Info'), self.__erase)
63 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) 64 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu)
64 self.resultList.customContextMenuRequested.connect(self.__showContextMenu) 65 self.resultList.customContextMenuRequested.connect(
66 self.__showContextMenu)
65 67
66 def __format_lines(self, lines): 68 def __format_lines(self, lines):
67 """ 69 """
68 Private method to format a list of integers into string by coalescing groups. 70 Private method to format a list of integers into string by coalescing
71 groups.
69 72
70 @param lines list of integers 73 @param lines list of integers
71 @return string representing the list 74 @return string representing the list
72 """ 75 """
73 pairs = [] 76 pairs = []
92 if start: 95 if start:
93 pairs.append((start, end)) 96 pairs.append((start, end))
94 97
95 def stringify(pair): 98 def stringify(pair):
96 """ 99 """
97 Private helper function to generate a string representation of a pair 100 Private helper function to generate a string representation of a
101 pair.
98 102
99 @param pair pair of integers 103 @param pair pair of integers
100 """ 104 """
101 start, end = pair 105 start, end = pair
102 if start == end: 106 if start == end:
104 else: 108 else:
105 return "{0:d}-{1:d}".format(start, end) 109 return "{0:d}-{1:d}".format(start, end)
106 110
107 return ", ".join(map(stringify, pairs)) 111 return ", ".join(map(stringify, pairs))
108 112
109 def __createResultItem(self, file, statements, executed, coverage, excluded, missing): 113 def __createResultItem(self, file, statements, executed, coverage,
114 excluded, missing):
110 """ 115 """
111 Private method to create an entry in the result list. 116 Private method to create an entry in the result list.
112 117
113 @param file filename of file (string) 118 @param file filename of file (string)
114 @param statements amount of statements (integer) 119 @param statements amount of statements (integer)
186 for file in files: 191 for file in files:
187 if self.cancelled: 192 if self.cancelled:
188 return 193 return
189 194
190 try: 195 try:
191 statements, excluded, missing, readable = cover.analysis2(file)[1:] 196 statements, excluded, missing, readable = \
192 readableEx = excluded and self.__format_lines(excluded) or '' 197 cover.analysis2(file)[1:]
198 readableEx = (excluded and self.__format_lines(excluded)
199 or '')
193 n = len(statements) 200 n = len(statements)
194 m = n - len(missing) 201 m = n - len(missing)
195 if n > 0: 202 if n > 0:
196 pc = 100.0 * m / n 203 pc = 100.0 * m / n
197 else: 204 else:
230 self.summaryGroup.hide() 237 self.summaryGroup.hide()
231 238
232 if total_exceptions: 239 if total_exceptions:
233 E5MessageBox.warning(self, 240 E5MessageBox.warning(self,
234 self.trUtf8("Parse Error"), 241 self.trUtf8("Parse Error"),
235 self.trUtf8("""%n file(s) could not be parsed. Coverage info for""" 242 self.trUtf8("""%n file(s) could not be parsed. Coverage"""
236 """ these is not available.""", "", total_exceptions)) 243 """ info for these is not available.""", "",
244 total_exceptions))
237 245
238 self.__finish() 246 self.__finish()
239 247
240 def __finish(self): 248 def __finish(self):
241 """ 249 """
242 Private slot called when the action finished or the user pressed the button. 250 Private slot called when the action finished or the user pressed the
251 button.
243 """ 252 """
244 self.cancelled = True 253 self.cancelled = True
245 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 254 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
246 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 255 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
247 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 256 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)

eric ide

mercurial