diff options
-rw-r--r-- | host/cmake/Modules/UHDUnitTest.cmake | 12 | ||||
-rw-r--r-- | host/tests/CMakeLists.txt | 17 | ||||
-rw-r--r-- | host/tests/pyranges_test.py | 20 |
3 files changed, 49 insertions, 0 deletions
diff --git a/host/cmake/Modules/UHDUnitTest.cmake b/host/cmake/Modules/UHDUnitTest.cmake index 9a71ca2aa..f1f52addc 100644 --- a/host/cmake/Modules/UHDUnitTest.cmake +++ b/host/cmake/Modules/UHDUnitTest.cmake @@ -104,3 +104,15 @@ function(UHD_ADD_TEST test_name) endif(WIN32) endfunction(UHD_ADD_TEST) + +######################################################################## +# Add a Python unit test +######################################################################## +function(UHD_ADD_PYTEST test_name) + add_test(NAME ${test_name} + COMMAND ${RUNTIME_PYTHON_EXECUTABLE} -m unittest discover + -s ${CMAKE_CURRENT_SOURCE_DIR} + -p "${test_name}.*" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/python" + ) +endfunction(UHD_ADD_PYTEST) diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 6207987ef..bc0ff8b3b 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -64,6 +64,12 @@ set(test_sources multichan_register_iface_test.cpp ) +# Note: Python-based tests cannot have the same name as a C++-based test (i.e., +# only differ in the cpp/py file extension). If in doubt, prepend 'py' +set(pytest_sources + pyranges_test.py +) + #turn each test cpp file into an executable with an int main() function add_definitions(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) @@ -98,6 +104,17 @@ foreach(benchmark_source ${benchmark_sources}) UHD_INSTALL(TARGETS ${benchmark_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/tests COMPONENT tests) endforeach(benchmark_source) +if(ENABLE_PYTHON_API) + foreach(test_source ${pytest_sources}) + get_filename_component(test_name ${test_source} NAME_WE) + UHD_ADD_PYTEST(${test_name}) + endforeach(test_source) + UHD_INSTALL(FILES ${pytest_sources} + DESTINATION ${PKG_LIB_DIR}/tests + COMPONENT tests + ) +endif(ENABLE_PYTHON_API) + ############################################################################### # Add a unit test that requires linkage to internal parts of UHD which are not # API 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) |