From ac8027c43c9df4431092d633a06bd5bd92341247 Mon Sep 17 00:00:00 2001 From: Yogeswaran Umasankar Date: Sat, 20 Jan 2024 20:24:55 +0000 Subject: New upstream version 1:20240117 --- .../test_bitwise.cpython-310-pytest-7.1.3.pyc | Bin 13541 -> 13846 bytes .../test_chirp_common.cpython-310-pytest-7.1.3.pyc | Bin 28607 -> 31324 bytes ...t_wxui_radiothread.cpython-310-pytest-7.1.3.pyc | Bin 3082 -> 4770 bytes tests/unit/test_bitwise.py | 21 ++++-- tests/unit/test_chirp_common.py | 84 +++++++++++++++++++++ tests/unit/test_wxui_radiothread.py | 46 +++++++++++ 6 files changed, 145 insertions(+), 6 deletions(-) (limited to 'tests/unit') 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 index 5066d3a..398ad6b 100644 Binary files a/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc and b/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc differ 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 index cd2beb0..3334195 100644 Binary files a/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc and b/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc differ 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 index bee4b94..1c758c2 100644 Binary files a/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc and b/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc differ 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( + "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( + "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( + "", 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( + "", + 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'/'',extra.test2=''/'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)]) -- cgit v1.2.3