diff options
| author | Dave Hibberd <hibby@debian.org> | 2024-04-13 21:27:52 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2024-04-13 21:27:52 +0100 |
| commit | 0496ffac85e663ba4c9a14d2d4eb300a3c017ae2 (patch) | |
| tree | 22850f3993686d89159885f516bfb4381ffc0906 /tests/unit | |
| parent | fc438e6a84402e621877f6c30097442af46f122b (diff) | |
New upstream version 20240413upstream/20240413
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/__pycache__/base.cpython-310.pyc | bin | 962 -> 1110 bytes | |||
| -rw-r--r-- | tests/unit/__pycache__/test_alinco_clone.cpython-310-pytest-7.1.3.pyc | bin | 4993 -> 6437 bytes | |||
| -rw-r--r-- | tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc | bin | 15690 -> 17015 bytes | |||
| -rw-r--r-- | tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc | bin | 31358 -> 31375 bytes | |||
| -rw-r--r-- | tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc | bin | 4770 -> 6529 bytes | |||
| -rw-r--r-- | tests/unit/base.py | 4 | ||||
| -rw-r--r-- | tests/unit/test_alinco_clone.py | 45 | ||||
| -rw-r--r-- | tests/unit/test_bitwise.py | 10 | ||||
| -rw-r--r-- | tests/unit/test_chirp_common.py | 1 | ||||
| -rw-r--r-- | tests/unit/test_wxui_radiothread.py | 72 |
10 files changed, 130 insertions, 2 deletions
diff --git a/tests/unit/__pycache__/base.cpython-310.pyc b/tests/unit/__pycache__/base.cpython-310.pyc Binary files differindex a5f2379..7fcc6bd 100644 --- a/tests/unit/__pycache__/base.cpython-310.pyc +++ b/tests/unit/__pycache__/base.cpython-310.pyc diff --git a/tests/unit/__pycache__/test_alinco_clone.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_alinco_clone.cpython-310-pytest-7.1.3.pyc Binary files differindex f9c396a..9811cb6 100644 --- a/tests/unit/__pycache__/test_alinco_clone.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_alinco_clone.cpython-310-pytest-7.1.3.pyc 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 3efe7a5..109a28e 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 b47cb93..e4719f6 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 1c758c2..38b9af1 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/base.py b/tests/unit/base.py index 72c554a..a9e938c 100644 --- a/tests/unit/base.py +++ b/tests/unit/base.py @@ -12,6 +12,10 @@ class BaseTest(unittest.TestCase): __builtins__['_'] = lambda s: s self.mocks = [] + def use(self, m): + self.mocks.append(m) + m.start() + def tearDown(self): for m in self.mocks: m.stop() diff --git a/tests/unit/test_alinco_clone.py b/tests/unit/test_alinco_clone.py index 5df6bcc..c5e28ca 100644 --- a/tests/unit/test_alinco_clone.py +++ b/tests/unit/test_alinco_clone.py @@ -19,7 +19,7 @@ import unittest from unittest import mock from chirp import directory -from chirp.drivers import alinco +from chirp.drivers import alinco, alinco_dr735t from chirp import memmap @@ -35,6 +35,29 @@ class FakeAlincoSerial: """Zero the mmap before an upload""" self.image = memmap.MemoryMapBytes(b'\x00' * len(self.image)) + def _handle_rw_dr735tn(self, data): + if b'R' in data: + addr_idx = data.index(b'R')-4 + elif b'W' in data: + addr_idx = data.index(b'W')-4 + else: + raise Exception('Unable to handle RW command %r' % data) + addr = int(data[addr_idx: addr_idx+4], 16) + cmd = chr(data[addr_idx+4]) + + if cmd == 'R': + bin_chunk = self.image[addr:addr+64] + hex_chunk = binascii.hexlify(bin_chunk) + assert (len(hex_chunk) == 128) + self.readbuf.append(hex_chunk) + self.readbuf.append(b'\r\n') + + if cmd == 'W': + hex_chunk = data[addr_idx+5:addr_idx+128+5].decode() + bin_chunk = binascii.unhexlify(hex_chunk) + self.image[addr] = bin_chunk + self.readbuf.append(b'OK\r\n') + def _handle_rw(self, data): if b'R' in data: cmdindex = data.index(b'R') @@ -87,8 +110,23 @@ class FakeAlincoSerial: self.readbuf.append(ident_ack) elif data.startswith(b'AL~F'): self._handle_rw(data) - elif data.startswith(b'AL~E'): + elif data.startswith(b'AL~E') and self.ident != b"DR735TN": self.readbuf.append(b'OK' * 10) + elif data.startswith(b'AL~WHO'): + # radio responds with model to WHO + self.ident = b"DR735TN" + # expect back "DR735TN\r\nOK\r\n" + self.readbuf.append(self.ident+b"\r\n") + elif data.startswith(b'AL~DR735J'): + # this is somehow making the radio writeable... + self.readbuf.append(b'OK\r\n') + + elif data.startswith(b'AL~RESET') and self.ident == b"DR735TN": + self.readbuf.append(b'OK\r\n') + + elif data.startswith(b'AL~EEPEL'): + self._handle_rw_dr735tn(data) + else: raise Exception('Unable to handle %r' % data) @@ -134,6 +172,9 @@ class AlincoCloneTest(unittest.TestCase): def test_dr235(self): self._test_alinco(alinco.DR235Radio) + def test_dr735(self): + self._test_alinco(alinco_dr735t.AlincoDR735T) + def test_dj175(self): # The 175 has a slightly different download string, so test it # specifically diff --git a/tests/unit/test_bitwise.py b/tests/unit/test_bitwise.py index 9f40dcc..3ace170 100644 --- a/tests/unit/test_bitwise.py +++ b/tests/unit/test_bitwise.py @@ -192,6 +192,16 @@ class TestBitType(BaseTest): obj.foo[i] = i % 2 self.assertEqual(data.get_packed(), b"\x55\x55\x55") + def test_lbit_array(self): + defn = "lbit foo[24];" + data = memmap.MemoryMapBytes(bytes(b"\x00\x20\x80")) + obj = bitwise.parse(defn, data) + for i, v in [(0, False), (13, True), (23, True)]: + self.assertEqual(bool(obj.foo[i]), v) + for i in range(0, 24): + obj.foo[i] = i % 2 + self.assertEqual(data.get_packed(), b"\xAA\xAA\xAA") + def test_bit_array_fail(self): self.assertRaises(ValueError, bitwise.parse, "bit foo[23];", b"000") diff --git a/tests/unit/test_chirp_common.py b/tests/unit/test_chirp_common.py index d0f22f9..9fe90ff 100644 --- a/tests/unit/test_chirp_common.py +++ b/tests/unit/test_chirp_common.py @@ -765,6 +765,7 @@ class TestOverrideRules(base.BaseTest): 'Retevis_RB17P', 'Baofeng_UV-17ProGPS', 'Baofeng_5RM', + 'Baofeng_K5-Plus', ] def _test_radio_override_immutable_policy(self, rclass): diff --git a/tests/unit/test_wxui_radiothread.py b/tests/unit/test_wxui_radiothread.py index 1088b81..aedd7c8 100644 --- a/tests/unit/test_wxui_radiothread.py +++ b/tests/unit/test_wxui_radiothread.py @@ -1,7 +1,10 @@ +import os import sys import time from unittest import mock +import ddt + sys.modules['wx'] = wx = mock.MagicMock() sys.modules['wx.lib'] = mock.MagicMock() sys.modules['wx.lib.scrolledpanel'] = mock.MagicMock() @@ -14,6 +17,7 @@ sys.modules['chirp.wxui.developer'] = mock.MagicMock() # wx to be present for these tests from tests.unit import base # noqa from chirp.wxui import clone # noqa +from chirp.wxui import config # noqa from chirp.wxui import radiothread # noqa @@ -151,3 +155,71 @@ class TestClone(base.BaseTest): 'COM17: Some other device'], [clone.port_label(p) for p in sorted(ports, key=clone.port_sort_key)]) + + +class TestException(Exception): + pass + + +@ddt.ddt +class TestStartup(base.BaseTest): + def setUp(self): + super().setUp() + self.use(mock.patch('os.path')) + self.use(mock.patch('os.makedirs')) + self.use(mock.patch('chirp.wxui.CONF')) + self.args = mock.MagicMock() + self.args.install_desktop_app = False + self.args.no_install_desktop_app = False + from chirp.wxui import maybe_install_desktop, CONF + self.maybe_install_desktop = maybe_install_desktop + self.conf = CONF + + @ddt.data( + # No arguments, no file, no previous, answer no + [False, False, False, False, False], + # No arguments, no file, no previous, answer yes + [False, False, False, False, True], + # No arguments, no file, previous yes, no prompt + [False, False, False, True, None], + # No arguments, exists, previous no, no prompt + [False, False, True, False, None], + # Opt out, no file, no prompt + [False, True, False, None, None], + # Opt in, no file, previous yes, still prompt + [True, False, False, True, True], + # Opt in, exists, previous no, no prompt'), + [True, False, True, False, None], + ) + @ddt.unpack + def test_linux_desktop_file(self, optin, optout, exists, last, answ): + self.args.install_desktop_app = optin + self.args.no_install_desktop_app = optout + os.path.exists.return_value = exists + self.conf.get_bool.return_value = last + wx.MessageBox.return_value = wx.YES if answ else wx.NO + os.makedirs.side_effect = TestException + wx.MessageBox.reset_mock() + + if answ is True: + # If we made it through all the checks, and thus prompted the user, + # make sure we get to the makedirs part if expected + self.assertRaises(TestException, + self.maybe_install_desktop, self.args) + elif answ is False: + # If we were supposed to make it to the prompt but answer no, + # make sure we did + self.maybe_install_desktop(self.args) + self.assertFalse(os.makedirs.called) + self.assertTrue(wx.MessageBox.called) + else: + # If we were not supposed to make it to the prompt, make sure we + # didn't, nor did we do any create actions + self.maybe_install_desktop(self.args) + self.assertFalse(os.makedirs.called) + self.assertFalse(wx.MessageBox.called) + + def test_linux_desktop_file_exists(self): + os.path.exists.return_value = True + self.maybe_install_desktop(self.args) + self.assertFalse(os.makedirs.called) |
