aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/pyranges_test.py
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-06-10 01:09:33 +0200
committerAaron Rossetto <aaron.rossetto@ni.com>2020-06-15 13:49:36 -0500
commit5193d3f9494c977ac4694a1fc6fb0570ce6e92a7 (patch)
treea4ea929c8d4d0edc071cdded7f56e7c46b65929a /host/tests/pyranges_test.py
parentf1361234091036fdf7e599c9596151732cbb5683 (diff)
downloaduhd-5193d3f9494c977ac4694a1fc6fb0570ce6e92a7.tar.gz
uhd-5193d3f9494c977ac4694a1fc6fb0570ce6e92a7.tar.bz2
uhd-5193d3f9494c977ac4694a1fc6fb0570ce6e92a7.zip
tests: Add infrastructure to run Python unit tests
- Add UHD_ADD_PYTEST() CMake macro - Add CMake code to tests/CMakeLists.txt to auto-run all registered Python unit tests - Add a token unit test (it replicates parts of ranges_test.cpp) The way Python-based unit tests are implemented in UHD is that they can import uhd, and then operate on the module as usual. Writing unit tests in Python instead of C++ can have multiple advantages: - If they test PyBind-wrapped C++ code, they can test both the binding and the underlying C++ code at once - Writing unit tests in Python may be more concise
Diffstat (limited to 'host/tests/pyranges_test.py')
-rw-r--r--host/tests/pyranges_test.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/host/tests/pyranges_test.py b/host/tests/pyranges_test.py
new file mode 100644
index 000000000..17137e9f2
--- /dev/null
+++ b/host/tests/pyranges_test.py
@@ -0,0 +1,20 @@
+#
+# Copyright 2020 Ettus Research, a National Instruments Brand
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+"""
+Unit test for uhd.types.*Range
+"""
+
+import unittest
+import uhd
+
+class RangesTest(unittest.TestCase):
+ """ Test Python-wrapped ranges classes """
+ def test_meta_range(self):
+ """ Test MetaRange.clip() """
+ my_range = uhd.types.MetaRange(1.0, 10.0, 0.5)
+ self.assertEqual(my_range.clip(5.0), 5.0)
+ self.assertEqual(my_range.clip(11.0), 10.0)
+ self.assertEqual(my_range.clip(5.1, True), 5.0)