From 189d46574f390cedae69e87c4796cec9c23a80ae Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Mon, 26 Jul 2010 19:09:41 -0400 Subject: Basic cleanup, removing unused code, re-organizing for clarity. --- machineout.py | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/machineout.py b/machineout.py index fc62875..da51f0f 100644 --- a/machineout.py +++ b/machineout.py @@ -4,14 +4,12 @@ It is intended to be use to integrate nose with your IDE such as Vim. """ import re +import os import traceback from nose.plugins import Plugin -__all__ = ['NoseMachineReadableOutput'] - - -class dummystream: +class DummyStream: def write(self, *arg): pass @@ -30,34 +28,31 @@ class NoseMachineReadableOutput(Plugin): name = 'machineout' - doctest_failure_re = re.compile('File "([^"]+)", line (\d+), in ([^\n]+)\n(.+)', + doctest_failure_re = re.compile( + 'File "([^"]+)", line (\d+), in ([^\n]+)\n(.+)', re.DOTALL) def __init__(self): super(NoseMachineReadableOutput, self).__init__() self.basepath = os.getcwd() - def add_options(self, parser, env): + def add_options(self, parser, env=None): super(NoseMachineReadableOutput, self).add_options(parser, env) parser.add_option("--machine-output", action="store_true", - dest="machine_output", - default=False, - help="Reports test results in easily parsable format.") + dest="machine_output", default=False, + help="Reports test results in parsable format.") - def configure(self, options, conf): - super(NoseMachineReadableOutput, self).configure(options, conf) - self.enabled = options.machine_output - - def addSkip(self, test): - pass + def addError(self, test, err): + self.add_formatted('error', err) - def addDeprecated(self, test): - pass + def addFailure(self, test, err): + self.add_formatted('fail', err) - def addError(self, test, err): - self.addFormatted('error', err) + def setOutputStream(self, stream): + self.stream = stream + return DummyStream() - def addFormatted(self, etype, err): + def add_formatted(self, etype, err): exctype, value, tb = err fulltb = traceback.extract_tb(tb) @@ -72,12 +67,12 @@ class NoseMachineReadableOutput(Plugin): lines = traceback.format_exception_only(exctype, value) lines = [line.strip('\n') for line in lines] - msg0 = lines[0] + msg = lines[0] fname = self.format_testfname(fname) prefix = "%s:%d" % (fname, lineno) self.stream.writeln("%s: In %s" % (fname, funname)) - self.stream.writeln("%s: %s: %s" % (prefix, etype, msg0)) + self.stream.writeln("%s: %s: %s" % (prefix, etype, msg)) if len(lines) > 1: pad = ' '*(len(etype)+1) @@ -89,10 +84,3 @@ class NoseMachineReadableOutput(Plugin): return fname[len(self.basepath)+1:] return fname - - def addFailure(self, test, err): - self.addFormatted('fail', err) - - def setOutputStream(self, stream): - self.stream = stream - return dummystream() -- cgit v1.2.3