Skip to content

Commit

Permalink
Merge pull request #9754 from keymanapp/chore/linux/speeduptest
Browse files Browse the repository at this point in the history
chore(linux): Speed up ibus-util tests
  • Loading branch information
ermshiperete authored Oct 16, 2023
2 parents 91e996f + c56b8a7 commit 3212faf
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions linux/keyman-config/tests/test_ibus_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, patched_time_sleep, MockIbusBusClass):
# Setup
mock_ibusBusInstance = MockIbusBusClass.return_value
mock_ibusBusInstance.is_connected.return_value = False
Expand All @@ -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, patched_time_sleep, MockIbusBusClass):
# Setup
mock_ibusBusInstance = MockIbusBusClass.return_value
mock_ibusBusInstance.is_connected.return_value = True
Expand All @@ -30,74 +31,62 @@ 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, patched_time_sleep, MockIbusBusClass):
# Setup
mock_ibusBusInstance = MockIbusBusClass.return_value
# Execute/Verify
self.assertIsNotNone(get_ibus_bus())
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, 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, MockIbusBusClass):
def test_installToIbus_InstallsNewKb(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, 'k4')
# Verify
mock_settingsSet.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')
@patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3'])
@patch('keyman_config.gsettings.GSettings.set')
def test_uninstallFromIbus_KbInstalled(self, MockSettingsSet, MockSettingsGet, MockIbusBusClass):
def test_uninstallFromIbus_KbInstalled(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
uninstall_from_ibus(mock_ibusBusInstance, 'k2')
# Verify
mock_settingsSet.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')
@patch('keyman_config.gsettings.GSettings.get', return_value=['k1', 'k2', 'k3'])
@patch('keyman_config.gsettings.GSettings.set')
def test_uninstallFromIbus_KbNotInstalled(self, MockSettingsSet, MockSettingsGet, MockIbusBusClass):
def test_uninstallFromIbus_KbNotInstalled(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
uninstall_from_ibus(mock_ibusBusInstance, 'k4')
# 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'])
Expand Down

0 comments on commit 3212faf

Please sign in to comment.