Merge lp:~elopio/ubuntu-ui-toolkit/fix1220346-pointing_device into lp:ubuntu-ui-toolkit

Proposed by Leo Arias
Status: Merged
Approved by: Zoltan Balogh
Approved revision: 745
Merged at revision: 743
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/fix1220346-pointing_device
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 107 lines (+34/-17)
2 files modified
tests/autopilot/ubuntuuitoolkit/emulators.py (+7/-17)
tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py (+27/-0)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/fix1220346-pointing_device
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+183719@code.launchpad.net

Commit message

Do not duplicate the pointer instantiation on the autopilot emulators.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
743. By Leo Arias

Fixed pep8 error.

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

+1 on the fact it would be nice to have access to the screen on touch devices.

Overall, this makes sense to leave in the base class and not duplicate.

Revision history for this message
Leo Arias (elopio) wrote :

<balloons> elopio, problems with this do you think? mock_model.return_value = 'not desktop'
<elopio> balloons: I didn't like it, but it seems each phone returns something different.
<balloons> I spoke with thomi at one point about getting actual device names returned via the platform model call
<elopio> balloons: hum, my nexus4 returns 'nexus4'.
<elopio> 'Nexus 4'
<balloons> it's just a test I suppose :-)
<elopio> balloons: it's just testing the two workflows we have: 1 on the desktop, 1 other.
<elopio> maybe later it would make more sense make a switch statement with all the available devices.
<balloons> right.. It's not an issue for us to solve, as we don't currently define anything beyond that
<balloons> we as in, autopilot I mean to say
<elopio> but I see more problems on that, because we are going to be always outdated.
<elopio> maybe, what we are missing is an api method that tells us if the platform has a touch interface.
<balloons> well, I mean something perhaps that says this is a tablet or phone.. or at least this device supports multitouch, osk, etc, etc
<elopio> there are desktop monitors that can be touched, and there are phones that can't.
<balloons> indeed
<elopio> yes, we are definetly missing something.
<balloons> perhaps thomi will solve that when he adds the accelerometer stuff
<elopio> yes, all those things are related. Selenium has something called capabilities
<elopio> to check if a browser can do javascript, and things like that.
<elopio> and then they have drivers for each browser.
<elopio> it might make sense to group some capabilities on device drivers, and select which tests to run based on that. Or which devices to use, like on-screen keyboard vrs external keyboard.

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

<thomi> elopio: I don't think you need so many mocks in your tests
<thomi> elopio: in fact, you can do it with 0 mocks :)
<thomi> first you need to add @skipIf(model() != 'Desktop') and the inverse above each test
<thomi> then just create your emulator, and assert that the pointing device is an instance of Pointer

review: Needs Fixing
744. By Leo Arias

Put the return value on the decorator, as suggested by thomi.

745. By Leo Arias

Remove the model mock and skip the test if we are on the wrong device, as suggested by thomi.

Revision history for this message
Leo Arias (elopio) wrote :

<elopio> thomi: but then all the tests will never be run. And if jenkins executes on desktop, the touch case will never be executed.
<thomi> elopio: this is true, but we're supposed to be running our tests on *all the platforms* :)
<thomi> in that case, at least change your patch descriptor to something like:
<thomi> @patch('autopilot.model.platform', new=lambda: "Desktop")
<thomi> so you don't need to pass it in
<elopio> thomi: ok, I changed that.
<elopio> I could get rid of the pointer mock, but I would have to assert the _device attribute.
<elopio> as it starts with _, I found that a bad idea.
<thomi> elopio: also, you can't create a mouse on the touch
<thomi> so you *have* to mock it
<elopio> really?
<thomi> or fake it, either way
<thomi> yeah
<thomi> Mouse is X11
<thomi> no X11 on the device :-/
<thomi> until we get bindings to the mir input stack, our hands are tied there I'm afraid
<elopio> ok, then it doesn't make a lot of sense to run all the tests. I'll add the skips.
<elopio> thomi: pushed.
<elopio> thomi: would you prefer if I check the type of pointer._device instead of using the mock and checking the type of the argument?
<thomi> elopio: I'm cool either way :)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/ubuntuuitoolkit/emulators.py'
2--- tests/autopilot/ubuntuuitoolkit/emulators.py 2013-09-03 10:38:06 +0000
3+++ tests/autopilot/ubuntuuitoolkit/emulators.py 2013-09-03 20:31:27 +0000
4@@ -35,20 +35,22 @@
5 input_device_class = input.Mouse
6 else:
7 input_device_class = input.Touch
8- return input.Pointer(input_device_class.create())
9+ return input.Pointer(device=input_device_class.create())
10
11
12 class UbuntuUIToolkitEmulatorBase(dbus.CustomEmulatorBase):
13 """A base class for all the Ubuntu UI Toolkit emulators."""
14
15+ def __init__(self, *args):
16+ super(UbuntuUIToolkitEmulatorBase, self).__init__(*args)
17+ self.pointing_device = get_pointing_device()
18+ # TODO it would be nice to have access to the screen keyboard if we are
19+ # on the touch UI -- elopio - 2013-09-04
20+
21
22 class MainView(UbuntuUIToolkitEmulatorBase):
23 """MainView Autopilot emulator."""
24
25- def __init__(self, *args):
26- super(MainView, self).__init__(*args)
27- self.pointing_device = get_pointing_device()
28-
29 def get_header(self):
30 """Return the Header emulator of the MainView."""
31 return self.select_single('Header', objectName='MainView_Header')
32@@ -198,10 +200,6 @@
33 class Toolbar(UbuntuUIToolkitEmulatorBase):
34 """Toolbar Autopilot emulator."""
35
36- def __init__(self, *args):
37- super(Toolbar, self).__init__(*args)
38- self.pointing_device = get_pointing_device()
39-
40 def click_button(self, object_name):
41 """Click a button of the toolbar.
42
43@@ -233,10 +231,6 @@
44 class TabBar(UbuntuUIToolkitEmulatorBase):
45 """TabBar Autopilot emulator."""
46
47- def __init__(self, *args):
48- super(TabBar, self).__init__(*args)
49- self.pointing_device = get_pointing_device()
50-
51 def switch_to_next_tab(self):
52 """Open the next tab."""
53 # Click the tab bar to switch to selection mode.
54@@ -264,10 +258,6 @@
55 class ActionSelectionPopover(UbuntuUIToolkitEmulatorBase):
56 """ActionSelectionPopover Autopilot emulator."""
57
58- def __init__(self, *args):
59- super(ActionSelectionPopover, self).__init__(*args)
60- self.pointing_device = get_pointing_device()
61-
62 def click_button_by_text(self, text):
63 """Click a button on the popover.
64
65
66=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py'
67--- tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py 2013-09-03 10:19:24 +0000
68+++ tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py 2013-09-03 20:31:27 +0000
69@@ -14,11 +14,38 @@
70 # You should have received a copy of the GNU Lesser General Public License
71 # along with this program. If not, see <http://www.gnu.org/licenses/>.
72
73+import unittest
74+
75 import mock
76+import testtools
77+from autopilot import input, platform
78
79 from ubuntuuitoolkit import emulators, tests
80
81
82+class UbuntuUIToolkitEmulatorBaseTestCase(testtools.TestCase):
83+
84+ def test_pointing_device(self):
85+ emulator = emulators.UbuntuUIToolkitEmulatorBase({}, 'dummy_path')
86+ self.assertIsInstance(emulator.pointing_device, input.Pointer)
87+
88+ @mock.patch('autopilot.input.Pointer')
89+ @unittest.skipIf(platform.model() != 'Desktop', 'Desktop only')
90+ def test_pointing_device_in_desktop(self, mock_pointer):
91+ emulators.UbuntuUIToolkitEmulatorBase({}, 'dummy_path')
92+ mock_pointer.assert_called_once_with(device=mock.ANY)
93+ _, _, keyword_args = mock_pointer.mock_calls[0]
94+ self.assertIsInstance(keyword_args['device'], input.Mouse)
95+
96+ @mock.patch('autopilot.input.Pointer')
97+ @unittest.skipIf(platform.model() == 'Desktop', 'Phablet only')
98+ def test_pointing_device_in_phablet(self, mock_pointer):
99+ emulators.UbuntuUIToolkitEmulatorBase({}, 'dummy_path')
100+ mock_pointer.assert_called_once_with(device=mock.ANY)
101+ _, _, keyword_args = mock_pointer.mock_calls[0]
102+ self.assertIsInstance(keyword_args['device'], input.Touch)
103+
104+
105 class MainViewTestCase(tests.UbuntuUiToolkitTestCase):
106
107 test_qml = ("""

Subscribers

People subscribed via source and target branches

to status/vote changes: