Merge lp:~elopio/ubuntu-calculator-app/emulators into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
- emulators
- Merge into old_trunk
Proposed by
Leo Arias
Status: | Merged |
---|---|
Approved by: | Nicholas Skaggs |
Approved revision: | 142 |
Merged at revision: | 127 |
Proposed branch: | lp:~elopio/ubuntu-calculator-app/emulators |
Merge into: | lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk |
Diff against target: |
760 lines (+342/-260) 7 files modified
Simple/Screen.qml (+1/-0) debian/control (+1/-0) tests/autopilot/ubuntu_calculator_app/emulators.py (+239/-0) tests/autopilot/ubuntu_calculator_app/emulators/__init__.py (+0/-6) tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py (+0/-32) tests/autopilot/ubuntu_calculator_app/tests/__init__.py (+9/-19) tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py (+92/-203) |
To merge this branch: | bzr merge lp:~elopio/ubuntu-calculator-app/emulators |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Nicholas Skaggs (community) | Approve | ||
Ubuntu Calculator Developers | Pending | ||
Review via email: mp+179166@code.launchpad.net |
Commit message
Updated the autopilot tests to use emulators.
Description of the change
To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote : | # |
Revision history for this message
Nicholas Skaggs (nskaggs) wrote : | # |
adding the wait_for covers my concerns.
review:
Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Simple/Screen.qml' |
2 | --- Simple/Screen.qml 2013-08-08 13:43:12 +0000 |
3 | +++ Simple/Screen.qml 2013-08-08 15:40:41 +0000 |
4 | @@ -237,6 +237,7 @@ |
5 | width: formulaLabel.operationsWidth |
6 | } |
7 | CalcLabel { |
8 | + objectName: _operation == "=" ? "result" : "operand" + index |
9 | id: formulaLabel |
10 | labelText: _text |
11 | numbers: _number |
12 | |
13 | === modified file 'debian/control' |
14 | --- debian/control 2013-05-18 09:52:21 +0000 |
15 | +++ debian/control 2013-08-08 15:40:41 +0000 |
16 | @@ -24,6 +24,7 @@ |
17 | Depends: ${shlibs:Depends}, |
18 | ${misc:Depends}, |
19 | ubuntu-calculator-app (= ${binary:Version}), |
20 | + ubuntu-ui-toolkit-autopilot, |
21 | libautopilot-qt, |
22 | python-support (>= 0.90) |
23 | Description: Autopilot tests for the calculator app for Ubuntu |
24 | |
25 | === removed directory 'tests/autopilot/ubuntu_calculator_app/emulators' |
26 | === added file 'tests/autopilot/ubuntu_calculator_app/emulators.py' |
27 | --- tests/autopilot/ubuntu_calculator_app/emulators.py 1970-01-01 00:00:00 +0000 |
28 | +++ tests/autopilot/ubuntu_calculator_app/emulators.py 2013-08-08 15:40:41 +0000 |
29 | @@ -0,0 +1,239 @@ |
30 | +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
31 | +# |
32 | +# Copyright (C) 2013 Canonical Ltd. |
33 | +# |
34 | +# This program is free software; you can redistribute it and/or modify |
35 | +# it under the terms of the GNU Lesser General Public License as published by |
36 | +# the Free Software Foundation; version 3. |
37 | +# |
38 | +# This program is distributed in the hope that it will be useful, |
39 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
40 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
41 | +# GNU Lesser General Public License for more details. |
42 | +# |
43 | +# You should have received a copy of the GNU Lesser General Public License |
44 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
45 | + |
46 | +"""Calculator app autopilot emulators.""" |
47 | + |
48 | +from ubuntuuitoolkit import emulators as toolkit_emulators |
49 | + |
50 | + |
51 | +class MainView(toolkit_emulators.MainView): |
52 | + """Calculator MainView Autopilot emulator.""" |
53 | + |
54 | + # TODO when we start the tests for the scientific calculator, many of this |
55 | + # methods will have to be moved to the SimplePage emulator, and the main |
56 | + # view can call them depending on the current page displayed. |
57 | + # --elopio - 2013-08-08 |
58 | + |
59 | + def __init__(self, *args): |
60 | + super(MainView, self).__init__(*args) |
61 | + self.pointing_device = toolkit_emulators.get_pointing_device() |
62 | + |
63 | + def clear_with_button(self): |
64 | + """Clear the calculation using the clear button.""" |
65 | + self.get_calc_keyboard().click_clear() |
66 | + |
67 | + def get_calc_keyboard(self): |
68 | + """Return the CalcKeyboard autopilot emulator.""" |
69 | + return self.select_single(CalcKeyboard) |
70 | + |
71 | + def calculate_operation(self, operation): |
72 | + """Calculate an operation. |
73 | + |
74 | + :parameter operation: A string with the operation to calculate. |
75 | + |
76 | + """ |
77 | + self.enter_operation(operation) |
78 | + self.get_calc_keyboard().click_equals() |
79 | + |
80 | + def enter_operation(self, operation): |
81 | + """Enter an operation. |
82 | + |
83 | + :parameter operation: A string with the operation to enter. |
84 | + |
85 | + """ |
86 | + self.get_calc_keyboard().enter_operation(operation) |
87 | + |
88 | + def change_sign(self): |
89 | + """Change the sign of the last operand.""" |
90 | + self.get_calc_keyboard().click_sign() |
91 | + |
92 | + def get_result(self): |
93 | + """Return the result of a calculation.""" |
94 | + return self.get_current_screen().get_result() |
95 | + |
96 | + def get_current_screen(self): |
97 | + """Return the screen for the current calculation.""" |
98 | + count = self.get_number_of_screens() |
99 | + return self.select_many(Screen)[count - 1] |
100 | + |
101 | + def get_operand_by_index(self, index): |
102 | + """Return an operand of a calculation entered.""" |
103 | + return self.get_current_screen().get_operand_by_index(index) |
104 | + |
105 | + def clear_with_swipe(self): |
106 | + """Clear the calculation making a swipe on the screen.""" |
107 | + self.get_current_screen().swipe_up() |
108 | + self._wait_for_screen_to_finish_animation() |
109 | + |
110 | + def _wait_for_screen_to_finish_animation(self): |
111 | + qquicklistview = self.select_single('QQuickListView') |
112 | + qquicklistview.moving.wait_for(False) |
113 | + |
114 | + def is_cleared(self): |
115 | + """Return True if the screen has no calculation. False otherwise.""" |
116 | + return self.get_current_screen().is_cleared() |
117 | + |
118 | + def get_screen_by_index(self, index): |
119 | + """Return a screen.""" |
120 | + return self._get_screens()[index] |
121 | + |
122 | + def _get_screens(self): |
123 | + return self.select_many(Screen) |
124 | + |
125 | + def get_number_of_screens(self): |
126 | + """Return the number of screens.""" |
127 | + return len(self._get_screens()) |
128 | + |
129 | + def swipe_previous_calculation_into_view(self, screen_index): |
130 | + previous_screen = self.get_screen_by_index(screen_index) |
131 | + _, prev_screen_y, _, prev_screen_h = previous_screen.globalRect |
132 | + x, y, w, h = self.globalRect |
133 | + start_x = stop_x = x + w / 2 |
134 | + start_y = y + h / 2 |
135 | + stop_y = start_y + y - prev_screen_y |
136 | + self.pointing_device.drag(start_x, start_y, stop_x, stop_y) |
137 | + self._wait_for_screen_to_finish_animation() |
138 | + |
139 | + def delete_previous_calculation(self, screen_index, confirm): |
140 | + """Delete an old calculation. |
141 | + |
142 | + :parameter screen_index: If index of the screen with the calculation |
143 | + to delete. |
144 | + :parameter confirm: If True, the deletion will be confimed. If False, |
145 | + it will be canceled. |
146 | + |
147 | + """ |
148 | + self.swipe_previous_calculation_into_view(screen_index) |
149 | + screen = self.get_screen_by_index(screen_index) |
150 | + screen.swipe_to_left() |
151 | + self._wait_for_screen_to_finish_animation() |
152 | + if confirm: |
153 | + screen.confirm_delete() |
154 | + else: |
155 | + raise NotImplementedError('Not yet implemented.') |
156 | + |
157 | + |
158 | +class CalcKeyboard(toolkit_emulators.UbuntuUIToolkitEmulatorBase): |
159 | + """CalcKeyboard Autopilot emulator.""" |
160 | + |
161 | + _BUTTONS_DICT = { |
162 | + "0": "zeroButton", |
163 | + "1": "oneButton", |
164 | + "2": "twoButton", |
165 | + "3": "threeButton", |
166 | + "4": "fourButton", |
167 | + "5": "fiveButton", |
168 | + "6": "sixButton", |
169 | + "7": "sevenButton", |
170 | + "8": "eightButton", |
171 | + "9": "nineButton", |
172 | + "+": "plusButton", |
173 | + "-": "minusButton", |
174 | + "/": "divideButton", |
175 | + "*": "multiplyButton", |
176 | + } |
177 | + |
178 | + def __init__(self, *args): |
179 | + super(CalcKeyboard, self).__init__(*args) |
180 | + self.pointing_device = toolkit_emulators.get_pointing_device() |
181 | + |
182 | + def click_clear(self): |
183 | + """Click the clear button.""" |
184 | + clear_button = self._get_keyboard_button('clearButton') |
185 | + self.pointing_device.click_object(clear_button) |
186 | + |
187 | + def _get_keyboard_button(self, objectName): |
188 | + return self.select_single('KeyboardButton', objectName=objectName) |
189 | + |
190 | + def enter_operation(self, operation): |
191 | + """Enter an operation on the calculator. |
192 | + |
193 | + :parameter operation: A string with the operation to enter. |
194 | + |
195 | + """ |
196 | + for char in operation: |
197 | + button = self._get_keyboard_button(self._BUTTONS_DICT[char]) |
198 | + self.pointing_device.click_object(button) |
199 | + |
200 | + def click_equals(self): |
201 | + """Click the equals button.""" |
202 | + equals_button = self._get_keyboard_button('equalsButton') |
203 | + self.pointing_device.click_object(equals_button) |
204 | + |
205 | + def click_sign(self): |
206 | + """Click the sign button.""" |
207 | + sign_button = self._get_keyboard_button('signButton') |
208 | + self.pointing_device.click_object(sign_button) |
209 | + |
210 | + |
211 | +class Screen(toolkit_emulators.UbuntuUIToolkitEmulatorBase): |
212 | + """Screen Autopilot emulator.""" |
213 | + |
214 | + def __init__(self, *args): |
215 | + super(Screen, self).__init__(*args) |
216 | + self.pointing_device = toolkit_emulators.get_pointing_device() |
217 | + |
218 | + def get_result(self): |
219 | + """Return the result of a calculation.""" |
220 | + result_label = self.get_result_label() |
221 | + assert result_label is not None, 'No result displayed.' |
222 | + return result_label.numbers |
223 | + |
224 | + def get_result_label(self): |
225 | + return self.select_single('CalcLabel', objectName='result') |
226 | + |
227 | + def get_operand_by_index(self, index): |
228 | + """Return an operand of a calculation entered.""" |
229 | + operand_label = self.select_single( |
230 | + 'CalcLabel', objectName='operand{0}'.format(index)) |
231 | + assert operand_label is not None, 'No operand with index {0}.'.format( |
232 | + index) |
233 | + return operand_label.numbers |
234 | + |
235 | + def swipe_up(self): |
236 | + """Swipe up on the screen to clear the calculation.""" |
237 | + x, y, w, h = self.globalRect |
238 | + tx = x + (w / 2) |
239 | + ty = y + (h / 2) |
240 | + |
241 | + self.pointing_device.drag(tx, ty + h, tx, ty - h) |
242 | + |
243 | + def is_cleared(self): |
244 | + """Return True if the screen has no calculation. False otherwise.""" |
245 | + return (self.get_result_label() is None and |
246 | + self._get_number_of_labels() == 1 and |
247 | + self.get_operand_by_index(0) == "") |
248 | + |
249 | + def _get_number_of_labels(self): |
250 | + return len(self.select_many('CalcLabel')) |
251 | + |
252 | + def swipe_to_left(self): |
253 | + """Swipe the screen to the left. |
254 | + |
255 | + If it's an old calculation, a delete dialog will appear. |
256 | + |
257 | + """ |
258 | + x, y, w, h = self.globalRect |
259 | + tx = x + (w - w / 8) |
260 | + ty = y + (h / 2) |
261 | + self.pointing_device.drag(tx, ty, tx / 8, ty) |
262 | + |
263 | + def confirm_delete(self): |
264 | + """Confirm the deletion of the calculation.""" |
265 | + delete_button = self.select_single( |
266 | + 'Button', objectName='calculationDelete') |
267 | + delete_button.visible.wait_for(True) |
268 | + self.pointing_device.click_object(delete_button) |
269 | |
270 | === removed file 'tests/autopilot/ubuntu_calculator_app/emulators/__init__.py' |
271 | --- tests/autopilot/ubuntu_calculator_app/emulators/__init__.py 2013-03-22 12:15:46 +0000 |
272 | +++ tests/autopilot/ubuntu_calculator_app/emulators/__init__.py 1970-01-01 00:00:00 +0000 |
273 | @@ -1,6 +0,0 @@ |
274 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
275 | -# Copyright 2013 Canonical |
276 | -# |
277 | -# This program is free software: you can redistribute it and/or modify it |
278 | -# under the terms of the GNU General Public License version 3, as published |
279 | -# by the Free Software Foundation. |
280 | |
281 | === removed file 'tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py' |
282 | --- tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py 2013-08-02 03:01:14 +0000 |
283 | +++ tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py 1970-01-01 00:00:00 +0000 |
284 | @@ -1,32 +0,0 @@ |
285 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
286 | -# Copyright 2013 Canonical |
287 | -# |
288 | -# This program is free software: you can redistribute it and/or modify it |
289 | -# under the terms of the GNU General Public License version 3, as published |
290 | -# by the Free Software Foundation. |
291 | - |
292 | - |
293 | -class SimplePage(object): |
294 | - """An emulator class that makes it easy to interact with the call panel.""" |
295 | - def __init__(self, app): |
296 | - self.app = app |
297 | - |
298 | - def get_button(self, text): |
299 | - return self.app.select_single('KeyboardButton', text=text) |
300 | - |
301 | - def get_formula_label(self): |
302 | - return self.app.select_single('CalcLabel', isLast=True) |
303 | - |
304 | - def get_calc_label(self, numbers): |
305 | - return self.app.select_single('CalcLabel', numbers=numbers) |
306 | - |
307 | - def get_screen(self): |
308 | - return self.app.select_many("Screen")[0] |
309 | - |
310 | - def get_confirm_delete_button(self): |
311 | - return self.app.select_single( |
312 | - "Button", objectName="calculationDelete", visible=True) |
313 | - |
314 | - def get_main_screen_qqlv(self): |
315 | - page = self.app.select_single("SimplePage") |
316 | - return page.select_single("QQuickListView") |
317 | |
318 | === modified file 'tests/autopilot/ubuntu_calculator_app/tests/__init__.py' |
319 | --- tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-07-14 22:05:48 +0000 |
320 | +++ tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-08-08 15:40:41 +0000 |
321 | @@ -12,9 +12,9 @@ |
322 | from autopilot.input import Mouse, Touch, Pointer |
323 | from autopilot.platform import model |
324 | from autopilot.testcase import AutopilotTestCase |
325 | - |
326 | - |
327 | -from ubuntu_calculator_app.emulators.simple_page import SimplePage |
328 | +from ubuntuuitoolkit import emulators as toolkit_emulators |
329 | + |
330 | +from ubuntu_calculator_app import emulators |
331 | |
332 | |
333 | class CalculatorTestCase(AutopilotTestCase): |
334 | @@ -43,7 +43,8 @@ |
335 | self.app = self.launch_test_application( |
336 | "qmlscene", |
337 | self.local_location, |
338 | - app_type='qt') |
339 | + app_type='qt', |
340 | + emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
341 | |
342 | def launch_test_installed(self): |
343 | self.app = self.launch_test_application( |
344 | @@ -51,20 +52,9 @@ |
345 | "/usr/share/ubuntu-calculator-app/ubuntu-calculator-app.qml", |
346 | "--desktop_file_hint=" |
347 | "/usr/share/applications/ubuntu-calculator-app.desktop", |
348 | - app_type='qt') |
349 | - |
350 | - def click_button(self, object_name): |
351 | - button = self.app.select_single( |
352 | - 'KeyboardButton', objectName=object_name + "Button") |
353 | - |
354 | - x, y, h, w = button.globalRect |
355 | - |
356 | - tx = x + (h / 2) |
357 | - ty = y + (w / 2) |
358 | - |
359 | - self.pointing_device.move(tx, ty) |
360 | - self.pointing_device.click() |
361 | + app_type='qt', |
362 | + emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
363 | |
364 | @property |
365 | - def simple_page(self): |
366 | - return SimplePage(self.app) |
367 | + def main_view(self): |
368 | + return self.app.select_single(emulators.MainView) |
369 | |
370 | === modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py' |
371 | --- tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py 2013-08-02 13:40:05 +0000 |
372 | +++ tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py 2013-08-08 15:40:41 +0000 |
373 | @@ -1,295 +1,184 @@ |
374 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
375 | -# Copyright 2013 Canonical |
376 | -# |
377 | -# This program is free software: you can redistribute it and/or modify it |
378 | -# under the terms of the GNU General Public License version 3, as published |
379 | -# by the Free Software Foundation. |
380 | - |
381 | +# |
382 | +# Copyright (C) 2013 Canonical Ltd. |
383 | +# |
384 | +# This program is free software; you can redistribute it and/or modify |
385 | +# it under the terms of the GNU Lesser General Public License as published by |
386 | +# the Free Software Foundation; version 3. |
387 | +# |
388 | +# This program is distributed in the hope that it will be useful, |
389 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
390 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
391 | +# GNU Lesser General Public License for more details. |
392 | +# |
393 | +# You should have received a copy of the GNU Lesser General Public License |
394 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
395 | |
396 | """Tests for the Calculator App""" |
397 | |
398 | from __future__ import absolute_import |
399 | |
400 | -from testtools.matchers import Equals, NotEquals |
401 | +from testtools.matchers import Equals |
402 | from autopilot.matchers import Eventually |
403 | |
404 | from ubuntu_calculator_app.tests import CalculatorTestCase |
405 | -from ubuntu_calculator_app.emulators.simple_page import SimplePage |
406 | - |
407 | -import os.path |
408 | -import unittest |
409 | -from types import IntType |
410 | |
411 | |
412 | class TestSimplePage(CalculatorTestCase): |
413 | |
414 | - _BUTTONS_DICT = { |
415 | - "0": "zero", |
416 | - "1": "one", |
417 | - "2": "two", |
418 | - "3": "three", |
419 | - "4": "four", |
420 | - "5": "five", |
421 | - "6": "six", |
422 | - "7": "seven", |
423 | - "8": "eight", |
424 | - "9": "nine", |
425 | - "+": "plus", |
426 | - "-": "minus", |
427 | - "/": "divide", |
428 | - "*": "multiply", |
429 | - "=": "equals", |
430 | - } |
431 | + def setUp(self): |
432 | + super(TestSimplePage, self).setUp() |
433 | + self.addCleanup(self._delete_old_calculations) |
434 | |
435 | - @property |
436 | - def simple_page(self): |
437 | - return SimplePage(self.app) |
438 | + def _delete_old_calculations(self): |
439 | + while self.main_view.get_number_of_screens() > 1: |
440 | + self.main_view.delete_previous_calculation(0, confirm=True) |
441 | |
442 | def test_operation_after_clear(self): |
443 | """ Test that after clearing one calculation, the next is still correct |
444 | (bug #1164973). |
445 | |
446 | """ |
447 | - self._calculate("1+1") |
448 | - |
449 | - # make sure the result is already there |
450 | - self._assert_result("2") |
451 | - |
452 | - # now clear the input by pressing "AC" |
453 | - self.click_button("clear") |
454 | - |
455 | - self._calculate("1+1") |
456 | - |
457 | - # make sure the result is correct |
458 | - self._assert_result("2") |
459 | - |
460 | - def _calculate(self, operation): |
461 | - self._click_buttons(operation + "=") |
462 | - |
463 | - def _tear_off(self, operation): |
464 | - self._calculate(operation) |
465 | - screen = self.simple_page.get_screen() |
466 | - x, y, w, h = screen.globalRect |
467 | - tx = x + (w / 2) |
468 | - ty = y + (h / 2) |
469 | - |
470 | - self.pointing_device.drag(tx, ty + h, tx, ty - h) |
471 | - |
472 | - self._assert_result("") |
473 | - |
474 | - def _delete_last_calculation(self): |
475 | - screen = self.simple_page.get_screen() |
476 | - quick_list_view = self.simple_page.get_main_screen_qqlv() |
477 | - |
478 | - x, y, w, h = screen.globalRect |
479 | - tx = x + (w - w / 8) |
480 | - ty = y + (h / 2) |
481 | - self.pointing_device.drag(tx, ty, tx / 8, ty) |
482 | - self.pointing_device.drag(tx, ty, tx, ty + h) |
483 | - |
484 | - self.assertThat(quick_list_view.moving, Eventually(Equals(False))) |
485 | - |
486 | - delete_button = self.simple_page.get_confirm_delete_button() |
487 | - self.pointing_device.click_object(delete_button) |
488 | - |
489 | - def _click_buttons(self, input_): |
490 | - for char in input_: |
491 | - self.click_button(self._BUTTONS_DICT[char]) |
492 | + self.main_view.calculate_operation("1+1") |
493 | + self._assert_result("2") |
494 | + self.main_view.clear_with_button() |
495 | + self.main_view.calculate_operation("1+1") |
496 | + self._assert_result("2") |
497 | |
498 | def _assert_result(self, expected_result): |
499 | - get_result = lambda: self.simple_page.get_formula_label().numbers |
500 | - self.assertThat( |
501 | - get_result, Eventually(Equals(expected_result))) |
502 | - |
503 | - def _close_and_reopen(self): |
504 | - # See #1188292, there is a bug in SDK that prevents to use terminate |
505 | - #self.simple_page.app.process.terminate() |
506 | - #self.simple_page.app.process.wait() |
507 | - |
508 | - screen = self.simple_page.get_screen() |
509 | - x, y, w, h = screen.globalRect |
510 | - |
511 | - self.pointing_device.move(x + (w / 25), y + h / 2.7) |
512 | - self.pointing_device.click() |
513 | - |
514 | - self.simple_page.app.process.wait() |
515 | - |
516 | - local_location = "../../ubuntu-calculator-app.qml" |
517 | - |
518 | - # Yes, I know, it's a duplication of CalculatorTestCase().setUp(), |
519 | - # but I didn't find a better way to implement it |
520 | - if os.path.exists(local_location): |
521 | - self.app = self.launch_test_application( |
522 | - "qmlscene", |
523 | - local_location, |
524 | - app_type='qt') |
525 | - else: |
526 | - self.app = self.launch_test_application( |
527 | - "qmlscene", |
528 | - "/usr/share/ubuntu-calculator-app/ubuntu-calculator-app.qml", |
529 | - "--desktop_file_hint=" |
530 | - "/usr/share/applications/ubuntu-calculator-app.desktop", |
531 | - app_type='qt') |
532 | - |
533 | - # Check if windows has been launch |
534 | - self.assertThat( |
535 | - self.simple_page.app.select_single("QQuickView").visible, |
536 | - Eventually(Equals(True))) |
537 | + self.assertThat( |
538 | + self.main_view.get_result, Eventually(Equals(expected_result))) |
539 | + |
540 | + def test_enter_operand(self): |
541 | + self.main_view.enter_operation("123") |
542 | + self.assertEqual(self.main_view.get_operand_by_index(0), "123") |
543 | |
544 | def test_equals_dont_change_numbers(self): |
545 | """ Test that typing a number and pressing "=" won't change the number |
546 | (bug #1165894). |
547 | |
548 | """ |
549 | - self._click_buttons("123") |
550 | - |
551 | - # check that the label is displaying correctly |
552 | - self._assert_result("123") |
553 | - |
554 | - # click the "=" button |
555 | - self._click_buttons("=") |
556 | + self.main_view.enter_operation("123") |
557 | + self.main_view.get_calc_keyboard().click_equals() |
558 | |
559 | # check that the label is still displaying correctly |
560 | - self._assert_result("123") |
561 | + self.assertEqual(self.main_view.get_operand_by_index(0), "123") |
562 | |
563 | def test_multiply_priority(self): |
564 | """Multiply is done before addition or substraction.""" |
565 | - self._calculate("2+2*2") |
566 | + self.main_view.calculate_operation("2+2*2") |
567 | self._assert_result("6") |
568 | |
569 | def test_divide_priority(self): |
570 | """Divide is done before addition or substraction.""" |
571 | - self._calculate("5+6/2") |
572 | + self.main_view.calculate_operation("5+6/2") |
573 | self._assert_result("8") |
574 | |
575 | def test_swipe_up_clears(self): |
576 | - """Make sure swiping up clears the formulae label.""" |
577 | - screen = self.simple_page.get_screen() |
578 | - self._click_buttons("9") |
579 | - |
580 | - x, y, w, h = screen.globalRect |
581 | - tx = x + (w / 2) |
582 | - ty = y + (h / 2) |
583 | - |
584 | - self.pointing_device.drag(tx, ty + h, tx, ty - h) |
585 | - |
586 | - self._assert_result("") |
587 | + """Make sure swiping up clears the formula label.""" |
588 | + self.main_view.enter_operation("9") |
589 | + self.main_view.clear_with_swipe() |
590 | + self.assertThat(self.main_view.is_cleared, Eventually(Equals(True))) |
591 | |
592 | def test_sign_button(self): |
593 | """Ensure the sign button is working.""" |
594 | - self._click_buttons("5+") |
595 | - self.click_button("sign") |
596 | - self._click_buttons("1=") |
597 | + calc_keyboard = self.main_view.get_calc_keyboard() |
598 | + calc_keyboard.enter_operation("5+") |
599 | + calc_keyboard.click_sign() |
600 | + calc_keyboard.enter_operation("1") |
601 | + calc_keyboard.click_equals() |
602 | |
603 | self._assert_result("4") |
604 | |
605 | def test_addition(self): |
606 | - self._calculate("4+2") |
607 | + self.main_view.calculate_operation("4+2") |
608 | self._assert_result("6") |
609 | |
610 | def test_substraction(self): |
611 | - self._calculate("5-4") |
612 | + self.main_view.calculate_operation("5-4") |
613 | self._assert_result("1") |
614 | |
615 | def test_positive_numbers_multiplication(self): |
616 | - self._calculate("2*3") |
617 | + self.main_view.calculate_operation("2*3") |
618 | self._assert_result("6") |
619 | |
620 | def test_multiplication_by_zero(self): |
621 | - self._calculate("4*0") |
622 | + self.main_view.calculate_operation("4*0") |
623 | self._assert_result("0") |
624 | |
625 | def test_one_negative_number_multiplication(self): |
626 | - self._calculate("-3*4") |
627 | + self.main_view.calculate_operation("-3*4") |
628 | self._assert_result("-12") |
629 | |
630 | def test_two_negative_numbers_multiplication(self): |
631 | - self._calculate("-2*-3") |
632 | + self.main_view.calculate_operation("-2*-3") |
633 | self._assert_result("6") |
634 | |
635 | def test_three_positive_numbers_multiplication(self): |
636 | - self._calculate("2*3*10") |
637 | + self.main_view.calculate_operation("2*3*10") |
638 | self._assert_result("60") |
639 | |
640 | def test_two_negatives_in_three_numbers_multiplication(self): |
641 | - self._calculate("-2*-3*5") |
642 | + self.main_view.calculate_operation("-2*-3*5") |
643 | self._assert_result("30") |
644 | |
645 | def test_three_negative_numbers_multiplication(self): |
646 | - self._calculate("-4*-5*-7") |
647 | + self.main_view.calculate_operation("-4*-5*-7") |
648 | self._assert_result("-140") |
649 | |
650 | def test_divide_positive(self): |
651 | - self._calculate("4/2") |
652 | + self.main_view.calculate_operation("4/2") |
653 | self._assert_result("2") |
654 | |
655 | def test_divide_negative(self): |
656 | - self._calculate("4/-2") |
657 | + self.main_view.calculate_operation("4/-2") |
658 | self._assert_result("-2") |
659 | |
660 | def test_divide_two_negatives(self): |
661 | - self._calculate("-4/-2") |
662 | + self.main_view.calculate_operation("-4/-2") |
663 | self._assert_result("2") |
664 | |
665 | def test_divide_with_zero(self): |
666 | - self._calculate("0/4") |
667 | + self.main_view.calculate_operation("0/4") |
668 | self._assert_result("0") |
669 | |
670 | def test_divide_by_zero(self): |
671 | - self._calculate("4/0") |
672 | - result_box = self.simple_page.get_formula_label().numbers |
673 | - |
674 | - self.assertThat( |
675 | - lambda: type(result_box) is not IntType, Eventually(Equals(True))) |
676 | - |
677 | - def test_tear_off(self): |
678 | - """Test tear off adds calculation to history""" |
679 | - quick_list_view = self.simple_page.get_main_screen_qqlv() |
680 | - num_calc_sections_old = int(quick_list_view.count) |
681 | - # Do the calc |
682 | - self._tear_off("9+5") |
683 | - |
684 | - # Check if has been saved |
685 | - self.assertThat( |
686 | - lambda: num_calc_sections_old, |
687 | - Eventually(NotEquals(quick_list_view.count))) |
688 | + self.main_view.calculate_operation("4/0") |
689 | + self._assert_result("Infinity") |
690 | + |
691 | + def test_swipe_up_with_result(self): |
692 | + """Test swipe up adds calculation to history""" |
693 | + self.main_view.calculate_operation("9+8") |
694 | + self.main_view.clear_with_swipe() |
695 | + |
696 | + self.assertThat( |
697 | + self.main_view.get_number_of_screens, Eventually(Equals(2))) |
698 | + self.assertTrue( |
699 | + self.main_view.get_screen_by_index(1).is_cleared()) |
700 | + self.assertEquals( |
701 | + self.main_view.get_screen_by_index(0).get_result(), "17") |
702 | |
703 | def test_swipe_delete_calculation_right_left(self): |
704 | - """Try to delete a calculation swiping it from right to left""" |
705 | - quick_list_view = self.simple_page.get_main_screen_qqlv() |
706 | - num_calc_sections_old = int(quick_list_view.count) |
707 | - # Do the calc |
708 | - self._tear_off("9+5") |
709 | - |
710 | - # Delete the calculation |
711 | - self._delete_last_calculation() |
712 | - # Check if has been deleted |
713 | + """Delete a calculation swiping it from right to left""" |
714 | + self.main_view.calculate_operation("9+5") |
715 | + self.main_view.clear_with_swipe() |
716 | + |
717 | + self.main_view.swipe_previous_calculation_into_view(0) |
718 | + self.main_view.delete_previous_calculation(0, confirm=True) |
719 | + |
720 | self.assertThat( |
721 | - lambda: num_calc_sections_old, |
722 | - Eventually(Equals(quick_list_view.count))) |
723 | + self.main_view.get_number_of_screens, Eventually(Equals(1))) |
724 | |
725 | def test_click_history(self): |
726 | - """Try to do a calculation using history items""" |
727 | - # Do the calc |
728 | - self._tear_off("19+1") |
729 | - |
730 | - # Clic on calc |
731 | - calc = self.simple_page.get_calc_label("20") |
732 | - self.pointing_device.click_object(calc) |
733 | - |
734 | - self._calculate("+5") |
735 | + """Do a calculation using history items.""" |
736 | + self.main_view.calculate_operation("19+1") |
737 | + self.main_view.clear_with_swipe() |
738 | + |
739 | + result_label = self.main_view.get_screen_by_index(0).get_result_label() |
740 | + self.pointing_device.click_object(result_label) |
741 | + |
742 | + calc_keyboard = self.main_view.get_calc_keyboard() |
743 | + calc_keyboard.enter_operation("+5") |
744 | + calc_keyboard.click_equals() |
745 | + |
746 | self._assert_result("25") |
747 | - |
748 | - @unittest.skip("We are doing things wrong on so many levels, we are \ |
749 | - trying to click the close button with magic numbers which we \ |
750 | - cannot rely on, also on touch devices there is no such thing as \ |
751 | - close button, skipping this test for now till we find a better \ |
752 | - solution. bug 1207593") |
753 | - def test_save_calculation_between_reload(self): |
754 | - # Do the calc |
755 | - self._tear_off("44-2") |
756 | - |
757 | - self._close_and_reopen() |
758 | - |
759 | - label = lambda: self.simple_page.get_calc_label("42") |
760 | - self.assertThat(label, Eventually(NotEquals(None))) |
Per IRC, commenting on trying to do more to remove the sleep. The rest of the code looks good -- glad to see another suite converted :-)