summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2010-07-26 19:09:41 -0400
committerMike Crute <mcrute@gmail.com>2010-07-26 19:09:41 -0400
commit189d46574f390cedae69e87c4796cec9c23a80ae (patch)
tree41a71a7b1e36972e85130dd01b25f617a240bbc5
parent3342871c734f8d9c8ca859a4be77f82e7083bdea (diff)
downloadnose-machineout-189d46574f390cedae69e87c4796cec9c23a80ae.tar.bz2
nose-machineout-189d46574f390cedae69e87c4796cec9c23a80ae.tar.xz
nose-machineout-189d46574f390cedae69e87c4796cec9c23a80ae.zip
Basic cleanup, removing unused code, re-organizing for clarity.
-rw-r--r--machineout.py46
1 files 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.
4""" 4"""
5 5
6import re 6import re
7import os
7import traceback 8import traceback
8from nose.plugins import Plugin 9from nose.plugins import Plugin
9 10
10 11
11__all__ = ['NoseMachineReadableOutput'] 12class DummyStream:
12
13
14class dummystream:
15 13
16 def write(self, *arg): 14 def write(self, *arg):
17 pass 15 pass
@@ -30,34 +28,31 @@ class NoseMachineReadableOutput(Plugin):
30 28
31 name = 'machineout' 29 name = 'machineout'
32 30
33 doctest_failure_re = re.compile('File "([^"]+)", line (\d+), in ([^\n]+)\n(.+)', 31 doctest_failure_re = re.compile(
32 'File "([^"]+)", line (\d+), in ([^\n]+)\n(.+)',
34 re.DOTALL) 33 re.DOTALL)
35 34
36 def __init__(self): 35 def __init__(self):
37 super(NoseMachineReadableOutput, self).__init__() 36 super(NoseMachineReadableOutput, self).__init__()
38 self.basepath = os.getcwd() 37 self.basepath = os.getcwd()
39 38
40 def add_options(self, parser, env): 39 def add_options(self, parser, env=None):
41 super(NoseMachineReadableOutput, self).add_options(parser, env) 40 super(NoseMachineReadableOutput, self).add_options(parser, env)
42 parser.add_option("--machine-output", action="store_true", 41 parser.add_option("--machine-output", action="store_true",
43 dest="machine_output", 42 dest="machine_output", default=False,
44 default=False, 43 help="Reports test results in parsable format.")
45 help="Reports test results in easily parsable format.")
46 44
47 def configure(self, options, conf): 45 def addError(self, test, err):
48 super(NoseMachineReadableOutput, self).configure(options, conf) 46 self.add_formatted('error', err)
49 self.enabled = options.machine_output
50
51 def addSkip(self, test):
52 pass
53 47
54 def addDeprecated(self, test): 48 def addFailure(self, test, err):
55 pass 49 self.add_formatted('fail', err)
56 50
57 def addError(self, test, err): 51 def setOutputStream(self, stream):
58 self.addFormatted('error', err) 52 self.stream = stream
53 return DummyStream()
59 54
60 def addFormatted(self, etype, err): 55 def add_formatted(self, etype, err):
61 exctype, value, tb = err 56 exctype, value, tb = err
62 fulltb = traceback.extract_tb(tb) 57 fulltb = traceback.extract_tb(tb)
63 58
@@ -72,12 +67,12 @@ class NoseMachineReadableOutput(Plugin):
72 67
73 lines = traceback.format_exception_only(exctype, value) 68 lines = traceback.format_exception_only(exctype, value)
74 lines = [line.strip('\n') for line in lines] 69 lines = [line.strip('\n') for line in lines]
75 msg0 = lines[0] 70 msg = lines[0]
76 71
77 fname = self.format_testfname(fname) 72 fname = self.format_testfname(fname)
78 prefix = "%s:%d" % (fname, lineno) 73 prefix = "%s:%d" % (fname, lineno)
79 self.stream.writeln("%s: In %s" % (fname, funname)) 74 self.stream.writeln("%s: In %s" % (fname, funname))
80 self.stream.writeln("%s: %s: %s" % (prefix, etype, msg0)) 75 self.stream.writeln("%s: %s: %s" % (prefix, etype, msg))
81 76
82 if len(lines) > 1: 77 if len(lines) > 1:
83 pad = ' '*(len(etype)+1) 78 pad = ' '*(len(etype)+1)
@@ -89,10 +84,3 @@ class NoseMachineReadableOutput(Plugin):
89 return fname[len(self.basepath)+1:] 84 return fname[len(self.basepath)+1:]
90 85
91 return fname 86 return fname
92
93 def addFailure(self, test, err):
94 self.addFormatted('fail', err)
95
96 def setOutputStream(self, stream):
97 self.stream = stream
98 return dummystream()