Merge lp:~sil2100/unity/autopilot_ibus_fixes into lp:unity

Proposed by Łukasz Zemczak
Status: Work in progress
Proposed branch: lp:~sil2100/unity/autopilot_ibus_fixes
Merge into: lp:unity
Diff against target: 50 lines (+26/-0)
1 file modified
tests/autopilot/unity/tests/test_ibus.py (+26/-0)
To merge this branch: bzr merge lp:~sil2100/unity/autopilot_ibus_fixes
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+135901@code.launchpad.net

Commit message

Clean the cache before every ibus test. To not lose user history, we backup the cache before doing that and restore it after the test.

Description of the change

This branch is probably still work-in-progress, as it probably doesn't fix all the problems with ibus history.

- Problem:

Some ibus autopilot tests might fail due to the ibus lookup table having preferences from previous ibus usages in the cache. Because of this, the first result that pops up when typing in ibus might be different than the expected hard-coded unicode value in the tests.

- The fix:

The real fix would be stop hard-coding unicode expected results, as even different ibus versions might return new default characters for given input. But this I'm still working on.

The fix proposed here was recommended as a temporary solution by Thomi. What we can do is actually simply clear the ibus cache before every autopilot ibus test. Not to lose user's preferences, the cache is backed up before every test, removed and then restored as a cleanup. This way, during the test execution the ibus cache on the filesystem is clean and we should be running the default ibus lookup table (see the problems section).

- Tests:

N/A

- Problems:

This solution might have some problems depending on how the ibus tests are actually executed. Once ibus is running, clearing the cache on the filesystem does nothing. So, if ibus is already running when autopilot is executed, clearing the cache probably won't do much good, since right now I *think* that the ibus daemon is not restarted on every test (please correct me if I'm wrong).

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

The problem with this, is it isn't going to clear out say ibus-anthy because it is stored in ~/.anthy/<some file in here>

Unmerged revisions

2920. By Łukasz Zemczak

Clean the cache before every ibus test. To not lose user history, we backup the cache before doing that and restore it after the test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/unity/tests/test_ibus.py'
2--- tests/autopilot/unity/tests/test_ibus.py 2012-11-23 02:05:14 +0000
3+++ tests/autopilot/unity/tests/test_ibus.py 2012-11-23 13:44:20 +0000
4@@ -25,6 +25,8 @@
5
6 from unity.tests import UnityTestCase
7
8+import shutil
9+import os
10
11 class IBusTests(UnityTestCase):
12 """Base class for IBus tests."""
13@@ -32,6 +34,7 @@
14 def setUp(self):
15 super(IBusTests, self).setUp()
16 self.set_correct_ibus_trigger_keys()
17+ self.clear_ibus_cache()
18
19 def set_correct_ibus_trigger_keys(self):
20 """Set the correct keys to trigger IBus.
21@@ -64,6 +67,29 @@
22 if cls._old_engines is not None:
23 set_active_engines(cls._old_engines)
24
25+ def clear_ibus_cache(self):
26+ """Clear the ibus cache so that we have clean history, backup the old one"""
27+
28+ self._old_cache = None
29+ cache = os.path.expanduser("~/.cache/ibus/")
30+ if os.path.isdir(cache):
31+ self._old_cache = os.tempnam()
32+ shutil.move(cache, self._old_cache)
33+
34+ self.addCleanup(self.restore_ibus_cache)
35+
36+ def restore_ibus_cache(self):
37+ """Restore the previously backed up ibus cache"""
38+
39+ if self._old_cache is not None:
40+ cache = os.path.expanduser("~/.cache/ibus/")
41+ if os.path.isdir(cache):
42+ shutil.rmtree(cache)
43+
44+ if os.path.isdir(self._old_cache):
45+ shutil.move(self._old_cache, cache)
46+
47+
48 def activate_input_engine_or_skip(self, engine_name):
49 """Activate the input engine 'engine_name', or skip the test if the
50 engine name is not avaialble (probably because it's not been installed).