Merge lp:~nskaggs/ubuntu-calculator-app/drop-fixtures into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 340
Merged at revision: 333
Proposed branch: lp:~nskaggs/ubuntu-calculator-app/drop-fixtures
Merge into: lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
Diff against target: 200 lines (+91/-61)
2 files modified
README.autopilot (+61/-0)
tests/autopilot/ubuntu_calculator_app/tests/__init__.py (+30/-61)
To merge this branch: bzr merge lp:~nskaggs/ubuntu-calculator-app/drop-fixtures
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Riccardo Padovani Approve
Review via email: mp+237848@code.launchpad.net

Commit message

This drops support for patching home via fixtures; instead the current user's home directory is assumed properly setup

Description of the change

This drops support for patching home via fixtures, and instead waits for a better fix from https://bugs.launchpad.net/ubuntu-app-launch/+bug/1376423.

If you run these tests without a test runner to setup the environment, these tests will modify the current user's home folder.

To post a comment you must log in.
337. By Nicholas Skaggs

add autopilot readme

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

Confirming no apparmor errors present on RTM, image 92, using only these changes.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
338. By Nicholas Skaggs

switch to mocking on desktop only

339. By Nicholas Skaggs

update readme

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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
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 :

Didn't test on a device, but sounds reasonable. Anyway, there is a little type (see inline comment)

review: Needs Fixing
340. By Nicholas Skaggs

fix typo

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

lgtm

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'README.autopilot'
2--- README.autopilot 1970-01-01 00:00:00 +0000
3+++ README.autopilot 2014-10-09 21:48:24 +0000
4@@ -0,0 +1,61 @@
5+# Running Autopilot tests
6+
7+Ubuntu Calculator App follows a test driven development where autopilot tests are run before every merge into trunk. If you are submitting your bugfix/patch to the calculator app, please follow the following steps below to ensure that all tests pass before proposing a merge request.
8+
9+If you are looking for more info about Autopilot or writing AP tests for the calculator app, here are some useful links to help you,
10+
11+- http://developer.ubuntu.com/api/devel/ubuntu-14.10/python/autopilot/
12+- http://developer.ubuntu.com/api/devel/ubuntu-14.10/python/autopilot-emulator/
13+
14+## Prerequisites
15+
16+Install the following autopilot packages required to run the tests,
17+$ sudo apt-get install python-autopilot libautopilot-qt ubuntu-ui-toolkit-autopilot python3-autopilot-vis
18+
19+NOTE, running the autopilot tests as yourself will run and modify your home directory on confined platforms (like the phone). For now, the desktop will still run inside a mocked /home.
20+
21+
22+## Running tests on the desktop
23+
24+Using terminal:
25+
26+* Branch the calculator app code,
27+ $ bzr branch lp:ubuntu-calculator-app
28+
29+* Navigate to the tests/autopilot directory.
30+ $ cd ubuntu-calculator-app/tests/autopilot
31+
32+* run all tests.
33+ $ autopilot3 run -v ubuntu_calculator_app
34+
35+ to list all tests:
36+ $ autopilot3 list ubuntu_calculator_app
37+
38+ To run only one test, pass the full testname (as shown in autopilot3 list)
39+
40+ Debugging tests using autopilot vis
41+ $ autopilot3 launch -i Qt qmlscene ../../ubuntu-calculator-app.qml
42+ $ autopilot3 vis
43+
44+
45+## Running tests on device or emulator:
46+
47+Note, using adt-run from autopkgtest will setup an isolated environment on the device to safely run tests. It's recommended you use this to run tests on your device.
48+
49+Using autopkgtest:
50+
51+If you have local modifications you want to run, make sure to pass the root folder containing the modifications to adt-run. So,
52+
53+* Branch the calculator app code,
54+ $ bzr branch lp:ubuntu-calculator-app
55+* Make your modifications
56+* Navigate to the directory where the ubuntu-calculator-app branch is and run:
57+ $ adt-run ubuntu-calculator-app --click=com.ubuntu.calculator --- ssh -s adb
58+
59+If you simply want to run the tests for the application as it is installed on the device, you can run
60+
61+$ adt-run --click=com.ubuntu.calculator --- ssh -s adb
62+
63+from anywhere. This will grab the version of the tests corresponding to the version of the click package installed on the device.
64+
65+For more help on autopkg, see https://people.debian.org/~mpitt/autopkgtest/README.running-tests.html
66
67=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/__init__.py'
68--- tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2014-09-05 20:56:31 +0000
69+++ tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2014-10-09 21:48:24 +0000
70@@ -20,17 +20,14 @@
71 import shutil
72 import logging
73
74-import fixtures
75 import ubuntu_calculator_app
76
77 from autopilot.testcase import AutopilotTestCase
78 from autopilot import logging as autopilot_logging
79
80+import fixtures
81 import ubuntuuitoolkit
82-from ubuntuuitoolkit import (
83- base,
84- fixture_setup as toolkit_fixtures
85-)
86+from ubuntuuitoolkit import base
87
88 logger = logging.getLogger(__name__)
89
90@@ -63,12 +60,12 @@
91 def setUp(self):
92 super(BaseTestCaseWithPatchedHome, self).setUp()
93 self.launcher, self.test_type = self.get_launcher_and_type()
94- self.home_dir = self._patch_home()
95+ self.patch_home()
96
97 # Unset the current locale to ensure locale-specific data
98 # (day and month names, first day of the week, …) doesn’t get
99 # in the way of test expectations.
100- self.useFixture(fixtures.EnvironmentVariable('LC_ALL', newvalue='C'))
101+ self.patch_environment('LC_ALL', 'C')
102
103 @autopilot_logging.log_action(logger.info)
104 def launch_test_local(self):
105@@ -109,60 +106,15 @@
106 '.Xauthority')),
107 os.path.join(directory, '.Xauthority'))
108
109- def _patch_home(self):
110+ def patch_home(self):
111 """ mock /home for testing purposes to preserve user data
112 """
113- # click requires apparmor profile, and writing to special dir
114- # but the desktop can write to a traditional /tmp directory
115- if self.test_type == 'click':
116- env_dir = os.path.join(os.environ.get('HOME'), 'autopilot',
117- 'fakeenv')
118-
119- if not os.path.exists(env_dir):
120- os.makedirs(env_dir)
121-
122- temp_dir_fixture = fixtures.TempDir(env_dir)
123- self.useFixture(temp_dir_fixture)
124-
125- # apparmor doesn't allow the app to create needed directories,
126- # so we create them now
127- temp_dir = temp_dir_fixture.path
128- temp_dir_cache = os.path.join(temp_dir, '.cache')
129- temp_dir_cache_font = os.path.join(temp_dir_cache, 'fontconfig')
130- temp_dir_cache_media = os.path.join(temp_dir_cache, 'media-art')
131- temp_dir_cache_write = os.path.join(temp_dir_cache,
132- 'tncache-write-text.null')
133- temp_dir_config = os.path.join(temp_dir, '.config')
134- temp_dir_toolkit = os.path.join(temp_dir_config,
135- 'ubuntu-ui-toolkit')
136- temp_dir_font = os.path.join(temp_dir_cache, '.fontconfig')
137- temp_dir_local = os.path.join(temp_dir, '.local', 'share')
138- temp_dir_confined = os.path.join(temp_dir, 'confined')
139-
140- if not os.path.exists(temp_dir_cache):
141- os.makedirs(temp_dir_cache)
142- if not os.path.exists(temp_dir_cache_font):
143- os.makedirs(temp_dir_cache_font)
144- if not os.path.exists(temp_dir_cache_media):
145- os.makedirs(temp_dir_cache_media)
146- if not os.path.exists(temp_dir_cache_write):
147- os.makedirs(temp_dir_cache_write)
148- if not os.path.exists(temp_dir_config):
149- os.makedirs(temp_dir_config)
150- if not os.path.exists(temp_dir_toolkit):
151- os.makedirs(temp_dir_toolkit)
152- if not os.path.exists(temp_dir_font):
153- os.makedirs(temp_dir_font)
154- if not os.path.exists(temp_dir_local):
155- os.makedirs(temp_dir_local)
156- if not os.path.exists(temp_dir_confined):
157- os.makedirs(temp_dir_confined)
158-
159- # before we set fixture, copy xauthority if needed
160- self._copy_xauthority_file(temp_dir)
161- self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
162- HOME=temp_dir))
163- else:
164+
165+ # if running on non-phablet device,
166+ # run in temp folder to avoid mucking up home
167+ # bug 1316746
168+ # bug 1376423
169+ if self.test_type is not 'click':
170 temp_dir_fixture = fixtures.TempDir()
171 self.useFixture(temp_dir_fixture)
172 temp_dir = temp_dir_fixture.path
173@@ -172,8 +124,25 @@
174 self.useFixture(fixtures.EnvironmentVariable('HOME',
175 newvalue=temp_dir))
176
177- logger.debug("Patched home to fake home directory %s" % temp_dir)
178- return temp_dir
179+ logger.debug("Patched home to fake home directory %s" % temp_dir)
180+
181+ def patch_environment(self, key, value):
182+ def patch_var(key, value):
183+ logging.info(
184+ "Setting environment variable '%s' to '%s'",
185+ key,
186+ value
187+ )
188+
189+ os.environ[key] = value
190+
191+ orginal = os.getenv(key)
192+ if orginal is None:
193+ orginal = ''
194+ patch_var(key, value)
195+ # on click, we should cleanup
196+ if self.test_type is 'click':
197+ self.addCleanup(patch_var, key, orginal)
198
199
200 class CalculatorAppTestCase(BaseTestCaseWithPatchedHome):

Subscribers

People subscribed via source and target branches