diff options
| author | Dave Hibberd <hibby@debian.org> | 2024-08-27 23:18:08 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2024-08-27 23:18:08 +0100 |
| commit | ddbe8d4b718c0d61a83c48c0b8e45f994254798b (patch) | |
| tree | f12d25b28cc3c0695a28c75a1ff9512a59544dab /tests/unit/test_directory.py | |
| parent | 12882a24180aa2deb5f091b7890ed9e2ae01a9c1 (diff) | |
| parent | ea5898c0bff9b0b52c87408027880f5d7049bdec (diff) | |
Update upstream source from tag 'upstream/20240827'
Update to upstream version '20240827'
with Debian dir f9522178f68ff440c5c82cf36271e1e1235ba8d4
Diffstat (limited to 'tests/unit/test_directory.py')
| -rw-r--r-- | tests/unit/test_directory.py | 48 |
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()) |
