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
=== modified file 'app/tests/autopilot/run'
--- app/tests/autopilot/run 2014-11-30 21:31:04 +0000
+++ app/tests/autopilot/run 2014-12-20 17:57:55 +0000
@@ -7,6 +7,6 @@
77
8SCRIPTPATH=`dirname $0`8SCRIPTPATH=`dirname $0`
9pushd ${SCRIPTPATH}9pushd ${SCRIPTPATH}
10autopilot run ubuntu_calculator_app10autopilot3 run ubuntu_calculator_app
11popd11popd
1212
1313
=== modified file 'app/tests/autopilot/ubuntu_calculator_app/__init__.py'
--- app/tests/autopilot/ubuntu_calculator_app/__init__.py 2014-11-10 09:28:27 +0000
+++ app/tests/autopilot/ubuntu_calculator_app/__init__.py 2014-12-20 17:57:55 +0000
@@ -1,133 +1,46 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
22#
3"""Ubuntu Touch App autopilot tests."""3# Copyright (C) 2013 Canonical Ltd.
44#
5from os import remove5# This program is free software; you can redistribute it and/or modify
6import os.path6# it under the terms of the GNU Lesser General Public License as published by
7from tempfile import mktemp7# the Free Software Foundation; version 3.
8import subprocess8#
99# This program is distributed in the hope that it will be useful,
10from autopilot.input import Mouse, Touch, Pointer10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11from autopilot.matchers import Eventually11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12from autopilot.platform import model12# GNU Lesser General Public License for more details.
13from testtools.matchers import Is, Not, Equals13#
14from autopilot.testcase import AutopilotTestCase14# You should have received a copy of the GNU Lesser General Public License
1515# along with this program. If not, see <http://www.gnu.org/licenses/>.
16def get_module_include_path():16
17 return os.path.abspath(17"""Calculator app autopilot emulators."""
18 os.path.join(18
19 os.path.dirname(__file__),19import ubuntuuitoolkit
20 '..',20
21 '..',21
22 '..',22class CalculatorApp(object):
23 '..',23 """Autopilot helper object for the calculator application."""
24 'backend',24
25 'modules')25 def __init__(self, app_proxy, test_type):
26 )26 self.app = app_proxy
2727 self.test_type = test_type
2828 self.main_view = self.app.select_single(MainView)
29class UbuntuTouchAppTestCase(AutopilotTestCase):
30 """A common test case class that provides several useful methods for the tests."""
31
32 if model() == 'Desktop':
33 scenarios = [
34 ('with mouse', dict(input_device_class=Mouse))
35 ]
36 else:
37 scenarios = [
38 ('with touch', dict(input_device_class=Touch))
39 ]
4029
41 @property30 @property
42 def main_window(self):31 def pointing_device(self):
43 return MainWindow(self.app)32 return self.app.pointing_device
4433
4534
46 def setUp(self):35class MainView(ubuntuuitoolkit.MainView):
47 self.pointing_device = Pointer(self.input_device_class.create())36 """Calculator MainView Autopilot emulator."""
48 super(UbuntuTouchAppTestCase, self).setUp()37
49 self.launch_test_qml()38 def __init__(self, *args):
5039 super(MainView, self).__init__(*args)
5140 self.visible.wait_for(True)
52 def launch_test_qml(self):41
53 # If the test class has defined a 'test_qml' class attribute then we42 def clear(self):
54 # write it to disk and launch it inside the QML Scene. If not, then we43 pass
55 # silently do nothing (presumably the test has something else planned).44
56 arch = subprocess.check_output(["dpkg-architecture",45 def press(self, button):
57 "-qDEB_HOST_MULTIARCH"]).strip()46 pass
58 if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
59 qml_path = mktemp(suffix='.qml')
60 open(qml_path, 'w').write(self.test_qml)
61 self.addCleanup(remove, qml_path)
62
63 self.app = self.launch_test_application(
64 "/usr/lib/" + arch + "/qt5/bin/qmlscene",
65 "-I", get_module_include_path(),
66 qml_path,
67 app_type='qt')
68
69 if hasattr(self, 'test_qml_file') and isinstance(self.test_qml_file, basestring):
70 qml_path = self.test_qml_file
71 self.app = self.launch_test_application(
72 "/usr/lib/" + arch + "/qt5/bin/qmlscene",
73 "-I", get_module_include_path(),
74 qml_path,
75 app_type='qt')
76
77 self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))
78
79
80 def get_qml_view(self):
81 """Get the main QML view"""
82
83 return self.app.select_single("QQuickView")
84
85 def get_mainview(self):
86 """Get the QML MainView"""
87
88 mainView = self.app.select_single("MainView")
89 self.assertThat(mainView, Not(Is(None)))
90 return mainView
91
92
93 def get_object(self,objectName):
94 """Get a object based on the objectName"""
95
96 obj = self.app.select_single(objectName=objectName)
97 self.assertThat(obj, Not(Is(None)))
98 return obj
99
100
101 def mouse_click(self,objectName):
102 """Move mouse on top of the object and click on it"""
103
104 obj = self.get_object(objectName)
105 self.pointing_device.move_to_object(obj)
106 self.pointing_device.click()
107
108
109 def mouse_press(self,objectName):
110 """Move mouse on top of the object and press mouse button (without releasing it)"""
111
112 obj = self.get_object(objectName)
113 self.pointing_device.move_to_object(obj)
114 self.pointing_device.press()
115
116
117 def mouse_release(self):
118 """Release mouse button"""
119
120 self.pointing_device.release()
121
122
123 def type_string(self, string):
124 """Type a string with keyboard"""
125
126 self.keyboard.type(string)
127
128
129 def type_key(self, key):
130 """Type a single key with keyboard"""
131
132 self.keyboard.key(key)
133
13447
=== removed directory 'app/tests/autopilot/ubuntu_calculator_app/main'
=== removed file 'app/tests/autopilot/ubuntu_calculator_app/main/__init__.py'
--- app/tests/autopilot/ubuntu_calculator_app/main/__init__.py 2014-11-10 09:28:27 +0000
+++ app/tests/autopilot/ubuntu_calculator_app/main/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1""" A main.qml test suite """
2
30
=== removed file 'app/tests/autopilot/ubuntu_calculator_app/main/test_main.py'
--- app/tests/autopilot/ubuntu_calculator_app/main/test_main.py 2014-11-30 21:31:04 +0000
+++ app/tests/autopilot/ubuntu_calculator_app/main/test_main.py 1970-01-01 00:00:00 +0000
@@ -1,24 +0,0 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
3"""Tests for the Hello World"""
4
5from autopilot.matchers import Eventually
6from textwrap import dedent
7from testtools.matchers import Is, Not, Equals
8from testtools import skip
9import os
10from ubuntu_calculator_app import UbuntuTouchAppTestCase
11
12
13class MainTests(UbuntuTouchAppTestCase):
14 """Generic tests for the Hello World"""
15
16 test_qml_file = "%s/%s.qml" % (os.path.dirname(os.path.realpath(__file__)),"../../../../ubuntu_calculator_app")
17
18 def test_0_can_select_mainView(self):
19 """Must be able to select the mainview."""
20
21 mainView = self.get_mainview()
22 self.assertThat(mainView.visible,Eventually(Equals(True)))
23
24
250
=== added directory 'app/tests/autopilot/ubuntu_calculator_app/tests'
=== added file 'app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py'
--- app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2014-12-20 17:57:55 +0000
@@ -0,0 +1,104 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2013, 2014 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""Calculator app autopilot tests."""
18
19import os
20import shutil
21import logging
22
23import ubuntu_calculator_app
24
25from autopilot.testcase import AutopilotTestCase
26from autopilot import logging as autopilot_logging
27
28import ubuntuuitoolkit
29from ubuntuuitoolkit import base
30
31logger = logging.getLogger(__name__)
32
33
34class CalculatorAppTestCase(AutopilotTestCase):
35 """A common test case class that provides several useful methods for
36 the ubuntu-calculator-app tests.
37
38 """
39
40 local_location = os.path.dirname(os.path.dirname(os.getcwd()))
41
42 local_location_qml = os.path.join(local_location,
43 'ubuntu-calculator-app.qml')
44
45 installed_location_qml = os.path.join('/usr/share/ubuntu-calculator-app/',
46 'ubuntu-calculator-app.qml')
47
48 def get_launcher_and_type(self):
49 if os.path.exists(self.local_location_qml):
50 launcher = self.launch_test_local
51 test_type = 'local'
52 elif os.path.exists(self.installed_location_qml):
53 launcher = self.launch_test_installed
54 test_type = 'deb'
55 else:
56 launcher = self.launch_test_click
57 test_type = 'click'
58 return launcher, test_type
59
60 def setUp(self):
61 super(CalculatorAppTestCase, self).setUp()
62 self.clear_calculator_database()
63 self.launcher, self.test_type = self.get_launcher_and_type()
64
65 # Unset the current locale to ensure locale-specific data
66 # (day and month names, first day of the week, …) doesn’t get
67 # in the way of test expectations.
68 self.patch_environment('LC_ALL', 'C')
69 self.app = ubuntu_calculator_app.CalculatorApp(self.launcher(),
70 self.test_type)
71
72 @autopilot_logging.log_action(logger.info)
73 def launch_test_local(self):
74 return self.launch_test_application(
75 base.get_qmlscene_launch_command(),
76 self.local_location_qml,
77 app_type='qt',
78 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
79
80 @autopilot_logging.log_action(logger.info)
81 def launch_test_installed(self):
82 return self.launch_test_application(
83 base.get_qmlscene_launch_command(),
84 self.installed_location_qml,
85 app_type='qt',
86 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
87
88 @autopilot_logging.log_action(logger.info)
89 def launch_test_click(self):
90 return self.launch_click_package(
91 "com.ubuntu.calculator",
92 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
93
94 def clear_calculator_database(self):
95 calculator_database_path = os.path.join(
96 os.path.expanduser('~'),
97 '.local',
98 'share',
99 'com.ubuntu.calculator'
100 )
101
102 if os.path.exists(calculator_database_path):
103 shutil.rmtree(calculator_database_path)
104 lambda: os.path.exists(calculator_database_path).wait_for(False)
0105
=== added file 'app/tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
--- app/tests/autopilot/ubuntu_calculator_app/tests/test_main.py 1970-01-01 00:00:00 +0000
+++ app/tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2014-12-20 17:57:55 +0000
@@ -0,0 +1,18 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
3"""Calculator app autopilot tests."""
4
5from autopilot.matchers import Eventually
6from testtools.matchers import Equals
7
8from ubuntu_calculator_app.tests import CalculatorAppTestCase
9
10
11class MainTestCase(CalculatorAppTestCase):
12
13 def setUp(self):
14 super(MainTestCase, self).setUp()
15
16 def test_calculator_visible(self):
17 self.assertThat(self.app.main_view.visible,
18 Eventually(Equals(True)))

Subscribers

People subscribed via source and target branches