File: test_settings.py

package info (click to toggle)
chirp 1%3A20251108-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,728 kB
  • sloc: python: 156,369; ansic: 296; sh: 219; xml: 24; makefile: 19
file content (63 lines) | stat: -rw-r--r-- 2,400 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from chirp import chirp_common
from chirp import settings
from tests import base


class TestCaseSettings(base.DriverTest):
    def test_has_settings(self):
        return
        settings = self.radio.get_settings()
        if settings:
            self.assertFalse(self.rf.has_settings,
                             'Radio returned settings but has_settings=False')
        else:
            self.assertTrue(self.rf.has_settings,
                            'Radio returned no settings but has_settings=True')

    @base.requires_feature('has_settings')
    def test_get_settings(self):
        lst = self.radio.get_settings()
        self.assertIsInstance(lst, list)

    @base.requires_feature('has_settings')
    def test_same_settings(self):
        o = self.radio.get_settings()
        self.radio.set_settings(o)
        n = self.radio.get_settings()
        list(map(self.compare_settings, o, n))

    def compare_settings(self, a, b):
        try:
            if isinstance(a, settings.RadioSettingValue):
                raise StopIteration
            list(map(self.compare_settings, a, b))
        except StopIteration:
            self.assertEqual(a.get_value(), b.get_value(),
                             'Setting value changed from %r to %r' % (
                                 a.get_value(), b.get_value()))
        except Exception as e:
            print('Failed %s on %s' % (e, a.get_name()))
            raise

    def test_memory_extra_frozen(self):
        # Find the first non-empty memory and try to set it back as a
        # FrozenMemory to make sure the driver does not try to modify
        # any of the settings.
        for i in range(*self.rf.memory_bounds):
            m = self.radio.get_memory(i)
            if not m.empty:
                self.radio.set_memory(chirp_common.FrozenMemory(m))
                break

    def test_memory_extra_flat(self):
        for i in range(*self.rf.memory_bounds):
            m = self.radio.get_memory(i)
            if not m.empty:
                self.assertIsInstance(
                    m.extra,
                    (list, settings.RadioSettingGroup),
                    'mem.extra must be a list or RadioSettingGroup')
                for e in m.extra:
                    self.assertIsInstance(
                        e, settings.RadioSetting,
                        'mem.extra items must be RadioSetting objects')