commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/03: runtime: stop catching errors from p


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/03: runtime: stop catching errors from primitive_connect in connect decorator
Date: Wed, 29 Jul 2015 17:30:19 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch maint
in repository gnuradio.

commit 623f96357c79b36dc49f66dee56284d5f41a822e
Author: Sebastian Koslowski <address@hidden>
Date:   Mon Jul 27 16:45:09 2015 +0200

    runtime: stop catching errors from primitive_connect in connect decorator
---
 gnuradio-runtime/python/gnuradio/gr/hier_block2.py | 25 +++++++++++-----------
 .../python/gnuradio/gr/qa_hier_block2.py           | 12 ++++++-----
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/gnuradio-runtime/python/gnuradio/gr/hier_block2.py 
b/gnuradio-runtime/python/gnuradio/gr/hier_block2.py
index 3bc1e2e..3f4c6aa 100644
--- a/gnuradio-runtime/python/gnuradio/gr/hier_block2.py
+++ b/gnuradio-runtime/python/gnuradio/gr/hier_block2.py
@@ -19,15 +19,14 @@
 # Boston, MA 02110-1301, USA.
 #
 
-from functools import wraps
-from itertools import imap
+import functools
 
 from runtime_swig import hier_block2_swig, dot_graph
 import pmt
 
 
 def _multiple_endpoints(func):
-    @wraps(func)
+    @functools.wraps(func)
     def wrapped(self, *points):
         if not points:
             raise ValueError("At least one block required for " + 
func.__name__)
@@ -39,24 +38,24 @@ def _multiple_endpoints(func):
             func(self, block)
         else:
             try:
-                endp = [(p, 0) if hasattr(p, 'to_basic_block') else p for p in 
points]
-                endp_pairs = imap(lambda i: endp[i:i+2], range(len(endp)-1))
-                for (src, src_port), (dst, dst_port) in endp_pairs:
-                    func(self, src.to_basic_block(), src_port,
-                         dst.to_basic_block(), dst_port)
-            except (ValueError, TypeError):
-                raise ValueError("Unable to coerce endpoint")
+                endp = [(p.to_basic_block(), 0) if hasattr(p, 'to_basic_block')
+                        else (p[0].to_basic_block(), p[1]) for p in points]
+            except (ValueError, TypeError, AttributeError) as err:
+                raise ValueError("Unable to coerce endpoints: " + str(err))
+
+            for (src, src_port), (dst, dst_port) in zip(endp, endp[1:]):
+                func(self, src, src_port, dst, dst_port)
     return wrapped
 
 
 def _optional_endpoints(func):
-    @wraps(func)
+    @functools.wraps(func)
     def wrapped(self, src, srcport, dst=None, dstport=None):
         if dst is None and dstport is None:
             try:
                 (src, srcport), (dst, dstport) = src, srcport
-            except (ValueError, TypeError):
-                raise ValueError("Unable to coerce endpoint")
+            except (ValueError, TypeError) as err:
+                raise ValueError("Unable to coerce endpoints: " + str(err))
         func(self, src.to_basic_block(), srcport, dst.to_basic_block(), 
dstport)
     return wrapped
 
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py 
b/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py
index 50b1562..a079f8d 100644
--- a/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py
@@ -66,14 +66,12 @@ class test_hier_block2(gr_unittest.TestCase):
         self.assertEqual(expected, self.call_log)
 
     def test_005(self):
-        with self.assertRaises(ValueError) as c:
+        with self.assertRaises(ValueError):
             self.multi((self.Block(), 5))
-        self.assertIsInstance(c.exception, ValueError)
 
     def test_006(self):
-        with self.assertRaises(ValueError) as c:
-            self.multi(self.Block(), (self.Block(), 5, 5))
-        self.assertIsInstance(c.exception, ValueError)
+        with self.assertRaises(ValueError):
+            self.multi(self.Block(), (5, 5))
 
     def test_007(self):
         b1, b2 = self.Block(), self.Block()
@@ -85,6 +83,10 @@ class test_hier_block2(gr_unittest.TestCase):
         self.opt((b1, "in"), (b2, "out"))
         self.assertEqual([(b1, "in", b2, "out")], self.call_log)
 
+    def test_009(self):
+        with self.assertRaises(ValueError):
+            self.multi(self.Block(), 5)
+
 
 if __name__ == '__main__':
     gr_unittest.run(test_hier_block2, "test_hier_block2.xml")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]