aboutsummaryrefslogtreecommitdiffstats
path: root/mpm
diff options
context:
space:
mode:
authorToni Jones <toni.jones@ni.com>2019-04-03 13:24:06 -0500
committerMartin Braun <martin.braun@ettus.com>2019-04-11 09:11:43 -0700
commit3642ac013e9b7eaf7d454790c6a1c7387b0238c4 (patch)
tree3d66d0c10d20c5078745b3bd11ae517388b58e91 /mpm
parentf93c5227bd4c6b6d86c16c28c309c7b20be977bf (diff)
downloaduhd-3642ac013e9b7eaf7d454790c6a1c7387b0238c4.tar.gz
uhd-3642ac013e9b7eaf7d454790c6a1c7387b0238c4.tar.bz2
uhd-3642ac013e9b7eaf7d454790c6a1c7387b0238c4.zip
mpm: Generalize unittest Test Case functionality
Pull some general functionality out of a specific test case and create a TestBase class. Future test cases will inherit from TestBase and have access to this general functionality.
Diffstat (limited to 'mpm')
-rwxr-xr-xmpm/python/tests/base_tests.py43
-rwxr-xr-xmpm/python/tests/sys_utils_tests.py40
2 files changed, 50 insertions, 33 deletions
diff --git a/mpm/python/tests/base_tests.py b/mpm/python/tests/base_tests.py
new file mode 100755
index 000000000..ec4b8328a
--- /dev/null
+++ b/mpm/python/tests/base_tests.py
@@ -0,0 +1,43 @@
+#
+# Copyright 2019 Ettus Research, a National Instruments Brand
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+"""
+Base Test Case classes
+"""
+
+import platform
+import unittest
+
+class TestBase(unittest.TestCase):
+ """
+ Base Test Case class which contains commonly required functionality
+ """
+ def skipUnlessOnLinux():
+ """
+ Test function decorator which skips tests unless the current
+ execution environment is a linux OS.
+ """
+ if 'linux' in platform.system().lower():
+ return lambda func: func
+ return unittest.skip("This test is only valid when run on a Linux system.")
+
+ def skipUnlessOnUsrp():
+ """
+ Test function decorator which skips tests unless the current
+ execution environment is a USRP.
+
+ Assumes that 'arm' in the machine name constitutes an ARM
+ processor, aka a USRP.
+ """
+ if 'arm' in platform.machine().lower():
+ return lambda func: func
+ return unittest.skip("This test is only valid when run on the USRP.")
+
+ def set_device_name(self, device_name):
+ """
+ Stores a device name attribute for tests whose success condition
+ depends on the current device.
+ """
+ self.device_name = device_name
diff --git a/mpm/python/tests/sys_utils_tests.py b/mpm/python/tests/sys_utils_tests.py
index fc0ae33a1..c21cfea07 100755
--- a/mpm/python/tests/sys_utils_tests.py
+++ b/mpm/python/tests/sys_utils_tests.py
@@ -7,11 +7,13 @@
Tests related to usrp_mpm.sys_utils
"""
-import platform
+from base_tests import TestBase
import unittest
from usrp_mpm.sys_utils import net
+import platform
-class TestNet(unittest.TestCase):
+
+class TestNet(TestBase):
"""
Tests multiple functions defined in usrp_mpm.sys_utils.net.
@@ -20,34 +22,6 @@ class TestNet(unittest.TestCase):
For tests run on the USRP, it is assumed that the device has at
least an active RJ-45 (eth0) connection.
"""
- def skipUnlessOnLinux():
- """
- Test function decorator which skips tests unless the current
- execution environment is a linux OS.
- """
- if 'linux' in platform.system().lower():
- return lambda func: func
- return unittest.skip("This test is only valid when run on a Linux system.")
-
- def skipUnlessOnUsrp():
- """
- Test function decorator which skips tests unless the current
- execution environment is a USRP.
-
- Assumes that 'arm' in the machine name constitutes an ARM
- processor, aka a USRP.
- """
- if 'arm' in platform.machine().lower():
- return lambda func: func
- return unittest.skip("This test is only valid when run on the USRP.")
-
- def set_device_name(self, device_name):
- """
- Stores a device name attribute for tests whose success condition
- depends on the current device.
- """
- self.device_name = device_name
-
def test_get_hostname(self):
"""
Test net.get_hostname() returns the same value as
@@ -57,7 +31,7 @@ class TestNet(unittest.TestCase):
expected_hostname = platform.node()
self.assertEqual(expected_hostname, net.get_hostname())
- @skipUnlessOnUsrp()
+ @TestBase.skipUnlessOnUsrp()
def test_get_valid_interfaces(self):
"""
Test that expected network interfaces are returned as valid
@@ -75,7 +49,7 @@ class TestNet(unittest.TestCase):
resulting_valid_ifaces = net.get_valid_interfaces(all_ifaces)
self.assertEqual(expected_valid_ifaces, resulting_valid_ifaces)
- @skipUnlessOnUsrp()
+ @TestBase.skipUnlessOnUsrp()
def test_get_iface_info(self):
"""
Tests the get_iface_info function.
@@ -104,7 +78,7 @@ class TestNet(unittest.TestCase):
# Verify that an unknown interface throws a LookupError
self.assertRaises(LookupError, net.get_iface_info, unknown_name)
- @skipUnlessOnUsrp()
+ @TestBase.skipUnlessOnUsrp()
def test_get_link_speed(self):
"""
Tests that the link speed of 'eth0' is the expected 1GB and that