diff options
| author | Yogeswaran Umasankar <kd8mbd@gmail.com> | 2024-01-20 20:25:00 +0000 |
|---|---|---|
| committer | Yogeswaran Umasankar <kd8mbd@gmail.com> | 2024-01-20 20:25:00 +0000 |
| commit | e5ac17f663e108f458b5e3d34bfcc85b2d0482bc (patch) | |
| tree | 13f52b05b717ade7f8ba982ee1d910834067c0c6 /tests/unit | |
| parent | f5e142a4e54bfda24bec40e923c643b434948a04 (diff) | |
| parent | ac8027c43c9df4431092d633a06bd5bd92341247 (diff) | |
Update upstream source from tag 'upstream/1%20240117'
Update to upstream version '1:20240117'
with Debian dir 8d8fe4e002b178241b01b8f9b69615aa2480698f
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc | bin | 13541 -> 13846 bytes | |||
| -rw-r--r-- | tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc | bin | 28607 -> 31324 bytes | |||
| -rw-r--r-- | tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc | bin | 3082 -> 4770 bytes | |||
| -rw-r--r-- | tests/unit/test_bitwise.py | 21 | ||||
| -rw-r--r-- | tests/unit/test_chirp_common.py | 84 | ||||
| -rw-r--r-- | tests/unit/test_wxui_radiothread.py | 46 |
6 files changed, 145 insertions, 6 deletions
diff --git a/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc Binary files differindex 5066d3a..398ad6b 100644 --- a/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc Binary files differindex cd2beb0..3334195 100644 --- a/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc Binary files differindex bee4b94..1c758c2 100644 --- a/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/test_bitwise.py b/tests/unit/test_bitwise.py index 969622f..f150886 100644 --- a/tests/unit/test_bitwise.py +++ b/tests/unit/test_bitwise.py @@ -251,8 +251,8 @@ class TestBitwiseCharTypes(BaseTest): def test_string_get_raw(self): data = memmap.MemoryMapBytes(bytes(b"foobar")) obj = bitwise.parse("char foo[6];", data) - self.assertEqual('foobar', obj.foo.get_raw()) - self.assertEqual(b'foobar', obj.foo.get_raw(asbytes=True)) + self.assertEqual(b'foobar', obj.foo.get_raw()) + self.assertEqual('foobar', obj.foo.get_raw(asbytes=False)) class TestBitwiseStructTypes(BaseTest): @@ -283,15 +283,24 @@ class TestBitwiseStructTypes(BaseTest): data = memmap.MemoryMapBytes(bytes(b"..")) defn = "struct { u8 bar; u8 baz; } foo;" obj = bitwise.parse(defn, data) - self.assertEqual('..', obj.get_raw()) - self.assertEqual(b'..', obj.get_raw(asbytes=True)) + self.assertEqual(b'..', obj.get_raw()) + self.assertEqual('..', obj.get_raw(asbytes=False)) def test_struct_get_raw_small(self): data = memmap.MemoryMapBytes(bytes(b".")) defn = "struct { u8 bar; } foo;" obj = bitwise.parse(defn, data) - self.assertEqual('.', obj.get_raw()) - self.assertEqual(b'.', obj.get_raw(asbytes=True)) + self.assertEqual(b'.', obj.get_raw()) + self.assertEqual('.', obj.get_raw(asbytes=False)) + + def test_struct_set_raw(self): + data = memmap.MemoryMapBytes(bytes(b".")) + defn = "struct { u8 bar; } foo;" + obj = bitwise.parse(defn, data) + obj.set_raw(b'1') + self.assertEqual(b'1', data.get_packed()) + obj.set_raw('2') + self.assertEqual(b'2', data.get_packed()) class TestBitwiseSeek(BaseTest): diff --git a/tests/unit/test_chirp_common.py b/tests/unit/test_chirp_common.py index 30da2c7..fb880c9 100644 --- a/tests/unit/test_chirp_common.py +++ b/tests/unit/test_chirp_common.py @@ -821,6 +821,15 @@ class TestMemory(base.BaseTest): self.assertNotIsInstance(m, FrozenMemory) self.assertFalse(hasattr(m, '_frozen')) + def test_frozen_modifications(self): + orig = chirp_common.Memory(123) + orig.extra = [settings.RadioSetting( + 'foo', 'Foo', + settings.RadioSettingValueBoolean(False))] + frozen = chirp_common.FrozenMemory(orig) + with self.assertRaises(ValueError): + frozen.extra[0].value = True + def test_tone_validator(self): m = chirp_common.Memory() # 100.0 is a valid tone @@ -843,6 +852,81 @@ class TestMemory(base.BaseTest): with self.assertRaises(ValueError): m.ctone = 300.0 + def test_repr_dump(self): + m = chirp_common.Memory() + self.assertEqual( + "<Memory 0: freq=0,name='',vfo=0,rtone=88.5,ctone=88.5,dtcs=23," + "rx_dtcs=23,tmode='',cross_mode='Tone->Tone',dtcs_polarity='NN'," + "skip='',power=None,duplex='',offset=600000,mode='FM'," + "tuning_step=5.0,comment='',empty=False,immutable=[]>", repr(m)) + + m.freq = 146520000 + m.rtone = 107.2 + m.tmode = 'Tone' + self.assertEqual( + "<Memory 0: freq=146520000,name='',vfo=0,rtone=107.2,ctone=88.5," + "dtcs=23,rx_dtcs=23,tmode='Tone',cross_mode='Tone->Tone'," + "dtcs_polarity='NN',skip='',power=None,duplex='',offset=600000," + "mode='FM',tuning_step=5.0,comment='',empty=False,immutable=[]>", + repr(m)) + + m.number = 101 + m.extd_number = 'Call' + self.assertEqual( + "<Memory Call(101): freq=146520000,name='',vfo=0,rtone=107.2," + "ctone=88.5,dtcs=23,rx_dtcs=23,tmode='Tone'," + "cross_mode='Tone->Tone',dtcs_polarity='NN',skip='',power=None," + "duplex='',offset=600000,mode='FM',tuning_step=5.0,comment=''," + "empty=False,immutable=[]>", repr(m)) + + m.extra = settings.RadioSettingGroup('extra', 'Extra') + m.extra.append( + settings.RadioSetting('test1', 'Test Setting 1', + settings.RadioSettingValueBoolean(False))) + m.extra.append( + settings.RadioSetting('test2', 'Test Setting 2', + settings.RadioSettingValueList( + ['foo', 'bar'], 'foo'))) + self.assertEqual( + "<Memory Call(101): freq=146520000,name='',vfo=0,rtone=107.2," + "ctone=88.5,dtcs=23,rx_dtcs=23,tmode='Tone'," + "cross_mode='Tone->Tone',dtcs_polarity='NN',skip='',power=None," + "duplex='',offset=600000,mode='FM',tuning_step=5.0,comment=''," + "empty=False,immutable=[],extra.test1='False',extra.test2='foo'>", + repr(m)) + + def test_debug_diff(self): + m1 = chirp_common.Memory(1) + m2 = chirp_common.Memory(1) + + m1.freq = 146520000 + m2.freq = 446000000 + self.assertEqual('freq=146520000>446000000', m1.debug_diff(m2, '>')) + + m2.tmode = 'TSQL' + self.assertEqual("freq=146520000/446000000,tmode=''/'TSQL'", + m1.debug_diff(m2)) + + # Make sure ident diffs come first and are noticed + m2.number = 2 + m2.freq = 146520000 + self.assertEqual("ident=1/2,tmode=''/'TSQL'", m1.debug_diff(m2)) + + # Make sure we can diff extras, and amongst heterogeneous formats + m2.number = 1 + m1.extra = settings.RadioSettingGroup('extra', 'Extra') + m2.extra = settings.RadioSettingGroup('extra', 'Extra') + m1.extra.append( + settings.RadioSetting('test1', 'Test Setting 1', + settings.RadioSettingValueBoolean(False))) + m2.extra.append( + settings.RadioSetting('test2', 'Test Setting 2', + settings.RadioSettingValueList( + ['foo', 'bar'], 'foo'))) + self.assertEqual( + "extra.test1='False'/'<missing>',extra.test2='<missing>'/'foo'," + "tmode=''/'TSQL'", m1.debug_diff(m2)) + class TestRadioFeatures(base.BaseTest): def test_valid_tones(self): diff --git a/tests/unit/test_wxui_radiothread.py b/tests/unit/test_wxui_radiothread.py index 99f9438..1088b81 100644 --- a/tests/unit/test_wxui_radiothread.py +++ b/tests/unit/test_wxui_radiothread.py @@ -3,10 +3,17 @@ import time from unittest import mock sys.modules['wx'] = wx = mock.MagicMock() +sys.modules['wx.lib'] = mock.MagicMock() +sys.modules['wx.lib.scrolledpanel'] = mock.MagicMock() +sys.modules['wx.lib.sized_controls'] = mock.MagicMock() +sys.modules['wx.richtext'] = mock.MagicMock() +wx.lib.newevent.NewCommandEvent.return_value = None, None +sys.modules['chirp.wxui.developer'] = mock.MagicMock() # These need to be imported after the above mock so that we don't require # wx to be present for these tests from tests.unit import base # noqa +from chirp.wxui import clone # noqa from chirp.wxui import radiothread # noqa @@ -105,3 +112,42 @@ class TestRadioThread(base.BaseTest): radio.set_memory.assert_not_called() radio.get_features.assert_not_called() wx.PostEvent.assert_not_called() + + +class TestClone(base.BaseTest): + @mock.patch('platform.system', return_value='Linux') + def test_sort_ports_unix(self, system): + ports = [ + mock.MagicMock(device='/dev/cu.zed', + description='My Zed'), + mock.MagicMock(device='/dev/cu.abc', + description='Some device'), + mock.MagicMock(device='/dev/cu.serial', + description='') + ] + self.assertEqual( + ['Some device (cu.abc)', + 'cu.serial', + 'My Zed (cu.zed)'], + [clone.port_label(p) + for p in sorted(ports, key=clone.port_sort_key)]) + + @mock.patch('platform.system', return_value='Windows') + def test_sort_ports_windows(self, system): + ports = [ + mock.MagicMock(device='COM7', + description='Some serial device'), + mock.MagicMock(device='COM17', + description='Some other device'), + mock.MagicMock(device='CNC0', + description='Some weird device'), + mock.MagicMock(device='COM4', + description=''), + ] + self.assertEqual( + ['CNC0: Some weird device', + 'COM4', + 'COM7: Some serial device', + 'COM17: Some other device'], + [clone.port_label(p) + for p in sorted(ports, key=clone.port_sort_key)]) |
