diff options
| author | Dave Hibberd <hibby@debian.org> | 2025-02-27 20:47:59 +0000 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2025-02-27 20:47:59 +0000 |
| commit | f6b2e6e7159906b8b3204dca3a9e58e42c36ccbb (patch) | |
| tree | f823b552593e7c151d07e99fdb6c0f64622ba5e8 /tests/unit | |
| parent | af38e5c951c5c0e8a80808eed77c9d8ea810a858 (diff) | |
New upstream version 20250221upstream/20250221
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc | bin | 16962 -> 18507 bytes | |||
| -rw-r--r-- | tests/unit/__pycache__/test_repeaterbook.cpython-310-pytest-7.1.3.pyc | bin | 8032 -> 8070 bytes | |||
| -rw-r--r-- | tests/unit/test_bitwise.py | 32 | ||||
| -rw-r--r-- | tests/unit/test_chirp_common.py | 23 | ||||
| -rw-r--r-- | tests/unit/test_repeaterbook.py | 5 |
5 files changed, 60 insertions, 0 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 9dcc2db..b65e7cd 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_repeaterbook.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_repeaterbook.cpython-310-pytest-7.1.3.pyc Binary files differindex 9676932..9c51168 100644 --- a/tests/unit/__pycache__/test_repeaterbook.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_repeaterbook.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/test_bitwise.py b/tests/unit/test_bitwise.py index 4ba467f..dc38cb6 100644 --- a/tests/unit/test_bitwise.py +++ b/tests/unit/test_bitwise.py @@ -97,6 +97,21 @@ class TestBitwiseBaseIntTypes(BaseTest): obj.foo[i] = i * 2 self.assertEqual(b'\x00\x02\x04\x06', data.get_packed()) + def test_int_array_of_one(self): + data = memmap.MemoryMapBytes(bytes(b'\x00\x01\x02\x03')) + obj = bitwise.parse('u8 foo[1];', data) + self.assertEqual(0, obj.foo[0]) + obj.foo[0] = 1 + self.assertEqual(b'\x01\x01\x02\x03', data.get_packed()) + + def test_int_array_of_zero(self): + data = memmap.MemoryMapBytes(bytes(b'\x00\x01\x02\x03')) + obj = bitwise.parse('u8 foo[0x0]; u8 bar;', data) + # Make sure we can't access any elements of zero-length foo + self.assertRaises(IndexError, lambda: obj.foo[0]) + # Make sure bar is still at the front, unaffected by zero-length foo + self.assertEqual(0, obj.bar) + def test_int_array_set_raw(self): data = memmap.MemoryMapBytes(bytes(b'\x00\x01\x02\x03')) obj = bitwise.parse('u8 foo[4];', data) @@ -357,6 +372,12 @@ class TestBitwiseStructTypes(BaseTest): self.assertRaises(AssertionError, obj.fill_raw, b'AB') self.assertRaises(AssertionError, obj.fill_raw, False) + def test_struct_array_of_one(self): + data = memmap.MemoryMapBytes(bytes(b"123")) + defn = "struct { u8 bar; } foo[1];" + obj = bitwise.parse(defn, data) + self.assertEqual(ord('1'), obj.foo[0].bar) + class TestBitwisePrintoffset(BaseTest): @mock.patch.object(bitwise.LOG, 'debug') @@ -383,6 +404,17 @@ class TestBitwiseErrors(BaseTest): def test_missing_semicolon(self): self.assertRaises(SyntaxError, bitwise.parse, "u8 foo", "") + def test_missing_element(self): + obj = bitwise.parse('u8 foo; struct { u8 bar; } baz;', b'12') + self.assertRaisesRegex(AttributeError, + 'No attribute does_not_exist', + getattr, obj, 'does_not_exist') + self.assertRaisesRegex(AttributeError, + 'No attribute this_either', + getattr, obj.baz, 'this_either') + self.assertTrue('foo' in obj) + self.assertFalse('does_not_exist' in obj) + class TestBitwiseComments(BaseTest): def test_comment_inline_cppstyle(self): diff --git a/tests/unit/test_chirp_common.py b/tests/unit/test_chirp_common.py index ea3bcf8..facdbed 100644 --- a/tests/unit/test_chirp_common.py +++ b/tests/unit/test_chirp_common.py @@ -78,6 +78,11 @@ class TestUtilityFunctions(base.BaseTest): self.assertEqual(140, chirp_common.from_MHz(14000001)) self.assertEqual(140, chirp_common.from_kHz(14001)) + def test_mem_to_from_csv(self): + mem1 = chirp_common.Memory() + mem2 = chirp_common.Memory._from_csv(','.join(mem1.to_csv())) + self.assertEqual(str(mem1), str(mem2)) + def test_mem_from_text_rb1(self): text = '145.2500 -0.6 MHz 97.4 OPEN' mem = chirp_common.mem_from_text(text) @@ -227,6 +232,24 @@ class TestUtilityFunctions(base.BaseTest): self.assertEqual(150000000, mem.offset) self.assertEqual('split', mem.duplex) + def test_mem_from_text_tsv(self): + from_lo = """8 Mt Scott 147.28 + 0.6 TSQL 88.5 167.9 23 NN 23 Tone->Tone FM 5 50W TayDan Emergency Step #2 +9 Mt Tabor 145.39 - 0.6 TSQL 88.5 100 23 NN 23 Tone->Tone FM 5 50W TayDan Emergency Step #1 +10 Timberline V 147.12 + 0.6 TSQL 103.5 100 23 NN 23 Tone->Tone FM 5 50W TayDan Emergency Step #4 +11 Timberline U 444.225 + 5 TSQL 88.5 100 23 NN 23 Tone->Tone FM 5 50W K7RPT Timberline, Linked to VHF side, AC7QE-R echolink +12 GovtCamp 443.875 + 5 TSQL 88.5 103.5 23 NN 23 Tone->Tone FM 5 50W""" # noqa + + lines = from_lo.split('\n') + mem = chirp_common.mem_from_text(lines[0]) + self.assertEqual('Mt Scott', mem.name) + self.assertEqual('TSQL', mem.tmode) + self.assertEqual('+', mem.duplex) + self.assertEqual(600000, mem.offset) + self.assertEqual(147280000, mem.freq) + self.assertEqual(8, mem.number) + for line in from_lo.split('\n'): + chirp_common.mem_from_text(line) + def test_mem_to_text1(self): mem = chirp_common.Memory() mem.freq = 146900000 diff --git a/tests/unit/test_repeaterbook.py b/tests/unit/test_repeaterbook.py index 8a0b059..57532fa 100644 --- a/tests/unit/test_repeaterbook.py +++ b/tests/unit/test_repeaterbook.py @@ -43,6 +43,7 @@ class TestRepeaterbook(unittest.TestCase): 'lon': coords[1], 'dist': 100, 'openonly': False, + 'cached': False, }) m = rb.get_memory(0) self.assertIsInstance(m, chirp_common.Memory) @@ -81,6 +82,7 @@ class TestRepeaterbook(unittest.TestCase): 'dist': 100, 'service': 'gmrs', 'openonly': False, + 'cached': False, }) m = rb.get_memory(0) self.assertIsInstance(m, chirp_common.Memory) @@ -102,6 +104,7 @@ class TestRepeaterbook(unittest.TestCase): 'lon': 133, 'dist': 20000, 'openonly': False, + 'cached': False, }) m = rb.get_memory(0) self.assertIsInstance(m, chirp_common.Memory) @@ -122,6 +125,7 @@ class TestRepeaterbook(unittest.TestCase): 'lon': -122, 'dist': 0, 'openonly': False, + 'cached': False, 'filter': 'tower'} rb = self._test_with_mocked(params) self.assertGreater(sum(rb.get_features().memory_bounds), 5) @@ -133,6 +137,7 @@ class TestRepeaterbook(unittest.TestCase): 'lon': -122, 'dist': 0, 'openonly': False, + 'cached': False, 'filter': 'tower'} rb1 = self._test_with_mocked(dict(params)) self.assertGreater(sum(rb1.get_features().memory_bounds), 5) |
