summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python/gnuradio/gr_unittest.py
diff options
context:
space:
mode:
authorMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
committerMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
commit254fe5e89403d4de1fa6663d09efdf946996aff3 (patch)
tree62877d7ac7fdedf6c397c51e22ac6f97eba97ddf /gnuradio-runtime/python/gnuradio/gr_unittest.py
parent896d1c9da31963ecf5b0d90942c2af51ca998a69 (diff)
parent5ad935c3a3dd46ce2860b13e2b774e4841784616 (diff)
Merge remote-tracking branch 'origin/next' into merge_next
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/gr_unittest.py')
-rw-r--r--[-rwxr-xr-x]gnuradio-runtime/python/gnuradio/gr_unittest.py63
1 files changed, 37 insertions, 26 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr_unittest.py b/gnuradio-runtime/python/gnuradio/gr_unittest.py
index 49d1189635..190ea63354 100755..100644
--- a/gnuradio-runtime/python/gnuradio/gr_unittest.py
+++ b/gnuradio-runtime/python/gnuradio/gr_unittest.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2004,2010 Free Software Foundation, Inc.
+# Copyright 2004,2010,2018 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -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):
@@ -44,11 +50,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):
"""
@@ -58,48 +65,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
@@ -126,7 +137,7 @@ def run(PUT, filename=None, verbosity=1):
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
@@ -134,13 +145,13 @@ def run(PUT, filename=None, verbosity=1):
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=verbosity)
@@ -150,7 +161,7 @@ def run(PUT, filename=None, verbosity=1):
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(verbosity=verbosity)