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_unittest.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_unittest.py')
-rw-r--r--[-rwxr-xr-x] | gnuradio-runtime/python/gnuradio/gr_unittest.py | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr_unittest.py b/gnuradio-runtime/python/gnuradio/gr_unittest.py index b20fa076de..1b8323ad7a 100755..100644 --- a/gnuradio-runtime/python/gnuradio/gr_unittest.py +++ b/gnuradio-runtime/python/gnuradio/gr_unittest.py @@ -22,10 +22,16 @@ """ GNU radio specific extension of unittest. """ +from __future__ import absolute_import +from __future__ import unicode_literals +from __future__ import division + +import os +import stat import unittest -import gr_xmlrunner -import sys, os, stat +from . import gr_xmlrunner + class TestCase(unittest.TestCase): """A subclass of unittest.TestCase that adds additional assertions @@ -43,11 +49,12 @@ class TestCase(unittest.TestCase): as significant digits (measured from the most significant digit). """ if round(second.real-first.real, places) != 0: - raise self.failureException, \ - (msg or '%s != %s within %s places' % (`first`, `second`, `places` )) + raise self.failureException( + msg or '%r != %r within %r places' % (first, second, places)) if round(second.imag-first.imag, places) != 0: - raise self.failureException, \ - (msg or '%s != %s within %s places' % (`first`, `second`, `places` )) + raise self.failureException( + msg or '%r != %r within %r places' % (first, second, places) + ) def assertComplexAlmostEqual2 (self, ref, x, abs_eps=1e-12, rel_eps=1e-6, msg=None): """ @@ -57,48 +64,52 @@ class TestCase(unittest.TestCase): return if abs(ref) > abs_eps: - if abs(ref-x)/abs(ref) > rel_eps: - raise self.failureException, \ - (msg or '%s != %s rel_error = %s rel_limit = %s' % ( - `ref`, `x`, abs(ref-x)/abs(ref), `rel_eps` )) + if abs(ref-x) / abs(ref) > rel_eps: + raise self.failureException( + msg or '%r != %r rel_error = %r rel_limit = %r' % ( + ref, x, abs(ref-x) / abs(ref), rel_eps + ) + ) else: - raise self.failureException, \ - (msg or '%s != %s rel_error = %s rel_limit = %s' % ( - `ref`, `x`, abs(ref-x)/abs(ref), `rel_eps` )) + raise self.failureException( + msg or '%r != %r rel_error = %r rel_limit = %r' % ( + ref, x, abs(ref-x) / abs(ref), rel_eps + ) + ) def assertComplexTuplesAlmostEqual (self, a, b, places=7, msg=None): self.assertEqual (len(a), len(b)) - for i in xrange (len(a)): + for i in range (len(a)): self.assertComplexAlmostEqual (a[i], b[i], places, msg) def assertComplexTuplesAlmostEqual2 (self, ref, x, abs_eps=1e-12, rel_eps=1e-6, msg=None): self.assertEqual (len(ref), len(x)) - for i in xrange (len(ref)): + for i in range (len(ref)): try: self.assertComplexAlmostEqual2 (ref[i], x[i], abs_eps, rel_eps, msg) - except self.failureException, e: + except self.failureException as e: #sys.stderr.write("index = %d " % (i,)) - #sys.stderr.write("%s\n" % (e,)) + #sys.stderr.write("%r\n" % (e,)) raise def assertFloatTuplesAlmostEqual (self, a, b, places=7, msg=None): self.assertEqual (len(a), len(b)) - for i in xrange (len(a)): + for i in range (len(a)): self.assertAlmostEqual (a[i], b[i], places, msg) def assertFloatTuplesAlmostEqual2 (self, ref, x, abs_eps=1e-12, rel_eps=1e-6, msg=None): self.assertEqual (len(ref), len(x)) - for i in xrange (len(ref)): + for i in range (len(ref)): try: self.assertComplexAlmostEqual2 (ref[i], x[i], abs_eps, rel_eps, msg) - except self.failureException, e: + except self.failureException as e: #sys.stderr.write("index = %d " % (i,)) - #sys.stderr.write("%s\n" % (e,)) + #sys.stderr.write("%r\n" % (e,)) raise @@ -124,7 +135,7 @@ def run(PUT, filename=None): path = basepath + "/python" if not os.path.exists(basepath): - os.makedirs(basepath, 0750) + os.makedirs(basepath, mode=0o750) xmlrunner = None # only proceed if .unittests is writable @@ -132,13 +143,13 @@ def run(PUT, filename=None): if(st & stat.S_IWUSR > 0): # Test if path exists; if not, build it if not os.path.exists(path): - os.makedirs(path, 0750) + os.makedirs(path, mode=0o750) # Just for safety: make sure we can write here, too st = os.stat(path)[stat.ST_MODE] if(st & stat.S_IWUSR > 0): # Create an XML runner to filename - fout = file(path+"/"+filename, "w") + fout = open(path+"/"+filename, "w") xmlrunner = gr_xmlrunner.XMLTestRunner(fout) txtrunner = TextTestRunner(verbosity=1) @@ -148,7 +159,7 @@ def run(PUT, filename=None): suite = TestLoader().loadTestsFromTestCase(PUT) # use the xmlrunner if we can write the the directory - if(xmlrunner is not None): + if xmlrunner is not None: xmlrunner.run(suite) main() |