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

Side by Side Diff: third_party/pycoverage/coverage/debug.py

Issue 727003004: Add python coverage module to third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « third_party/pycoverage/coverage/data.py ('k') | third_party/pycoverage/coverage/execfile.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 """Control of and utilities for debugging."""
2
3 import os
4
5
6 # When debugging, it can be helpful to force some options, especially when
7 # debugging the configuration mechanisms you usually use to control debugging!
8 # This is a list of forced debugging options.
9 FORCED_DEBUG = []
10
11
12 class DebugControl(object):
13 """Control and output for debugging."""
14
15 def __init__(self, options, output):
16 """Configure the options and output file for debugging."""
17 self.options = options
18 self.output = output
19
20 def should(self, option):
21 """Decide whether to output debug information in category `option`."""
22 return (option in self.options or option in FORCED_DEBUG)
23
24 def write(self, msg):
25 """Write a line of debug output."""
26 if self.should('pid'):
27 msg = "pid %5d: %s" % (os.getpid(), msg)
28 self.output.write(msg+"\n")
29 self.output.flush()
30
31 def write_formatted_info(self, info):
32 """Write a sequence of (label,data) pairs nicely."""
33 for line in info_formatter(info):
34 self.write(" %s" % line)
35
36
37 def info_formatter(info):
38 """Produce a sequence of formatted lines from info.
39
40 `info` is a sequence of pairs (label, data). The produced lines are
41 nicely formatted, ready to print.
42
43 """
44 label_len = max([len(l) for l, _d in info])
45 for label, data in info:
46 if data == []:
47 data = "-none-"
48 if isinstance(data, (list, tuple)):
49 prefix = "%*s:" % (label_len, label)
50 for e in data:
51 yield "%*s %s" % (label_len+1, prefix, e)
52 prefix = ""
53 else:
54 yield "%*s: %s" % (label_len, label, data)
OLDNEW
« no previous file with comments | « third_party/pycoverage/coverage/data.py ('k') | third_party/pycoverage/coverage/execfile.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698