From d92808e77964c2cb97d8f826edab8fe43d7906e3 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Thu, 12 Oct 2023 18:22:56 +0200 Subject: [PATCH 1/3] chore(linux): Speed up ibus-util tests --- linux/keyman-config/tests/test_ibus_util.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/linux/keyman-config/tests/test_ibus_util.py b/linux/keyman-config/tests/test_ibus_util.py index eb51515f3ff..d9d407cabb1 100644 --- a/linux/keyman-config/tests/test_ibus_util.py +++ b/linux/keyman-config/tests/test_ibus_util.py @@ -6,9 +6,10 @@ @patch('keyman_config.ibus_util.IBus.Bus') +@patch('time.sleep', return_value=None) class IbusUtilTests(unittest.TestCase): - def test_getIbusBus_NotConnected_ReturnsNone(self, MockIbusBusClass): + def test_getIbusBus_NotConnected_ReturnsNone(self, PatchedTimeSleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value mock_ibusBusInstance.is_connected.return_value = False @@ -18,7 +19,7 @@ def test_getIbusBus_NotConnected_ReturnsNone(self, MockIbusBusClass): self.assertTrue(MockIbusBusClass.called, "IBus.Bus called") self.assertTrue(mock_ibusBusInstance.destroy.called) - def test_getIbusBus_GlobalEngineNotEnabled_ReturnsNone(self, MockIbusBusClass): + def test_getIbusBus_GlobalEngineNotEnabled_ReturnsNone(self, PatchedTimeSleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value mock_ibusBusInstance.is_connected.return_value = True @@ -30,7 +31,7 @@ def test_getIbusBus_GlobalEngineNotEnabled_ReturnsNone(self, MockIbusBusClass): self.assertTrue(MockIbusBusClass.called, "IBus.Bus called") self.assertTrue(mock_ibusBusInstance.destroy.called) - def test_getIbusBus_ReturnsBus(self, MockIbusBusClass): + def test_getIbusBus_ReturnsBus(self, PatchedTimeSleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value # Execute/Verify @@ -40,7 +41,7 @@ def test_getIbusBus_ReturnsBus(self, MockIbusBusClass): @patch('keyman_config.gsettings.GSettings.get') @patch('keyman_config.gsettings.GSettings.set') - def test_installToIbus_AlreadyInstalled(self, MockSettingsSet, MockSettingsGet, MockIbusBusClass): + def test_installToIbus_AlreadyInstalled(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): # Setup mock_settingsGet = MockSettingsGet mock_settingsSet = MockSettingsSet @@ -56,7 +57,7 @@ def test_installToIbus_AlreadyInstalled(self, MockSettingsSet, MockSettingsGet, @patch('keyman_config.gsettings.GSettings.get') @patch('keyman_config.gsettings.GSettings.set') - def test_installToIbus_InstallsNewKb(self, MockSettingsSet, MockSettingsGet, MockIbusBusClass): + def test_installToIbus_InstallsNewKb(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): # Setup mock_settingsGet = MockSettingsGet mock_settingsSet = MockSettingsSet @@ -72,7 +73,7 @@ def test_installToIbus_InstallsNewKb(self, MockSettingsSet, MockSettingsGet, Moc @patch('keyman_config.gsettings.GSettings.get') @patch('keyman_config.gsettings.GSettings.set') - def test_uninstallFromIbus_KbInstalled(self, MockSettingsSet, MockSettingsGet, MockIbusBusClass): + def test_uninstallFromIbus_KbInstalled(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): # Setup mock_settingsGet = MockSettingsGet mock_settingsSet = MockSettingsSet @@ -88,7 +89,7 @@ def test_uninstallFromIbus_KbInstalled(self, MockSettingsSet, MockSettingsGet, M @patch('keyman_config.gsettings.GSettings.get') @patch('keyman_config.gsettings.GSettings.set') - def test_uninstallFromIbus_KbNotInstalled(self, MockSettingsSet, MockSettingsGet, MockIbusBusClass): + def test_uninstallFromIbus_KbNotInstalled(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): # Setup mock_settingsGet = MockSettingsGet mock_settingsSet = MockSettingsSet From 303e57ba68d7c920bc8355d4acba2dfeb0671bd6 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Thu, 12 Oct 2023 18:44:34 +0200 Subject: [PATCH 2/3] refactor(linux): Refactor mocks in ibus-util tests --- linux/keyman-config/tests/test_ibus_util.py | 42 ++++++++------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/linux/keyman-config/tests/test_ibus_util.py b/linux/keyman-config/tests/test_ibus_util.py index d9d407cabb1..85c4a7589a6 100644 --- a/linux/keyman-config/tests/test_ibus_util.py +++ b/linux/keyman-config/tests/test_ibus_util.py @@ -9,7 +9,7 @@ @patch('time.sleep', return_value=None) class IbusUtilTests(unittest.TestCase): - def test_getIbusBus_NotConnected_ReturnsNone(self, PatchedTimeSleep, MockIbusBusClass): + def test_getIbusBus_NotConnected_ReturnsNone(self, patched_time_sleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value mock_ibusBusInstance.is_connected.return_value = False @@ -19,7 +19,7 @@ def test_getIbusBus_NotConnected_ReturnsNone(self, PatchedTimeSleep, MockIbusBus self.assertTrue(MockIbusBusClass.called, "IBus.Bus called") self.assertTrue(mock_ibusBusInstance.destroy.called) - def test_getIbusBus_GlobalEngineNotEnabled_ReturnsNone(self, PatchedTimeSleep, MockIbusBusClass): + def test_getIbusBus_GlobalEngineNotEnabled_ReturnsNone(self, patched_time_sleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value mock_ibusBusInstance.is_connected.return_value = True @@ -31,7 +31,7 @@ def test_getIbusBus_GlobalEngineNotEnabled_ReturnsNone(self, PatchedTimeSleep, M self.assertTrue(MockIbusBusClass.called, "IBus.Bus called") self.assertTrue(mock_ibusBusInstance.destroy.called) - def test_getIbusBus_ReturnsBus(self, PatchedTimeSleep, MockIbusBusClass): + def test_getIbusBus_ReturnsBus(self, patched_time_sleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value # Execute/Verify @@ -39,66 +39,54 @@ def test_getIbusBus_ReturnsBus(self, PatchedTimeSleep, MockIbusBusClass): self.assertTrue(MockIbusBusClass.called, "IBus.Bus called") self.assertFalse(mock_ibusBusInstance.destroy.called) - @patch('keyman_config.gsettings.GSettings.get') + @patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3']) @patch('keyman_config.gsettings.GSettings.set') - def test_installToIbus_AlreadyInstalled(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): + def test_installToIbus_AlreadyInstalled(self, patched_settings_set, patched_settings_get, patched_time_sleep, MockIbusBusClass): # Setup - mock_settingsGet = MockSettingsGet - mock_settingsSet = MockSettingsSet - mock_settingsGet.return_value = ['k1', 'k2', 'k3'] mock_ibusBusInstance = MockIbusBusClass.return_value # Execute install_to_ibus(mock_ibusBusInstance, 'k3') # Verify - mock_settingsSet.assert_called_once_with( + patched_settings_set.assert_called_once_with( "preload-engines", ['k1', 'k2', 'k3'], 'as') mock_ibusBusInstance.preload_engines.assert_called_once_with( ['k1', 'k2', 'k3']) - @patch('keyman_config.gsettings.GSettings.get') + @patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3']) @patch('keyman_config.gsettings.GSettings.set') - def test_installToIbus_InstallsNewKb(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): + def test_installToIbus_InstallsNewKb(self, mock_settings_set, mock_settings_get, patched_time_sleep, MockIbusBusClass): # Setup - mock_settingsGet = MockSettingsGet - mock_settingsSet = MockSettingsSet - mock_settingsGet.return_value = ['k1', 'k2', 'k3'] mock_ibusBusInstance = MockIbusBusClass.return_value # Execute install_to_ibus(mock_ibusBusInstance, 'k4') # Verify - mock_settingsSet.assert_called_once_with( + mock_settings_set.assert_called_once_with( "preload-engines", ['k1', 'k2', 'k3', 'k4'], 'as') mock_ibusBusInstance.preload_engines.assert_called_once_with( ['k1', 'k2', 'k3', 'k4']) - @patch('keyman_config.gsettings.GSettings.get') + @patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3']) @patch('keyman_config.gsettings.GSettings.set') - def test_uninstallFromIbus_KbInstalled(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): + def test_uninstallFromIbus_KbInstalled(self, mock_settings_set, mock_settings_get, patched_time_sleep, MockIbusBusClass): # Setup - mock_settingsGet = MockSettingsGet - mock_settingsSet = MockSettingsSet - mock_settingsGet.return_value = ['k1', 'k2', 'k3'] mock_ibusBusInstance = MockIbusBusClass.return_value # Execute uninstall_from_ibus(mock_ibusBusInstance, 'k2') # Verify - mock_settingsSet.assert_called_once_with( + mock_settings_set.assert_called_once_with( "preload-engines", ['k1', 'k3'], 'as') mock_ibusBusInstance.preload_engines.assert_called_once_with( ['k1', 'k3']) - @patch('keyman_config.gsettings.GSettings.get') + @patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3']) @patch('keyman_config.gsettings.GSettings.set') - def test_uninstallFromIbus_KbNotInstalled(self, MockSettingsSet, MockSettingsGet, PatchedTimeSleep, MockIbusBusClass): + def test_uninstallFromIbus_KbNotInstalled(self, mock_settings_set, mock_settings_get, patched_time_sleep, MockIbusBusClass): # Setup - mock_settingsGet = MockSettingsGet - mock_settingsSet = MockSettingsSet - mock_settingsGet.return_value = ['k1', 'k2', 'k3'] mock_ibusBusInstance = MockIbusBusClass.return_value # Execute uninstall_from_ibus(mock_ibusBusInstance, 'k4') # Verify - mock_settingsSet.assert_called_once_with( + mock_settings_set.assert_called_once_with( "preload-engines", ['k1', 'k2', 'k3'], 'as') mock_ibusBusInstance.preload_engines.assert_called_once_with( ['k1', 'k2', 'k3']) From c56b8a72ebc2df2c62786d613e4550afc1a84850 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Mon, 16 Oct 2023 09:12:28 +0200 Subject: [PATCH 3/3] chore(linux): rename parameters This addresses code review comments. --- linux/keyman-config/tests/test_ibus_util.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/linux/keyman-config/tests/test_ibus_util.py b/linux/keyman-config/tests/test_ibus_util.py index 85c4a7589a6..29918994e30 100644 --- a/linux/keyman-config/tests/test_ibus_util.py +++ b/linux/keyman-config/tests/test_ibus_util.py @@ -54,39 +54,39 @@ def test_installToIbus_AlreadyInstalled(self, patched_settings_set, patched_sett @patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3']) @patch('keyman_config.gsettings.GSettings.set') - def test_installToIbus_InstallsNewKb(self, mock_settings_set, mock_settings_get, patched_time_sleep, MockIbusBusClass): + def test_installToIbus_InstallsNewKb(self, patched_settings_set, patched_settings_get, patched_time_sleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value # Execute install_to_ibus(mock_ibusBusInstance, 'k4') # Verify - mock_settings_set.assert_called_once_with( + patched_settings_set.assert_called_once_with( "preload-engines", ['k1', 'k2', 'k3', 'k4'], 'as') mock_ibusBusInstance.preload_engines.assert_called_once_with( ['k1', 'k2', 'k3', 'k4']) @patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3']) @patch('keyman_config.gsettings.GSettings.set') - def test_uninstallFromIbus_KbInstalled(self, mock_settings_set, mock_settings_get, patched_time_sleep, MockIbusBusClass): + def test_uninstallFromIbus_KbInstalled(self, patched_settings_set, patched_settings_get, patched_time_sleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value # Execute uninstall_from_ibus(mock_ibusBusInstance, 'k2') # Verify - mock_settings_set.assert_called_once_with( + patched_settings_set.assert_called_once_with( "preload-engines", ['k1', 'k3'], 'as') mock_ibusBusInstance.preload_engines.assert_called_once_with( ['k1', 'k3']) @patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3']) @patch('keyman_config.gsettings.GSettings.set') - def test_uninstallFromIbus_KbNotInstalled(self, mock_settings_set, mock_settings_get, patched_time_sleep, MockIbusBusClass): + def test_uninstallFromIbus_KbNotInstalled(self, patched_settings_set, patched_settings_get, patched_time_sleep, MockIbusBusClass): # Setup mock_ibusBusInstance = MockIbusBusClass.return_value # Execute uninstall_from_ibus(mock_ibusBusInstance, 'k4') # Verify - mock_settings_set.assert_called_once_with( + patched_settings_set.assert_called_once_with( "preload-engines", ['k1', 'k2', 'k3'], 'as') mock_ibusBusInstance.preload_engines.assert_called_once_with( ['k1', 'k2', 'k3'])