Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: tools/code_coverage/croc.py

Issue 660142: Add resilience in croc to a failed build (e.g. 0 stats generated).... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/code_coverage/croc_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/code_coverage/croc.py
===================================================================
--- tools/code_coverage/croc.py (revision 39945)
+++ tools/code_coverage/croc.py (working copy)
@@ -52,6 +52,14 @@
class CoverageStats(dict):
"""Coverage statistics."""
+ # Default dictionary values for this stat.
+ DEFAULTS = { 'files_covered': 0,
+ 'files_instrumented': 0,
+ 'files_executable': 0,
+ 'lines_covered': 0,
+ 'lines_instrumented': 0,
+ 'lines_executable': 0 }
+
def Add(self, coverage_stats):
"""Adds a contribution from another coverage stats dict.
@@ -64,6 +72,15 @@
else:
self[k] = v
+ def AddDefaults(self):
+ """Add some default stats which might be assumed present.
+
+ Do not clobber if already present. Adds resilience when evaling a
+ croc file which expects certain stats to exist."""
+ for k, v in self.DEFAULTS.iteritems():
+ if not k in self:
+ self[k] = v
+
#------------------------------------------------------------------------------
@@ -399,6 +416,10 @@
return default
stats = self.tree.stats_by_group[group]
+ # Unit tests use real dicts, not CoverageStats objects,
+ # so we can't AddDefaults() on them.
+ if group == 'all' and hasattr(stats, 'AddDefaults'):
+ stats.AddDefaults()
try:
return eval(stat, {'__builtins__': {'S': self.GetStat}}, stats)
except Exception, e:
« no previous file with comments | « no previous file | tools/code_coverage/croc_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698