[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 15/22: runtime: add tests for new decorator
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 15/22: runtime: add tests for new decorators in hier_block2 |
Date: |
Tue, 23 Dec 2014 09:38:58 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 0356a8df991f04922c4e112a5ce16155221127c1
Author: Sebastian Koslowski <address@hidden>
Date: Thu Dec 11 17:42:03 2014 +0100
runtime: add tests for new decorators in hier_block2
---
gnuradio-runtime/python/gnuradio/gr/hier_block2.py | 74 ++++++++++--------
.../python/gnuradio/gr/qa_hier_block2.py | 91 ++++++++++++++++++++++
gnuradio-runtime/python/gnuradio/gr/top_block.py | 38 ++++-----
3 files changed, 151 insertions(+), 52 deletions(-)
diff --git a/gnuradio-runtime/python/gnuradio/gr/hier_block2.py
b/gnuradio-runtime/python/gnuradio/gr/hier_block2.py
index 602e5f7..3bc1e2e 100644
--- a/gnuradio-runtime/python/gnuradio/gr/hier_block2.py
+++ b/gnuradio-runtime/python/gnuradio/gr/hier_block2.py
@@ -1,46 +1,51 @@
-"""
-Copyright 2006, 2007, 2014 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
+#
+# Copyright 2006,2007,2014 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
from functools import wraps
+from itertools import imap
from runtime_swig import hier_block2_swig, dot_graph
import pmt
def _multiple_endpoints(func):
- def coerce_endpoint(endp, default_port=0):
- if hasattr(endp, 'to_basic_block'):
- return endp.to_basic_block(), default_port
- try:
- block, port = endp
- return block.to_basic_block(), port
- except ValueError:
- raise ValueError("unable to coerce endpoint")
@wraps(func)
def wrapped(self, *points):
if not points:
- raise ValueError("At least one endpoint required for " +
func.__name__)
+ raise ValueError("At least one block required for " +
func.__name__)
elif len(points) == 1:
- func(points[0].to_basic_block())
+ try:
+ block = points[0].to_basic_block()
+ except AttributeError:
+ raise ValueError("At least two endpoints required for " +
func.__name__)
+ func(self, block)
else:
- for src, dst in map(lambda i: points[i:i + 2], range(len(points) -
1)):
- func(self, *(coerce_endpoint(src) + coerce_endpoint(dst)))
+ 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")
return wrapped
@@ -48,10 +53,11 @@ def _optional_endpoints(func):
@wraps(func)
def wrapped(self, src, srcport, dst=None, dstport=None):
if dst is None and dstport is None:
- (src, srcport), (dst, dstport) = src, srcport
- return func(self,
- src.to_basic_block(), srcport,
- dst.to_basic_block(), dstport)
+ try:
+ (src, srcport), (dst, dstport) = src, srcport
+ except (ValueError, TypeError):
+ raise ValueError("Unable to coerce endpoint")
+ 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
new file mode 100644
index 0000000..50b1562
--- /dev/null
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py
@@ -0,0 +1,91 @@
+#
+# Copyright 2014 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr_unittest
+from gnuradio.gr.hier_block2 import _multiple_endpoints, _optional_endpoints
+
+
+class test_hier_block2(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.call_log = []
+ self.Block = type("Block", (), {"to_basic_block": lambda bl: bl})
+
+ def test_f(self, *args):
+ """test doc"""
+ self.call_log.append(args)
+
+ multi = _multiple_endpoints(test_f)
+ opt = _optional_endpoints(test_f)
+
+ def test_000(self):
+ self.assertEqual(self.multi.__doc__, "test doc")
+ self.assertEqual(self.multi.__name__, "test_f")
+
+ def test_001(self):
+ b = self.Block()
+ self.multi(b)
+ self.assertEqual((b,), self.call_log[0])
+
+ def test_002(self):
+ b1, b2 = self.Block(), self.Block()
+ self.multi(b1, b2)
+ self.assertEqual([(b1, 0, b2, 0)], self.call_log)
+
+ def test_003(self):
+ b1, b2 = self.Block(), self.Block()
+ self.multi((b1, 1), (b2, 2))
+ self.assertEqual([(b1, 1, b2, 2)], self.call_log)
+
+ def test_004(self):
+ b1, b2, b3, b4 = [self.Block()] * 4
+ self.multi(b1, (b2, 5), b3, (b4, 0))
+ expected = [
+ (b1, 0, b2, 5),
+ (b2, 5, b3, 0),
+ (b3, 0, b4, 0),
+ ]
+ self.assertEqual(expected, self.call_log)
+
+ def test_005(self):
+ with self.assertRaises(ValueError) as c:
+ 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)
+
+ def test_007(self):
+ b1, b2 = self.Block(), self.Block()
+ self.opt(b1, "in", b2, "out")
+ self.assertEqual([(b1, "in", b2, "out")], self.call_log)
+
+ def test_008(self):
+ f, b1, b2 = self.multi, self.Block(), self.Block()
+ self.opt((b1, "in"), (b2, "out"))
+ self.assertEqual([(b1, "in", b2, "out")], self.call_log)
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_hier_block2, "test_hier_block2.xml")
+
diff --git a/gnuradio-runtime/python/gnuradio/gr/top_block.py
b/gnuradio-runtime/python/gnuradio/gr/top_block.py
index 8d81065..f9872fc 100644
--- a/gnuradio-runtime/python/gnuradio/gr/top_block.py
+++ b/gnuradio-runtime/python/gnuradio/gr/top_block.py
@@ -1,21 +1,23 @@
-"""
-Copyright 2007, 2014 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
+#
+# Copyright 2007,2014 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
from runtime_swig import top_block_swig, \
top_block_wait_unlocked, top_block_run_unlocked, \
- [Commit-gnuradio] [gnuradio] branch master updated (3427a66 -> 2402ccc), git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 07/22: grc: per element line styles (for custom domain ports and message connections), git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 08/22: grc: add gr_message domain, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 12/22: grc: port connections by domain, block name in generated code, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 10/22: grc: add multiple_sources flag to domain.dtd, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 13/22: runtime: whitespace fixes, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 15/22: runtime: add tests for new decorators in hier_block2,
git <=
- [Commit-gnuradio] [gnuradio] 14/22: runtime: refactor top/hier block python wrappers, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 17/22: grc: fix connections error log and color, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 11/22: grc: PEP8 fixes in Generator, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 16/22: grc: add domain property color and use it for connections, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 06/22: grc: domain-specific port keys, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 09/22: grc: make Generator use gr_message domain, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 03/22: grc: draw ports with custom domain differently, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 22/22: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 04/22: grc: don't fail for unknown domains, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 19/22: Merge branch 'port_domains' into master_grcwg, git, 2014/12/23