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/test_wxui_radiothread.py | |
| parent | fc438e6a84402e621877f6c30097442af46f122b (diff) | |
New upstream version 20240413upstream/20240413
Diffstat (limited to 'tests/unit/test_wxui_radiothread.py')
| -rw-r--r-- | tests/unit/test_wxui_radiothread.py | 72 |
1 files changed, 72 insertions, 0 deletions
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) |
