From a43be0b7948d2596edcd9fe7258e81d6e31a70c8 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Tue, 3 Nov 2009 14:56:00 -0500 Subject: Initial import --- PKG-INFO | 19 ++++ machineout.py | 119 ++++++++++++++++++++++++++ nose_machineout.egg-info/PKG-INFO | 19 ++++ nose_machineout.egg-info/SOURCES.txt | 10 +++ nose_machineout.egg-info/dependency_links.txt | 1 + nose_machineout.egg-info/entry_points.txt | 3 + nose_machineout.egg-info/not-zip-safe | 1 + nose_machineout.egg-info/requires.txt | 1 + nose_machineout.egg-info/top_level.txt | 2 + setup.cfg | 5 ++ setup.py | 34 ++++++++ test_machineout.py | 10 +++ 12 files changed, 224 insertions(+) create mode 100644 PKG-INFO create mode 100644 machineout.py create mode 100644 nose_machineout.egg-info/PKG-INFO create mode 100644 nose_machineout.egg-info/SOURCES.txt create mode 100644 nose_machineout.egg-info/dependency_links.txt create mode 100644 nose_machineout.egg-info/entry_points.txt create mode 100644 nose_machineout.egg-info/not-zip-safe create mode 100644 nose_machineout.egg-info/requires.txt create mode 100644 nose_machineout.egg-info/top_level.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 test_machineout.py diff --git a/PKG-INFO b/PKG-INFO new file mode 100644 index 0000000..7237e4c --- /dev/null +++ b/PKG-INFO @@ -0,0 +1,19 @@ +Metadata-Version: 1.0 +Name: nose_machineout +Version: 0.2 +Summary: Changes output of the nose testing tool into format easily parsable by machine. +Home-page: http://maxischenko.in.ua/blog/entries/109/nose-vim-integration +Author: Max Ischenko +Author-email: ischenko@gmail.com +License: BSD +Download-URL: http://cheeseshop.python.org/pypi/nose_machineout/0.1 +Description: UNKNOWN +Keywords: test unittest nose +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Console +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: Python Software Foundation License +Classifier: Operating System :: POSIX +Classifier: Programming Language :: Python +Classifier: Topic :: Software Development diff --git a/machineout.py b/machineout.py new file mode 100644 index 0000000..c074e30 --- /dev/null +++ b/machineout.py @@ -0,0 +1,119 @@ + +""" +Formats nose output into format easily parsable by machine. + +It is intended to be use to integrate nose with your IDE such as Vim. + +@author: Max Ischenko +""" + +import re +import os +import os.path +import traceback +from nose.plugins import Plugin + +__all__ = ['NoseMachineReadableOutput'] + +try: + import doctest + doctest_fname = re.sub('\.py.?$', '.py', doctest.__file__) + del doctest +except ImportError: + doctest_fname = None + +class dummystream: + def write(self, *arg): + pass + def writeln(self, *arg): + pass + +def is_doctest_traceback(fname): + return fname == doctest_fname + +class PluginError(Exception): + def __repr__(self): + s = super(PluginError, self).__repr__() + return s + "\nReport bugs to ischenko@gmail.com." + +class NoseMachineReadableOutput(Plugin): + + """ + Output errors and failures in a machine-readable way. + """ + + name = 'machineout' + + 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): + 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.") + + def configure(self, options, conf): + super(NoseMachineReadableOutput, self).configure(options, conf) + self.enabled = options.machine_output + + def addSkip(self, test): + pass + + def addDeprecated(self, test): + pass + + def addError(self, test, err, capt): + self.addFormatted('error', err) + + def addFormatted(self, etype, err): + exctype, value, tb = err + fulltb = traceback.extract_tb(tb) + fname, lineno, funname, msg = fulltb[-1] + # explicit support for doctests is needed + if is_doctest_traceback(fname): + # doctest traceback includes pre-formatted error message + # which we parse (in a very crude way). + n = value.args[0].rindex('-'*20) + formatted_msg = value.args[0][n+20+1:] + m = self.doctest_failure_re.match(formatted_msg) + if not m: + raise RuntimeError("Can't parse doctest output: %r" % value.args[0]) + fname, lineno, funname, msg = m.groups() + if '.' in funname: # strip module package name, if any + funname = funname.split('.')[-1] + lineno = int(lineno) + lines = msg.split('\n') + msg0 = lines[0] + else: + lines = traceback.format_exception_only(exctype, value) + lines = [line.strip('\n') for line in lines] + msg0 = 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)) + if len(lines) > 1: + pad = ' '*(len(etype)+1) + for line in lines[1:]: + self.stream.writeln("%s: %s %s" % (prefix, pad, line)) + + def format_testfname(self, fname): + "Strips common path segments if any." + if fname.startswith(self.basepath): + return fname[len(self.basepath)+1:] + return fname + + def addFailure(self, test, err, capt, tb_info): + self.addFormatted('fail', err) + + def setOutputStream(self, stream): + # grab for own use + self.stream = stream + # return dummy stream to supress normal output + return dummystream() diff --git a/nose_machineout.egg-info/PKG-INFO b/nose_machineout.egg-info/PKG-INFO new file mode 100644 index 0000000..ffbaa44 --- /dev/null +++ b/nose_machineout.egg-info/PKG-INFO @@ -0,0 +1,19 @@ +Metadata-Version: 1.0 +Name: nose-machineout +Version: 0.2 +Summary: Changes output of the nose testing tool into format easily parsable by machine. +Home-page: http://maxischenko.in.ua/blog/entries/109/nose-vim-integration +Author: Max Ischenko +Author-email: ischenko@gmail.com +License: BSD +Download-URL: http://cheeseshop.python.org/pypi/nose_machineout/0.1 +Description: UNKNOWN +Keywords: test unittest nose +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Console +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: Python Software Foundation License +Classifier: Operating System :: POSIX +Classifier: Programming Language :: Python +Classifier: Topic :: Software Development diff --git a/nose_machineout.egg-info/SOURCES.txt b/nose_machineout.egg-info/SOURCES.txt new file mode 100644 index 0000000..957a1d9 --- /dev/null +++ b/nose_machineout.egg-info/SOURCES.txt @@ -0,0 +1,10 @@ +machineout.py +setup.py +test_machineout.py +nose_machineout.egg-info/PKG-INFO +nose_machineout.egg-info/SOURCES.txt +nose_machineout.egg-info/dependency_links.txt +nose_machineout.egg-info/entry_points.txt +nose_machineout.egg-info/not-zip-safe +nose_machineout.egg-info/requires.txt +nose_machineout.egg-info/top_level.txt diff --git a/nose_machineout.egg-info/dependency_links.txt b/nose_machineout.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/nose_machineout.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/nose_machineout.egg-info/entry_points.txt b/nose_machineout.egg-info/entry_points.txt new file mode 100644 index 0000000..55767e3 --- /dev/null +++ b/nose_machineout.egg-info/entry_points.txt @@ -0,0 +1,3 @@ +[nose.plugins] +machineout = machineout:NoseMachineReadableOutput + diff --git a/nose_machineout.egg-info/not-zip-safe b/nose_machineout.egg-info/not-zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/nose_machineout.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/nose_machineout.egg-info/requires.txt b/nose_machineout.egg-info/requires.txt new file mode 100644 index 0000000..ada25d6 --- /dev/null +++ b/nose_machineout.egg-info/requires.txt @@ -0,0 +1 @@ +nose>=0.9 \ No newline at end of file diff --git a/nose_machineout.egg-info/top_level.txt b/nose_machineout.egg-info/top_level.txt new file mode 100644 index 0000000..10b2550 --- /dev/null +++ b/nose_machineout.egg-info/top_level.txt @@ -0,0 +1,2 @@ +test_machineout +machineout diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..861a9f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..679bf1e --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +#from distutils import setup +from setuptools import setup + +setup( + name="nose_machineout", + version="0.2", + description="""\ +Changes output of the nose testing tool into format easily parsable by machine.""", + author="Max Ischenko", + author_email="ischenko@gmail.com", + url="http://maxischenko.in.ua/blog/entries/109/nose-vim-integration", + download_url="http://cheeseshop.python.org/pypi/nose_machineout/0.1", + install_requires = [ + "nose>=0.9", + ], + scripts = [], + license="BSD", + zip_safe=False, + py_modules=['machineout', 'test_machineout'], + entry_points = { + 'nose.plugins': ['machineout = machineout:NoseMachineReadableOutput'], + }, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Python Software Foundation License', + 'Operating System :: POSIX', + 'Programming Language :: Python', + 'Topic :: Software Development', + ], + keywords='test unittest nose', + test_suite = 'nose.collector') + diff --git a/test_machineout.py b/test_machineout.py new file mode 100644 index 0000000..3a574d3 --- /dev/null +++ b/test_machineout.py @@ -0,0 +1,10 @@ + +from machineout import * + +def doctest_enabled_function(): + """ + Run with nosetests -v --with-doctest --doctest-tests --machine-output + >>> 2 + 2 + 5 + """ + pass -- cgit v1.2.3