mirror of
https://github.com/saymrwulf/uhd.git
synced 2026-05-16 21:10:10 +00:00
- 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
20 lines
546 B
Python
20 lines
546 B
Python
#
|
|
# 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)
|