Permalink
Browse files

Bug 1079635 - Implement a verbose option for the machformatter for th…

…ose debugging tests locally.;r=jgraham
  • Loading branch information...
chmanchester committed Oct 17, 2014
1 parent a0be7e7 commit b7b2dc40de355add3634cc972fc31521a8daeed3
@@ -22,11 +22,24 @@
def level_filter_wrapper(formatter, level):
return handlers.LogLevelFilter(formatter, level)
def verbose_wrapper(formatter, verbose):
formatter.verbose = verbose
return formatter
formatter_option_defaults = {
'verbose': False,
'level': 'info',
}
fmt_options = {
# <option name>: (<wrapper function>, description, <applicable formatters>)
# <option name>: (<wrapper function>, description, <applicable formatters>, action)
# "action" is used by the commandline parser in use.
'verbose': (verbose_wrapper,
"Enables verbose mode for the given formatter.",
["mach"], "store_true"),
'level': (level_filter_wrapper,
"A least log level to subscribe to for the given formatter (debug, info, error, etc.)",
["mach", "tbpl"]),
["mach", "tbpl"], "store"),
}
@@ -61,10 +74,10 @@ def add_logging_group(parser):
for name, (cls, help_str) in log_formatters.iteritems():
group.add_option("--log-" + name, action="append", type="str",
help=help_str)
for optname, (cls, help_str, formatters) in fmt_options.iteritems():
for optname, (cls, help_str, formatters, action) in fmt_options.iteritems():
for fmt in formatters:
group.add_option("--log-%s-%s" % (fmt, optname), action="store",
type="str", help=help_str)
group.add_option("--log-%s-%s" % (fmt, optname), action=action,
help=help_str, default=None)
parser.add_option_group(group)
else:
group = parser.add_argument_group(group_name,
@@ -73,10 +86,10 @@ def add_logging_group(parser):
group.add_argument("--log-" + name, action="append", type=log_file,
help=help_str)
for optname, (cls, help_str, formatters) in fmt_options.iteritems():
for optname, (cls, help_str, formatters, action) in fmt_options.iteritems():
for fmt in formatters:
group.add_argument("--log-%s-%s" % (fmt, optname), action="store",
type=str, help=help_str)
group.add_argument("--log-%s-%s" % (fmt, optname), action=action,
help=help_str, default=None)
def setup_handlers(logger, formatters, formatter_options):
@@ -125,13 +138,9 @@ def setup_logging(suite, args, defaults=None):
:rtype: StructuredLogger
"""
_option_defaults = {
'level': 'info',
}
logger = StructuredLogger(suite)
# Keep track of any options passed for formatters.
formatter_options = defaultdict(lambda: _option_defaults.copy())
formatter_options = defaultdict(lambda: formatter_option_defaults.copy())
# Keep track of formatters and list of streams specified.
formatters = {}
found = False
@@ -43,6 +43,7 @@ def __init__(self, start_time=None, write_interval=False, write_times=True,
self.has_unexpected = {}
self.last_time = None
self.terminal = terminal
self.verbose = False
self.summary_values = {"tests": 0,
"subtests": 0,
@@ -74,7 +75,8 @@ def __call__(self, data):
color = self.terminal.green
else:
color = self.terminal.red
elif data["action"] in ("suite_start", "suite_end", "test_start"):
elif data["action"] in ("suite_start", "suite_end",
"test_start", "test_status"):
color = self.terminal.yellow
elif data["action"] == "crash":
color = self.terminal.red
@@ -231,16 +233,26 @@ def test_status(self, data):
message += "\n"
message += data["stack"]
if "expected" in data:
self.status_buffer[test]["unexpected"].append((data["subtest"],
data["status"],
data["expected"],
message))
if data["status"] == "PASS":
self.status_buffer[test]["pass"] += 1
self._update_summary(data)
rv = None
status, subtest = data["status"], data["subtest"]
unexpected = "expected" in data
if self.verbose:
color = self.terminal.red if unexpected else self.terminal.green
rv = " ".join([subtest, color(status), message])
elif unexpected:
# We only append an unexpected summary if it was not logged
# directly by verbose mode.
self.status_buffer[test]["unexpected"].append((subtest,
status,
data["expected"],
message))
return rv
def _update_summary(self, data):
if "expected" in data:
self.summary_values["unexpected"][data["status"]] += 1

0 comments on commit b7b2dc4

Please sign in to comment.