summaryrefslogtreecommitdiff
path: root/tests/test_detect.py
diff options
context:
space:
mode:
authorDave Hibberd <d@vehibberd.com>2023-10-16 21:37:34 +0100
committerDave Hibberd <d@vehibberd.com>2023-10-16 21:37:34 +0100
commit96e7558ee5db759a7214cd451a3478f3b44f59a3 (patch)
treee673aa5fb96256d43311c0e9581a2d5c6141ace6 /tests/test_detect.py
parenta289d9178e89abd7dc0fb29bdd6dedf3987b4f06 (diff)
parent91dbf844ad923e3c4bca1252dd104d8fc8ce5475 (diff)
Update upstream source from tag 'upstream/20231016'
Update to upstream version '20231016' with Debian dir cd57b3fbc431f25a1408f045533dcb7f7b9975c0
Diffstat (limited to 'tests/test_detect.py')
-rw-r--r--tests/test_detect.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_detect.py b/tests/test_detect.py
new file mode 100644
index 0000000..5a94cb9
--- /dev/null
+++ b/tests/test_detect.py
@@ -0,0 +1,42 @@
+import logging
+import sys
+from unittest import mock
+
+import pytest
+
+from chirp import directory
+from tests import base
+
+
+class TestCaseDetect(base.DriverTest):
+ def test_detect(self):
+ radio = directory.get_radio_by_image(self.TEST_IMAGE)
+ if hasattr(radio, '_orig_rclass'):
+ radio = radio._orig_rclass(self.TEST_IMAGE)
+ if isinstance(self.radio, radio.__class__):
+ # If we are a sub-device of the detected class then that's fine.
+ # There's no good way for us to know that other than checking, so
+ # the below assertion is just for show.
+ self.assertIsInstance(self.radio, radio.__class__)
+ else:
+ self.assertIsInstance(radio, self.RADIO_CLASS,
+ "Image %s detected as %s but expected %s" % (
+ self.TEST_IMAGE,
+ radio.__class__, self.RADIO_CLASS))
+
+ @pytest.mark.skipif(sys.version_info < (3, 10),
+ reason="requires python3.10 or higher")
+ @mock.patch('builtins.print')
+ def test_match_model_is_quiet_no_match(self, mock_print):
+ with self.assertNoLogs(level=logging.DEBUG):
+ self.radio.match_model(b'', 'foo.img')
+ mock_print.assert_not_called()
+
+ @pytest.mark.skipif(sys.version_info < (3, 10),
+ reason="requires python3.10 or higher")
+ @mock.patch('builtins.print')
+ def test_match_model_is_quiet_with_match(self, mock_print):
+ with self.assertNoLogs(level=logging.DEBUG):
+ with open(self.TEST_IMAGE, 'rb') as f:
+ self.radio.match_model(f.read(), self.TEST_IMAGE)
+ mock_print.assert_not_called()