DataViews/PyCoverageDialog.py

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

eric ide

mercurial