summaryrefslogtreecommitdiff
path: root/tests/unit/test_directory.py
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2024-08-27 23:17:59 +0100
committerDave Hibberd <hibby@debian.org>2024-08-27 23:17:59 +0100
commitea5898c0bff9b0b52c87408027880f5d7049bdec (patch)
tree2d76776f577a99039e0618ae6d8d26014d7c8e8f /tests/unit/test_directory.py
parent0496ffac85e663ba4c9a14d2d4eb300a3c017ae2 (diff)
New upstream version 20240827upstream/20240827
Diffstat (limited to 'tests/unit/test_directory.py')
-rw-r--r--tests/unit/test_directory.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/unit/test_directory.py b/tests/unit/test_directory.py
index e60cb35..e9f1697 100644
--- a/tests/unit/test_directory.py
+++ b/tests/unit/test_directory.py
@@ -4,6 +4,7 @@ import json
import os
import shutil
import tempfile
+from unittest import mock
import yaml
@@ -143,3 +144,50 @@ class TestAliasMap(base.BaseTest):
# before we add it to ensure there are no duplicates
self.assertNotIn(model['model'], directory_models[vendor])
directory_models[vendor].add(model['model'])
+
+
+class TestDetectedBy(base.BaseTest):
+ @mock.patch('chirp.directory.DRV_TO_RADIO', new={})
+ @mock.patch('chirp.directory.RADIO_TO_DRV', new={})
+ def test_detected_isolation(self):
+ @directory.register
+ class BaseRadio(chirp_common.CloneModeRadio):
+ VENDOR = 'CHIRP'
+ MODEL = 'Base'
+
+ @directory.register
+ class SubRadio1(BaseRadio):
+ MODEL = 'Sub1'
+
+ @directory.register
+ @directory.detected_by(SubRadio1)
+ class SubRadio2(SubRadio1):
+ MODEL = 'Sub2'
+
+ # BaseRadio should not think it detects the subs
+ self.assertEqual([BaseRadio], BaseRadio.detected_models())
+
+ # Sub1 detects both itself and Sub2
+ self.assertEqual([SubRadio1, SubRadio2], SubRadio1.detected_models())
+
+ # If include_self=False, Sub1 should not include itself
+ self.assertEqual([SubRadio2],
+ SubRadio1.detected_models(include_self=False))
+
+ # Sub2 does not also detect Sub1
+ self.assertEqual([SubRadio2], SubRadio2.detected_models())
+
+ @mock.patch('chirp.directory.DRV_TO_RADIO', new={})
+ @mock.patch('chirp.directory.RADIO_TO_DRV', new={})
+ def test_detected_include_self(self):
+ class BaseRadio(chirp_common.CloneModeRadio):
+ VENDOR = 'CHIRP'
+ MODEL = 'Base'
+
+ @directory.register
+ @directory.detected_by(BaseRadio)
+ class SubRadio(BaseRadio):
+ MODEL = 'Sub'
+
+ # BaseRadio should not include itself since it is not registered
+ self.assertEqual([SubRadio], BaseRadio.detected_models())