Merge lp:~acerisara/ubuntu-calculator-app/suite-setup into lp:ubuntu-calculator-app

Proposed by Andrea Cerisara
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 42
Merged at revision: 42
Proposed branch: lp:~acerisara/ubuntu-calculator-app/suite-setup
Merge into: lp:ubuntu-calculator-app
Diff against target: 362 lines (+166/-157)
6 files modified
app/tests/autopilot/run (+1/-1)
app/tests/autopilot/ubuntu_calculator_app/__init__.py (+43/-130)
app/tests/autopilot/ubuntu_calculator_app/main/__init__.py (+0/-2)
app/tests/autopilot/ubuntu_calculator_app/main/test_main.py (+0/-24)
app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py (+104/-0)
app/tests/autopilot/ubuntu_calculator_app/tests/test_main.py (+18/-0)
To merge this branch: bzr merge lp:~acerisara/ubuntu-calculator-app/suite-setup
Reviewer Review Type Date Requested Status
Riccardo Padovani Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Needs Fixing
Review via email: mp+245265@code.launchpad.net

Commit message

Ported autopilot suite from old app.

Description of the change

Ported the autopilot suite infrastructure from the old app. Not sure this is enough to be considered a proper bootstrap :)

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Thanks for the effort, code looks good.
I merged in this other branch[0] to see if your branch resolves all issues with packaging we have.

If it works I'll approve this one. Otherwise, I'll evaluate results from Jenkins and choose how to go on.

Thanks again

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Ok, tested and fixed all Jenkins fails in this branch[0]

I approve this one and do manually merge, last one for this series \o/

[0]https://code.launchpad.net/~rpadovani/ubuntu-calculator-app/debianFolder141211/+merge/245269

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/tests/autopilot/run'
2--- app/tests/autopilot/run 2014-11-30 21:31:04 +0000
3+++ app/tests/autopilot/run 2014-12-20 17:57:55 +0000
4@@ -7,6 +7,6 @@
5
6 SCRIPTPATH=`dirname $0`
7 pushd ${SCRIPTPATH}
8-autopilot run ubuntu_calculator_app
9+autopilot3 run ubuntu_calculator_app
10 popd
11
12
13=== modified file 'app/tests/autopilot/ubuntu_calculator_app/__init__.py'
14--- app/tests/autopilot/ubuntu_calculator_app/__init__.py 2014-11-10 09:28:27 +0000
15+++ app/tests/autopilot/ubuntu_calculator_app/__init__.py 2014-12-20 17:57:55 +0000
16@@ -1,133 +1,46 @@
17 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
18-
19-"""Ubuntu Touch App autopilot tests."""
20-
21-from os import remove
22-import os.path
23-from tempfile import mktemp
24-import subprocess
25-
26-from autopilot.input import Mouse, Touch, Pointer
27-from autopilot.matchers import Eventually
28-from autopilot.platform import model
29-from testtools.matchers import Is, Not, Equals
30-from autopilot.testcase import AutopilotTestCase
31-
32-def get_module_include_path():
33- return os.path.abspath(
34- os.path.join(
35- os.path.dirname(__file__),
36- '..',
37- '..',
38- '..',
39- '..',
40- 'backend',
41- 'modules')
42- )
43-
44-
45-class UbuntuTouchAppTestCase(AutopilotTestCase):
46- """A common test case class that provides several useful methods for the tests."""
47-
48- if model() == 'Desktop':
49- scenarios = [
50- ('with mouse', dict(input_device_class=Mouse))
51- ]
52- else:
53- scenarios = [
54- ('with touch', dict(input_device_class=Touch))
55- ]
56+#
57+# Copyright (C) 2013 Canonical Ltd.
58+#
59+# This program is free software; you can redistribute it and/or modify
60+# it under the terms of the GNU Lesser General Public License as published by
61+# the Free Software Foundation; version 3.
62+#
63+# This program is distributed in the hope that it will be useful,
64+# but WITHOUT ANY WARRANTY; without even the implied warranty of
65+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66+# GNU Lesser General Public License for more details.
67+#
68+# You should have received a copy of the GNU Lesser General Public License
69+# along with this program. If not, see <http://www.gnu.org/licenses/>.
70+
71+"""Calculator app autopilot emulators."""
72+
73+import ubuntuuitoolkit
74+
75+
76+class CalculatorApp(object):
77+ """Autopilot helper object for the calculator application."""
78+
79+ def __init__(self, app_proxy, test_type):
80+ self.app = app_proxy
81+ self.test_type = test_type
82+ self.main_view = self.app.select_single(MainView)
83
84 @property
85- def main_window(self):
86- return MainWindow(self.app)
87-
88-
89- def setUp(self):
90- self.pointing_device = Pointer(self.input_device_class.create())
91- super(UbuntuTouchAppTestCase, self).setUp()
92- self.launch_test_qml()
93-
94-
95- def launch_test_qml(self):
96- # If the test class has defined a 'test_qml' class attribute then we
97- # write it to disk and launch it inside the QML Scene. If not, then we
98- # silently do nothing (presumably the test has something else planned).
99- arch = subprocess.check_output(["dpkg-architecture",
100- "-qDEB_HOST_MULTIARCH"]).strip()
101- if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
102- qml_path = mktemp(suffix='.qml')
103- open(qml_path, 'w').write(self.test_qml)
104- self.addCleanup(remove, qml_path)
105-
106- self.app = self.launch_test_application(
107- "/usr/lib/" + arch + "/qt5/bin/qmlscene",
108- "-I", get_module_include_path(),
109- qml_path,
110- app_type='qt')
111-
112- if hasattr(self, 'test_qml_file') and isinstance(self.test_qml_file, basestring):
113- qml_path = self.test_qml_file
114- self.app = self.launch_test_application(
115- "/usr/lib/" + arch + "/qt5/bin/qmlscene",
116- "-I", get_module_include_path(),
117- qml_path,
118- app_type='qt')
119-
120- self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))
121-
122-
123- def get_qml_view(self):
124- """Get the main QML view"""
125-
126- return self.app.select_single("QQuickView")
127-
128- def get_mainview(self):
129- """Get the QML MainView"""
130-
131- mainView = self.app.select_single("MainView")
132- self.assertThat(mainView, Not(Is(None)))
133- return mainView
134-
135-
136- def get_object(self,objectName):
137- """Get a object based on the objectName"""
138-
139- obj = self.app.select_single(objectName=objectName)
140- self.assertThat(obj, Not(Is(None)))
141- return obj
142-
143-
144- def mouse_click(self,objectName):
145- """Move mouse on top of the object and click on it"""
146-
147- obj = self.get_object(objectName)
148- self.pointing_device.move_to_object(obj)
149- self.pointing_device.click()
150-
151-
152- def mouse_press(self,objectName):
153- """Move mouse on top of the object and press mouse button (without releasing it)"""
154-
155- obj = self.get_object(objectName)
156- self.pointing_device.move_to_object(obj)
157- self.pointing_device.press()
158-
159-
160- def mouse_release(self):
161- """Release mouse button"""
162-
163- self.pointing_device.release()
164-
165-
166- def type_string(self, string):
167- """Type a string with keyboard"""
168-
169- self.keyboard.type(string)
170-
171-
172- def type_key(self, key):
173- """Type a single key with keyboard"""
174-
175- self.keyboard.key(key)
176-
177+ def pointing_device(self):
178+ return self.app.pointing_device
179+
180+
181+class MainView(ubuntuuitoolkit.MainView):
182+ """Calculator MainView Autopilot emulator."""
183+
184+ def __init__(self, *args):
185+ super(MainView, self).__init__(*args)
186+ self.visible.wait_for(True)
187+
188+ def clear(self):
189+ pass
190+
191+ def press(self, button):
192+ pass
193
194=== removed directory 'app/tests/autopilot/ubuntu_calculator_app/main'
195=== removed file 'app/tests/autopilot/ubuntu_calculator_app/main/__init__.py'
196--- app/tests/autopilot/ubuntu_calculator_app/main/__init__.py 2014-11-10 09:28:27 +0000
197+++ app/tests/autopilot/ubuntu_calculator_app/main/__init__.py 1970-01-01 00:00:00 +0000
198@@ -1,2 +0,0 @@
199-""" A main.qml test suite """
200-
201
202=== removed file 'app/tests/autopilot/ubuntu_calculator_app/main/test_main.py'
203--- app/tests/autopilot/ubuntu_calculator_app/main/test_main.py 2014-11-30 21:31:04 +0000
204+++ app/tests/autopilot/ubuntu_calculator_app/main/test_main.py 1970-01-01 00:00:00 +0000
205@@ -1,24 +0,0 @@
206-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
207-
208-"""Tests for the Hello World"""
209-
210-from autopilot.matchers import Eventually
211-from textwrap import dedent
212-from testtools.matchers import Is, Not, Equals
213-from testtools import skip
214-import os
215-from ubuntu_calculator_app import UbuntuTouchAppTestCase
216-
217-
218-class MainTests(UbuntuTouchAppTestCase):
219- """Generic tests for the Hello World"""
220-
221- test_qml_file = "%s/%s.qml" % (os.path.dirname(os.path.realpath(__file__)),"../../../../ubuntu_calculator_app")
222-
223- def test_0_can_select_mainView(self):
224- """Must be able to select the mainview."""
225-
226- mainView = self.get_mainview()
227- self.assertThat(mainView.visible,Eventually(Equals(True)))
228-
229-
230
231=== added directory 'app/tests/autopilot/ubuntu_calculator_app/tests'
232=== added file 'app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py'
233--- app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py 1970-01-01 00:00:00 +0000
234+++ app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2014-12-20 17:57:55 +0000
235@@ -0,0 +1,104 @@
236+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
237+#
238+# Copyright (C) 2013, 2014 Canonical Ltd
239+#
240+# This program is free software: you can redistribute it and/or modify
241+# it under the terms of the GNU General Public License version 3 as
242+# published by the Free Software Foundation.
243+#
244+# This program is distributed in the hope that it will be useful,
245+# but WITHOUT ANY WARRANTY; without even the implied warranty of
246+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
247+# GNU General Public License for more details.
248+#
249+# You should have received a copy of the GNU General Public License
250+# along with this program. If not, see <http://www.gnu.org/licenses/>.
251+
252+"""Calculator app autopilot tests."""
253+
254+import os
255+import shutil
256+import logging
257+
258+import ubuntu_calculator_app
259+
260+from autopilot.testcase import AutopilotTestCase
261+from autopilot import logging as autopilot_logging
262+
263+import ubuntuuitoolkit
264+from ubuntuuitoolkit import base
265+
266+logger = logging.getLogger(__name__)
267+
268+
269+class CalculatorAppTestCase(AutopilotTestCase):
270+ """A common test case class that provides several useful methods for
271+ the ubuntu-calculator-app tests.
272+
273+ """
274+
275+ local_location = os.path.dirname(os.path.dirname(os.getcwd()))
276+
277+ local_location_qml = os.path.join(local_location,
278+ 'ubuntu-calculator-app.qml')
279+
280+ installed_location_qml = os.path.join('/usr/share/ubuntu-calculator-app/',
281+ 'ubuntu-calculator-app.qml')
282+
283+ def get_launcher_and_type(self):
284+ if os.path.exists(self.local_location_qml):
285+ launcher = self.launch_test_local
286+ test_type = 'local'
287+ elif os.path.exists(self.installed_location_qml):
288+ launcher = self.launch_test_installed
289+ test_type = 'deb'
290+ else:
291+ launcher = self.launch_test_click
292+ test_type = 'click'
293+ return launcher, test_type
294+
295+ def setUp(self):
296+ super(CalculatorAppTestCase, self).setUp()
297+ self.clear_calculator_database()
298+ self.launcher, self.test_type = self.get_launcher_and_type()
299+
300+ # Unset the current locale to ensure locale-specific data
301+ # (day and month names, first day of the week, …) doesn’t get
302+ # in the way of test expectations.
303+ self.patch_environment('LC_ALL', 'C')
304+ self.app = ubuntu_calculator_app.CalculatorApp(self.launcher(),
305+ self.test_type)
306+
307+ @autopilot_logging.log_action(logger.info)
308+ def launch_test_local(self):
309+ return self.launch_test_application(
310+ base.get_qmlscene_launch_command(),
311+ self.local_location_qml,
312+ app_type='qt',
313+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
314+
315+ @autopilot_logging.log_action(logger.info)
316+ def launch_test_installed(self):
317+ return self.launch_test_application(
318+ base.get_qmlscene_launch_command(),
319+ self.installed_location_qml,
320+ app_type='qt',
321+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
322+
323+ @autopilot_logging.log_action(logger.info)
324+ def launch_test_click(self):
325+ return self.launch_click_package(
326+ "com.ubuntu.calculator",
327+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
328+
329+ def clear_calculator_database(self):
330+ calculator_database_path = os.path.join(
331+ os.path.expanduser('~'),
332+ '.local',
333+ 'share',
334+ 'com.ubuntu.calculator'
335+ )
336+
337+ if os.path.exists(calculator_database_path):
338+ shutil.rmtree(calculator_database_path)
339+ lambda: os.path.exists(calculator_database_path).wait_for(False)
340
341=== added file 'app/tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
342--- app/tests/autopilot/ubuntu_calculator_app/tests/test_main.py 1970-01-01 00:00:00 +0000
343+++ app/tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2014-12-20 17:57:55 +0000
344@@ -0,0 +1,18 @@
345+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
346+
347+"""Calculator app autopilot tests."""
348+
349+from autopilot.matchers import Eventually
350+from testtools.matchers import Equals
351+
352+from ubuntu_calculator_app.tests import CalculatorAppTestCase
353+
354+
355+class MainTestCase(CalculatorAppTestCase):
356+
357+ def setUp(self):
358+ super(MainTestCase, self).setUp()
359+
360+ def test_calculator_visible(self):
361+ self.assertThat(self.app.main_view.visible,
362+ Eventually(Equals(True)))

Subscribers

People subscribed via source and target branches