From 841c4ebda14e6629db51b6f761ba7061f63a62d7 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Wed, 2 Oct 2024 14:32:51 -0700 Subject: [PATCH] Update detected models label generation and test --- chirp/wxui/clone.py | 12 ++++++++++-- tests/unit/test_wxui_radiothread.py | 12 +++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/chirp/wxui/clone.py b/chirp/wxui/clone.py index 2b19425c..817f584f 100644 --- a/chirp/wxui/clone.py +++ b/chirp/wxui/clone.py @@ -45,6 +45,15 @@ def is_prolific_warning(string): return 'PL2303' in string and 'CONTACT YOUR SUPPLIER' in string +def get_model_label(rclass): + detected = ','.join( + detected_value(rclass, m) + for m in rclass.detected_models(include_self=False)) + if len(detected) > (32 - 5): + detected = 'others' + return detected + + def get_fakes(): return { 'Fake NOP': developer.FakeSerial(), @@ -532,8 +541,7 @@ def _select_vendor(self, vendor): for rclass in self._vendors[vendor]: display = model_value(rclass) actual_models.append(display) - detected = ','.join(detected_value(rclass, x) for x in - rclass.detected_models(include_self=False)) + detected = get_model_label(rclass) if detected: display += ' (+ %s)' % detected display_models.append(display) diff --git a/tests/unit/test_wxui_radiothread.py b/tests/unit/test_wxui_radiothread.py index 02770341..18d08b56 100644 --- a/tests/unit/test_wxui_radiothread.py +++ b/tests/unit/test_wxui_radiothread.py @@ -164,15 +164,9 @@ def test_detected_model_labels(self): # be visible in the model box. for rclass in [x for x in directory.DRV_TO_RADIO.values() if issubclass(x, chirp_common.DetectableInterface)]: - labels = [] - for child_rclass in rclass.detected_models(include_self=False): - label = clone.detected_value(rclass, child_rclass) - self.assertNotEqual('', label) - labels.append(label) - if labels: - label = '%s (+ %s)' % (rclass.MODEL, ','.join(labels)) - self.assertLessEqual(len(label), 32, - 'Label %r is too long' % label) + label = clone.get_model_label(rclass) + self.assertLessEqual(len(label), 32, + 'Label %r is too long' % label) class TestException(Exception):