diff options
author | Mike Crute <mcrute@gmail.com> | 2010-07-26 19:00:06 -0400 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2010-07-26 19:00:06 -0400 |
commit | 9e566f52c17e71662c75e626eca9fac0721fffc9 (patch) | |
tree | 2b07541355905c09dc060aae91d0082ef2ebf4e7 | |
parent | f31637d9545d788f9333d90b6a3d2f5b7a31d1ab (diff) | |
download | nose-machineout-9e566f52c17e71662c75e626eca9fac0721fffc9.tar.bz2 nose-machineout-9e566f52c17e71662c75e626eca9fac0721fffc9.tar.xz nose-machineout-9e566f52c17e71662c75e626eca9fac0721fffc9.zip |
Pedantic PEP8 cleanup.
-rw-r--r-- | machineout.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/machineout.py b/machineout.py index 69a53c6..3b47e68 100644 --- a/machineout.py +++ b/machineout.py | |||
@@ -1,10 +1,6 @@ | |||
1 | |||
2 | """ | 1 | """ |
3 | Formats nose output into format easily parsable by machine. | 2 | Formats nose output into format easily parsable by machine. |
4 | |||
5 | It is intended to be use to integrate nose with your IDE such as Vim. | 3 | It is intended to be use to integrate nose with your IDE such as Vim. |
6 | |||
7 | @author: Max Ischenko <ischenko@gmail.com> | ||
8 | """ | 4 | """ |
9 | 5 | ||
10 | import re | 6 | import re |
@@ -12,8 +8,10 @@ import os.path | |||
12 | import traceback | 8 | import traceback |
13 | from nose.plugins import Plugin | 9 | from nose.plugins import Plugin |
14 | 10 | ||
11 | |||
15 | __all__ = ['NoseMachineReadableOutput'] | 12 | __all__ = ['NoseMachineReadableOutput'] |
16 | 13 | ||
14 | |||
17 | try: | 15 | try: |
18 | import doctest | 16 | import doctest |
19 | doctest_fname = re.sub('\.py.?$', '.py', doctest.__file__) | 17 | doctest_fname = re.sub('\.py.?$', '.py', doctest.__file__) |
@@ -21,24 +19,28 @@ try: | |||
21 | except ImportError: | 19 | except ImportError: |
22 | doctest_fname = None | 20 | doctest_fname = None |
23 | 21 | ||
22 | |||
24 | class dummystream: | 23 | class dummystream: |
24 | |||
25 | def write(self, *arg): | 25 | def write(self, *arg): |
26 | pass | 26 | pass |
27 | |||
27 | def writeln(self, *arg): | 28 | def writeln(self, *arg): |
28 | pass | 29 | pass |
30 | |||
29 | def flush(self): | 31 | def flush(self): |
30 | pass | 32 | pass |
31 | 33 | ||
34 | |||
32 | def is_doctest_traceback(fname): | 35 | def is_doctest_traceback(fname): |
33 | return fname == doctest_fname | 36 | return fname == doctest_fname |
34 | 37 | ||
38 | |||
35 | class PluginError(Exception): | 39 | class PluginError(Exception): |
36 | def __repr__(self): | 40 | pass |
37 | s = super(PluginError, self).__repr__() | ||
38 | return s + "\nReport bugs to ischenko@gmail.com." | ||
39 | 41 | ||
40 | class NoseMachineReadableOutput(Plugin): | ||
41 | 42 | ||
43 | class NoseMachineReadableOutput(Plugin): | ||
42 | """ | 44 | """ |
43 | Output errors and failures in a machine-readable way. | 45 | Output errors and failures in a machine-readable way. |
44 | """ | 46 | """ |
@@ -104,26 +106,26 @@ class NoseMachineReadableOutput(Plugin): | |||
104 | lines = traceback.format_exception_only(exctype, value) | 106 | lines = traceback.format_exception_only(exctype, value) |
105 | lines = [line.strip('\n') for line in lines] | 107 | lines = [line.strip('\n') for line in lines] |
106 | msg0 = lines[0] | 108 | msg0 = lines[0] |
109 | |||
107 | fname = self.format_testfname(fname) | 110 | fname = self.format_testfname(fname) |
108 | prefix = "%s:%d" % (fname, lineno) | 111 | prefix = "%s:%d" % (fname, lineno) |
109 | self.stream.writeln("%s: In %s" % (fname, funname)) | 112 | self.stream.writeln("%s: In %s" % (fname, funname)) |
110 | self.stream.writeln("%s: %s: %s" % (prefix, etype, msg0)) | 113 | self.stream.writeln("%s: %s: %s" % (prefix, etype, msg0)) |
114 | |||
111 | if len(lines) > 1: | 115 | if len(lines) > 1: |
112 | pad = ' '*(len(etype)+1) | 116 | pad = ' '*(len(etype)+1) |
113 | for line in lines[1:]: | 117 | for line in lines[1:]: |
114 | self.stream.writeln("%s: %s %s" % (prefix, pad, line)) | 118 | self.stream.writeln("%s: %s %s" % (prefix, pad, line)) |
115 | 119 | ||
116 | def format_testfname(self, fname): | 120 | def format_testfname(self, fname): |
117 | "Strips common path segments if any." | ||
118 | if fname.startswith(self.basepath): | 121 | if fname.startswith(self.basepath): |
119 | return fname[len(self.basepath)+1:] | 122 | return fname[len(self.basepath)+1:] |
123 | |||
120 | return fname | 124 | return fname |
121 | 125 | ||
122 | def addFailure(self, test, err): | 126 | def addFailure(self, test, err): |
123 | self.addFormatted('fail', err) | 127 | self.addFormatted('fail', err) |
124 | 128 | ||
125 | def setOutputStream(self, stream): | 129 | def setOutputStream(self, stream): |
126 | # grab for own use | ||
127 | self.stream = stream | 130 | self.stream = stream |
128 | # return dummy stream to supress normal output | ||
129 | return dummystream() | 131 | return dummystream() |