diff options
author | Andrej Rode <mail@andrejro.de> | 2018-06-23 23:41:42 +0200 |
---|---|---|
committer | Andrej Rode <mail@andrejro.de> | 2018-06-24 00:03:35 +0200 |
commit | 167a6152bad060fc53dd29e0fa79ef83eff1be5b (patch) | |
tree | a01049672d9d7d1bf3d295ed96698a323941f8e8 /gnuradio-runtime/python/gnuradio/gr_xmlrunner.py | |
parent | 3c8e6008b092287246234001db7cf1a4038300da (diff) | |
parent | fcd002b6ac82e1e0c1224e24506410ff0833e1aa (diff) |
Merge branch 'python3_fix' into next
Manual merge conflict resolution has been applied to following
conflicts:
* Typos:
* gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py
* gr-blocks/python/blocks/qa_wavfile.py
* gr-filter/examples/gr_filtdes_api.py
* grc/blocks/parameter.xml
* gr-uhd/python/uhd/__init__.py
* ValueError -> RuntimeError:
* gr-blocks/python/blocks/qa_hier_block2.py
* relative Imports & other Py3k:
* gr-digital/python/digital/psk_constellations.py
* gr-digital/python/digital/qam_constellations.py
* gr-digital/python/digital/test_soft_decisions.py
* gr-digital/python/digital/gfsk.py
* SequenceCompleter:
* gr-utils/python/modtool/modtool_add.py
* gr-utils/python/modtool/modtool_rename.py
* gr-utils/python/modtool/modtool_rm.py
* Updated API on next:
* gr-blocks/grc/blocks_file_source.xml
* gr-blocks/python/blocks/qa_file_source_sink.py
* gr-qtgui/grc/qtgui_time_sink_x.xml
* GRC Py3k Updates:
* grc/core/Block.py
* grc/core/Constants.py
* grc/core/Platform.py
* grc/core/utils/odict.py
* grc/gui/Actions.py
* grc/gui/Block.py
* grc/gui/Executor.py
* grc/gui/Port.py
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/gr_xmlrunner.py')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr_xmlrunner.py | 86 |
1 files changed, 60 insertions, 26 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr_xmlrunner.py b/gnuradio-runtime/python/gnuradio/gr_xmlrunner.py index 31298197ff..fccb1b76f0 100644 --- a/gnuradio-runtime/python/gnuradio/gr_xmlrunner.py +++ b/gnuradio-runtime/python/gnuradio/gr_xmlrunner.py @@ -1,25 +1,56 @@ """ XML Test Runner for PyUnit """ - # Written by Sebastian Rittau <srittau@jroger.in-berlin.de> and placed in # the Public Domain. With contributions by Paolo Borelli and others. # Added to GNU Radio Oct. 3, 2010 -__version__ = "0.1" +from __future__ import unicode_literals import os.path import re import sys import time -import traceback import unittest +import linecache from xml.sax.saxutils import escape +from io import StringIO + + +__version__ = "0.1" -try: - from StringIO import StringIO -except ImportError: - from io import StringIO + +# inline trackeback.print_tb so that py2 uses unicode literals (py2/3 compat) +def print_tb(tb, limit=None, out=None): + """Print up to 'limit' stack trace entries from the traceback 'tb'. + + If 'limit' is omitted or None, all entries are printed. If 'file' + is omitted or None, the output goes to sys.stderr; otherwise + 'file' should be an open file or file-like object with a write() + method. + """ + def _print(out, s='', terminator='\n'): + out.write(s+terminator) + + if out is None: + out = sys.stderr + if limit is None: + if hasattr(sys, 'tracebacklimit'): + limit = sys.tracebacklimit + n = 0 + while tb is not None and (limit is None or n < limit): + f = tb.tb_frame + lineno = tb.tb_lineno + co = f.f_code + filename = co.co_filename + name = co.co_name + _print(out, ' Out "%s", line %d, in %s' % (filename, lineno, name)) + linecache.checkcache(filename) + line = linecache.getline(filename, lineno, f.f_globals) + if line: + _print(out, ' ' + line.strip()) + tb = tb.tb_next + n = n+1 class _TestInfo(object): @@ -60,12 +91,12 @@ class _TestInfo(object): supplied stream. """ - stream.write(' <testcase classname="%(class)s" name="%(method)s" time="%(time).4f">' % \ - { - "class": self._class, - "method": self._method, - "time": self._time, - }) + stream.write(' <testcase classname="%(class)s" name="%(method)s" time="%(time).4f">' % + { + 'class': self._class, + 'method': self._method, + 'time': self._time, + }) if self._failure is not None: self._print_error(stream, 'failure', self._failure) if self._error is not None: @@ -76,10 +107,10 @@ class _TestInfo(object): """Print information from a failure or error to the supplied stream.""" text = escape(str(error[1])) stream.write('\n') - stream.write(' <%s type="%s">%s\n' \ - % (tagname, _clsname(error[0]), text)) + stream.write(' <%s type="%s">%s\n' + % (tagname, _clsname(error[0]), text)) tb_stream = StringIO() - traceback.print_tb(error[2], None, tb_stream) + print_tb(error[2], None, tb_stream) stream.write(escape(tb_stream.getvalue())) stream.write(' </%s>\n' % tagname) stream.write(' ') @@ -137,14 +168,17 @@ class _XMLTestResult(unittest.TestResult): output and standard error streams must be passed in.a """ - stream.write('<testsuite errors="%(e)d" failures="%(f)d" ' % \ - { "e": len(self.errors), "f": len(self.failures) }) - stream.write('name="%(n)s" tests="%(t)d" time="%(time).3f">\n' % \ - { - "n": self._test_name, - "t": self.testsRun, - "time": time_taken, - }) + stream.write('<testsuite errors="%(e)d" failures="%(f)d" ' % + { + "e": len(self.errors), + "f": len(self.failures) + }) + stream.write('name="%(n)s" tests="%(t)d" time="%(time).3f">\n' % + { + "n": self._test_name, + "t": self.testsRun, + "time": time_taken + }) for info in self._tests: info.print_report(stream) stream.write(' <system-out><![CDATA[%s]]></system-out>\n' % out) @@ -173,9 +207,9 @@ class XMLTestRunner(object): """Run the given test case or test suite.""" class_ = test.__class__ classname = class_.__module__ + "." + class_.__name__ - if self._stream == None: + if self._stream is None: filename = "TEST-%s.xml" % classname - stream = file(os.path.join(self._path, filename), "w") + stream = open(os.path.join(self._path, filename), "w") stream.write('<?xml version="1.0" encoding="utf-8"?>\n') else: stream = self._stream |