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

Proposed by Łukasz Zemczak
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: no longer in the source branch.
Merged at revision: 3337
Proposed branch: lp:~sil2100/unity/autopilot_hud_more_fixes
Merge into: lp:unity
Diff against target: 125 lines (+35/-17)
3 files modified
tests/autopilot/unity/emulators/hud.py (+9/-0)
tests/autopilot/unity/tests/test_hud.py (+20/-16)
tests/autopilot/unity/tests/test_search.py (+6/-1)
To merge this branch: bzr merge lp:~sil2100/unity/autopilot_hud_more_fixes
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Francis Ginther Approve
Andrea Azzarone (community) Approve
Review via email: mp+164880@code.launchpad.net

Commit message

Modify all the hud_query_check lambdas to be more smart and error-checking. Same for the selected_hud_button method in the HUD emulator.
Also, get rid of the troublesome test_gedit_undo and change it into test_gedit_save, which is easier to test and anyway tests what we want.
Besides that we also now try to handle the StateNotFoundError exception in the HUD emulator, another cause of some AP failures.

Description of the change

- Problem:

Some HUD tests are still failing, which is blocking the QA stack. The problem for that are differences on how HUD is returning the results, it's not instant.

- Fix:

Most of the fixes are related to changing the hud_query_check() lambda to a more 'smart' function. We first check if there is any HUD button we can fetch the label for. We do that every time hud_query_check was used.
We're adding one additional check to selected_hud_button() method in the hud emulator to make it safer to use. This fixes some of the errors I have been encountering.

Also, we get rid of the test_gedit_undo and change it into test_gedit_save. This test is used only to check if activating the menu entries in an application works and performs the actions (besides quitting). So, instead of performing a hard-to-test task like undo, I think 'save' is enough to test what we need.

- Tests:

N/A

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Francis Ginther (fginther) wrote :

The tests look better, but I get a StateNotFoundError on about every other test. My theory is that the contents of the hud have not yet 'settled' and the menu buttons are still changing. It might be worth merging this as is to make the testing better and addressing the StateNotFoundError later if it proves to be a problem for the integration testing.

Here's a stacktrace:

Traceback (most recent call last):
  File "/home/fginther/work/unity/autopilot_hud_more_fixes/tests/autopilot/unity/tests/test_hud.py", line 334, in test_app_activate_on_enter
    Eventually(Equals(u'Quit\u2002(File)'), timeout=30))
  File "/usr/lib/python2.7/dist-packages/testtools/testcase.py", line 401, in assertThat
    mismatch = matcher.match(matchee)
  File "/usr/lib/python2.7/dist-packages/autopilot/matchers/__init__.py", line 103, in match
    wait_fun(self.matcher, self.timeout)
  File "/usr/lib/python2.7/dist-packages/autopilot/matchers/__init__.py", line 119, in _callable_wait_for
    new_value = refresh_fn()
  File "/home/fginther/work/unity/autopilot_hud_more_fixes/tests/autopilot/unity/tests/test_hud.py", line 328, in hud_query_check
    button = self.unity.hud.selected_hud_button
  File "/home/fginther/work/unity/autopilot_hud_more_fixes/tests/autopilot/unity/emulators/hud.py", line 123, in selected_hud_button
    [button] = filter(lambda x: x.focused, self.hud_buttons)
  File "/home/fginther/work/unity/autopilot_hud_more_fixes/tests/autopilot/unity/emulators/hud.py", line 123, in <lambda>
    [button] = filter(lambda x: x.focused, self.hud_buttons)
  File "/usr/lib/python2.7/dist-packages/autopilot/introspection/dbus.py", line 410, in __getattr__
    self.refresh_state()
  File "/usr/lib/python2.7/dist-packages/autopilot/introspection/dbus.py", line 363, in refresh_state
    _, new_state = self.get_new_state()
  File "/usr/lib/python2.7/dist-packages/autopilot/introspection/dbus.py", line 444, in get_new_state
    raise StateNotFoundError(self.__class__.__name__, self.id)
StateNotFoundError: State not found for class with name 'HudButton' and id '8793'.

review: Needs Fixing
Revision history for this message
Francis Ginther (fginther) wrote :

Ughh! I'm still seeing a StateNotFoundError, but this is when attempting to read the hud button label:

Traceback (most recent call last):
  File "/home/fginther/work/unity/lukasz/tests/autopilot/unity/tests/test_hud.py", line 334, in test_app_activate_on_enter
    Eventually(Equals(u'Quit\u2002(File)'), timeout=30))
  File "/usr/lib/python2.7/dist-packages/testtools/testcase.py", line 401, in assertThat
    mismatch = matcher.match(matchee)
  File "/usr/lib/python2.7/dist-packages/autopilot/matchers/__init__.py", line 103, in match
    wait_fun(self.matcher, self.timeout)
  File "/usr/lib/python2.7/dist-packages/autopilot/matchers/__init__.py", line 119, in _callable_wait_for
    new_value = refresh_fn()
  File "/home/fginther/work/unity/lukasz/tests/autopilot/unity/tests/test_hud.py", line 331, in hud_query_check
    return button.label_no_formatting
  File "/home/fginther/work/unity/lukasz/tests/autopilot/unity/emulators/hud.py", line 168, in label_no_formatting
    return htmlparser.unescape(re.sub("<[^>]*>", "", self.label))
  File "/usr/lib/python2.7/dist-packages/autopilot/introspection/dbus.py", line 410, in __getattr__
    self.refresh_state()
  File "/usr/lib/python2.7/dist-packages/autopilot/introspection/dbus.py", line 363, in refresh_state
    _, new_state = self.get_new_state()
  File "/usr/lib/python2.7/dist-packages/autopilot/introspection/dbus.py", line 444, in get_new_state
    raise StateNotFoundError(self.__class__.__name__, self.id)
StateNotFoundError: State not found for class with name 'HudButton' and id '10497'.

I used your approach of handling the exception and added it to hud_query_check (along with moving it to the base class in test_hud): lp:~fginther/unity/autopilot_hud_button_label_fixes

review: Needs Fixing
Revision history for this message
Francis Ginther (fginther) wrote :

Per our IRC discussion, this is already an improvement, so I'll approve. We can then consider the additional fix separately.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Francis Ginther (fginther) wrote :

Jenkins barfed on itself, re-approving.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/unity/emulators/hud.py'
2--- tests/autopilot/unity/emulators/hud.py 2013-05-10 05:16:07 +0000
3+++ tests/autopilot/unity/emulators/hud.py 2013-05-21 16:21:28 +0000
4@@ -9,7 +9,10 @@
5
6 from __future__ import absolute_import
7
8+from logging import getLogger
9+
10 from autopilot.input import Keyboard
11+from autopilot.introspection.dbus import StateNotFoundError
12 from autopilot.keybindings import KeybindingsHelper
13 from HTMLParser import HTMLParser
14 import re
15@@ -18,6 +21,7 @@
16 from unity.emulators.dash import SearchBar
17 from unity.emulators.icons import HudEmbeddedIcon, HudLauncherIcon
18
19+log = getLogger(__name__)
20
21 class HudController(UnityIntrospectionObject, KeybindingsHelper):
22 """Proxy object for the Unity Hud Controller."""
23@@ -118,10 +122,15 @@
24 @property
25 def selected_hud_button(self):
26 try:
27+ if len(self.hud_buttons) is 0:
28+ return 0
29 [button] = filter(lambda x: x.focused, self.hud_buttons)
30 return button
31 except IndexError:
32 raise RuntimeError("No HUD buttons found, is hud active?")
33+ except StateNotFoundError:
34+ log.warning("StateNotFoundError has been raised by HudController")
35+ return 0
36
37 @property
38 def num_buttons(self):
39
40=== modified file 'tests/autopilot/unity/tests/test_hud.py'
41--- tests/autopilot/unity/tests/test_hud.py 2013-05-20 17:42:42 +0000
42+++ tests/autopilot/unity/tests/test_hud.py 2013-05-21 16:21:28 +0000
43@@ -195,8 +195,8 @@
44
45 self.assertEqual(calc.is_active, True)
46
47- def test_gedit_undo(self):
48- """Test that the 'undo' action in the Hud works with GEdit."""
49+ def test_gedit_save(self):
50+ """Test that the 'save' action in the Hud works with GEdit."""
51
52 file_path = mktemp()
53 self.addCleanup(remove, file_path)
54@@ -204,29 +204,27 @@
55 self.addCleanup(self.process_manager.close_all_app, 'Text Editor')
56 self.assertProperty(gedit_win, is_focused=True)
57
58- self.keyboard.type("0")
59- self.keyboard.type(" ")
60- self.keyboard.type("1")
61+ self.keyboard.type("Test")
62
63 self.unity.hud.ensure_visible()
64
65- self.keyboard.type("undo")
66- hud_query_check = lambda: self.unity.hud.selected_hud_button.label_no_formatting
67+ self.keyboard.type("save")
68+
69+ def hud_query_check():
70+ button = self.unity.hud.selected_hud_button
71+ if not button:
72+ return
73+ return button.label_no_formatting
74+
75 self.assertThat(hud_query_check,
76- Eventually(Equals(u'Undo\u2002(Edit)')))
77+ Eventually(Equals(u'Save\u2002(File)')))
78 self.keyboard.press_and_release('Return')
79+ self.addCleanup(self.keyboard.press_and_release, "Ctrl+s")
80 self.assertThat(self.unity.hud.visible, Eventually(Equals(False), timeout=30))
81
82 self.assertProperty(gedit_win, is_focused=True)
83- # XXX: Because of LP: #1180903, we need to give HUD some time after activating
84- # any entry, because it takes some time
85- sleep(1.5)
86- self.keyboard.press_and_release("Ctrl+s")
87 self.assertThat(lambda: exists(file_path), Eventually(Equals(True), timeout=30))
88
89- contents = open(file_path).read().strip('\n')
90- self.assertEqual("0 ", contents)
91-
92 def test_hud_to_dash_has_key_focus(self):
93 """When switching from the hud to the dash you don't lose key focus."""
94 self.unity.hud.ensure_visible()
95@@ -325,7 +323,13 @@
96
97 self.keyboard.type("Quit")
98 self.assertThat(self.unity.hud.search_string, Eventually(Equals("Quit")))
99- hud_query_check = lambda: self.unity.hud.selected_hud_button.label_no_formatting
100+
101+ def hud_query_check():
102+ button = self.unity.hud.selected_hud_button
103+ if not button:
104+ return
105+ return button.label_no_formatting
106+
107 self.assertThat(hud_query_check,
108 Eventually(Equals(u'Quit\u2002(File)'), timeout=30))
109
110
111=== modified file 'tests/autopilot/unity/tests/test_search.py'
112--- tests/autopilot/unity/tests/test_search.py 2013-05-17 16:19:20 +0000
113+++ tests/autopilot/unity/tests/test_search.py 2013-05-21 16:21:28 +0000
114@@ -146,7 +146,12 @@
115 def input_and_check_result(self, string, expected):
116 self.keyboard.type(string)
117 self.assertThat(self.unity.hud.search_string, Eventually(Equals(string), timeout=30))
118- hud_query_check = lambda: self.unity.hud.selected_hud_button.label_no_formatting
119+ def hud_query_check():
120+ button = self.unity.hud.selected_hud_button
121+ if not button:
122+ return
123+ return button.label_no_formatting
124+
125 self.assertThat(hud_query_check, Eventually(Equals(expected), timeout=30))
126
127