Merge lp:~thomir-deactivatedaccount/camera-app/autopilot-tests-port into lp:camera-app

Proposed by Thomi Richards
Status: Work in progress
Proposed branch: lp:~thomir-deactivatedaccount/camera-app/autopilot-tests-port
Merge into: lp:camera-app
Diff against target: 374 lines (+69/-115)
5 files modified
tests/autopilot/camera_app/tests/__init__.py (+9/-7)
tests/autopilot/camera_app/tests/test_capture.py (+33/-34)
tests/autopilot/camera_app/tests/test_flash.py (+20/-46)
tests/autopilot/camera_app/tests/test_focus.py (+4/-15)
tests/autopilot/camera_app/tests/test_zoom.py (+3/-13)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/camera-app/autopilot-tests-port
Reviewer Review Type Date Requested Status
Leo Arias (community) Disapprove
Ubuntu Phablet Team Pending
Review via email: mp+161045@code.launchpad.net

Description of the change

This brnch contains the minimum set of changes required to port the camera-app tests to autopilot 1.3.

DO NOT MERGE THIS BRANCH!

...until you're ready to start using the new autopilot.

To post a comment you must log in.
127. By Thomi Richards

various test cleanups.

128. By Thomi Richards

Example of how to use scenarios.

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

This branch is no longer need.

review: Disapprove

Unmerged revisions

128. By Thomi Richards

Example of how to use scenarios.

127. By Thomi Richards

various test cleanups.

126. By Thomi Richards

port tests to new API.

125. By Thomi Richards

removed another unused import.

124. By Thomi Richards

removed unused imports.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/camera_app/tests/__init__.py'
2--- tests/autopilot/camera_app/tests/__init__.py 2012-12-17 14:07:00 +0000
3+++ tests/autopilot/camera_app/tests/__init__.py 2013-04-30 00:10:42 +0000
4@@ -7,25 +7,31 @@
5
6 """Camera-app autopilot tests."""
7
8-from os import remove
9 import os.path
10
11-from autopilot.introspection.qt import QtIntrospectionTestMixin
12 from autopilot.testcase import AutopilotTestCase
13+from testtools.matchers import Equals
14
15 from camera_app.emulators.main_window import MainWindow
16
17-class CameraAppTestCase(AutopilotTestCase, QtIntrospectionTestMixin):
18+class CameraAppTestCase(AutopilotTestCase):
19
20 """A common test case class that provides several useful methods for camera-app tests."""
21+ scenarios = [
22+ ('with mouse', dict(input_device_class=Mouse)),
23+ ('with touch', dict(input_device_class=Touch)),
24+ ]
25
26 def setUp(self):
27+ self.input_device = self.input_device_class.create()
28 super(CameraAppTestCase, self).setUp()
29 # Lets assume we are installed system wide if this file is somewhere in /usr
30 if os.path.realpath(__file__).startswith("/usr/"):
31 self.launch_test_installed()
32 else:
33 self.launch_test_local()
34+ # wait for the main window to be visible:
35+ self.assertThat(self.main_window.get_qml_view().visible, Eventually(Equals(True)))
36
37 def launch_test_local(self):
38 self.app = self.launch_test_application(
39@@ -40,10 +46,6 @@
40 self.app = self.launch_test_application(
41 "camera-app")
42
43- @staticmethod
44- def running_on_device():
45- return os.path.isfile('/system/usr/idc/autopilot-finger.idc')
46-
47 @property
48 def main_window(self):
49 return MainWindow(self.app)
50
51=== modified file 'tests/autopilot/camera_app/tests/test_capture.py'
52--- tests/autopilot/camera_app/tests/test_capture.py 2013-04-17 20:40:53 +0000
53+++ tests/autopilot/camera_app/tests/test_capture.py 2013-04-30 00:10:42 +0000
54@@ -9,63 +9,62 @@
55
56 from __future__ import absolute_import
57
58-from testtools.matchers import Equals, NotEquals, GreaterThan
59 from autopilot.matchers import Eventually
60+from autopilot.platform import model
61+from testtools.matchers import Equals, NotEquals, HasLength
62
63 from camera_app.tests import CameraAppTestCase
64
65-import unittest
66-import time
67+import testtools
68+import glob
69 import os
70 from os import path
71
72 class TestCapture(CameraAppTestCase):
73 """Tests the main camera features"""
74
75- """ This is needed to wait for the application to start.
76- In the testfarm, the application may take some time to show up."""
77- def setUp(self):
78- super(TestCapture, self).setUp()
79- self.assertThat(self.main_window.get_qml_view().visible, Eventually(Equals(True)))
80-
81- def tearDown(self):
82- super(TestCapture, self).tearDown()
83-
84- """Test taking a picture"""
85- def test_take_picture(self):
86- toolbar = self.main_window.get_toolbar()
87- exposure_button = self.main_window.get_exposure_button()
88- pictures_dir = path.expanduser("~/Pictures")
89+ def cleanup_picture_files(self):
90+ """Cleanup picture files from ~/Pictures that matches our file naming pattern."""
91+ pictures_dir = self.get_picture_dir()
92
93 # Remove all pictures from ~/Pictures that match our pattern
94 files = [ f for f in os.listdir(pictures_dir) if f[0:5] == "image" and path.isfile(path.join(pictures_dir,f))]
95 for f in files:
96 os.remove(path.join(pictures_dir, f))
97
98+ def get_picture_dir(self):
99+ """Return the picture folder path."""
100+ return path.expanduser("~/Pictures")
101+
102+ def get_pictures_on_disk(self):
103+ """Return a list of pictures on the disk."""
104+ return glob.glob(path.join(self.get_picture_dir(), "image*"))
105+
106+ def test_take_picture(self):
107+ """Must be able to take a picture."""
108+ # cleanup before the test starts, just to be safe:
109+ self.cleanup_picture_files()
110+
111+ exposure_button = self.main_window.get_exposure_button()
112+
113 # Wait for the camera to have finished focusing (the exposure button gets enabled when ready)
114 self.assertThat(exposure_button.enabled, Eventually(Equals(True)))
115
116 # Now take the picture! (Give it a little time to animate)
117 self.mouse.move_to_object(exposure_button)
118 self.mouse.click()
119+ self.addCleanup(self.cleanup_picture_files)
120
121 # Check that only one picture with the right name pattern is actually there
122- one_picture_on_disk = False
123- for i in range(0, 10):
124- files = [ f for f in os.listdir(pictures_dir) if f[0:5] == "image" and path.isfile(path.join(pictures_dir,f))]
125- if len(files) == 1:
126- one_picture_on_disk = True
127- break
128- time.sleep(1)
129- self.assertEquals(one_picture_on_disk, True)
130+ self.assertThat(self.get_pictures_on_disk, Eventually(HasLength(1)))
131
132- """Tests clicking on the record control and checks if the flash changes
133- to torch off mode and the recording time appears"""
134- @unittest.skipIf(CameraAppTestCase.running_on_device(), 'recording not available on device yet')
135+ @testtools.skipUnless(model == 'Desktop', 'recording not available on device yet')
136 def test_record_video(self):
137+ """Clicking on the record control
138+
139+ Tests clicking on the record control and checks if the flash changes
140+ to torch off mode and the recording time appears"""
141 # Get all the elements
142- camera_window = self.main_window.get_camera()
143- toolbar = self.main_window.get_toolbar()
144 record_control = self.main_window.get_record_control()
145 flash_button = self.main_window.get_flash_button()
146 stop_watch = self.main_window.get_stop_watch()
147@@ -86,7 +85,7 @@
148 # Before recording the stop watch should read zero recording time
149 # and not be visible anyway.
150 self.assertThat(stop_watch.opacity, Equals(0.0))
151- self.assertEquals(stop_watch.elapsed, "00:00")
152+ self.assertThat(stop_watch.elapsed, Equals("00:00"))
153
154 # Click the exposure button to start recording
155 self.mouse.move_to_object(exposure_button)
156@@ -111,7 +110,7 @@
157 self.assertThat(flash_button.flashState, Eventually(Equals("off")))
158 self.assertThat(flash_button.torchMode, Eventually(Equals(True)))
159 self.assertThat(stop_watch.opacity, Eventually(Equals(1.0)))
160- self.assertEquals(stop_watch.elapsed, "00:00")
161+ self.assertThat(stop_watch.elapsed, Equals("00:00"))
162
163 # Record video for 2 seconds and check if the stop watch actually works
164 self.assertThat(stop_watch.elapsed, Eventually(NotEquals("00:00")))
165@@ -125,12 +124,12 @@
166 self.assertThat(flash_button.flashState, Eventually(Equals(flashlight_old_state)))
167 self.assertThat(flash_button.torchMode, Eventually(Equals(torchmode_old_state)))
168
169- """Test that the shoot button gets disabled for a while then re-enabled after shooting"""
170 def test_shoot_button_disable(self):
171+ """The shoot button must be disabled and then re-enabled after shooting."""
172 exposure_button = self.main_window.get_exposure_button()
173
174 # The focus ring should be invisible in the beginning
175- self.assertEquals(exposure_button.enabled, True)
176+ self.assertThat(exposure_button.enabled, Equals(True))
177
178 # Now take the picture! (Give it a little time to animate)
179 self.mouse.move_to_object(exposure_button)
180
181=== modified file 'tests/autopilot/camera_app/tests/test_flash.py'
182--- tests/autopilot/camera_app/tests/test_flash.py 2013-04-17 20:40:53 +0000
183+++ tests/autopilot/camera_app/tests/test_flash.py 2013-04-30 00:10:42 +0000
184@@ -9,71 +9,45 @@
185
186 from __future__ import absolute_import
187
188-from testtools.matchers import Equals, NotEquals
189+from testtools.matchers import Equals
190 from autopilot.matchers import Eventually
191
192 from camera_app.tests import CameraAppTestCase
193
194-import time
195
196 class TestCameraFlash(CameraAppTestCase):
197 """Tests the flash"""
198
199- """ This is needed to wait for the application to start.
200- In the testfarm, the application may take some time to show up."""
201- def setUp(self):
202- super(TestCameraFlash, self).setUp()
203- self.assertThat(self.main_window.get_qml_view().visible, Eventually(Equals(True)))
204-
205- def tearDown(self):
206- super(TestCameraFlash, self).tearDown()
207-
208- """Test that flash modes cycle properly"""
209 def test_cycle_flash(self):
210+ """Test that flash modes cycle properly"""
211 flash_button = self.main_window.get_flash_button()
212+ self.mouse.move_to_object(flash_button)
213
214 #ensure initial state
215- self.assertThat(flash_button.flashState, Equals("off"))
216- self.assertThat(flash_button.torchMode, Equals(False))
217-
218- self.mouse.move_to_object(flash_button)
219-
220- self.mouse.click()
221- self.assertThat(flash_button.flashState, Eventually(Equals("on")))
222- self.assertThat(flash_button.torchMode, Equals(False))
223-
224- self.mouse.click()
225- self.assertThat(flash_button.flashState, Eventually(Equals("auto")))
226- self.assertThat(flash_button.torchMode, Equals(False))
227-
228- self.mouse.click()
229- self.assertThat(flash_button.flashState, Eventually(Equals("off")))
230- self.assertThat(flash_button.torchMode, Equals(False))
231-
232- """Test that torch modes cycles properly"""
233+ for desired_mode in ("off", "on", "auto", "off"):
234+ self.assertThat(flash_button.flashState, Eventually(Equals(desired_mode)))
235+ self.assertThat(flash_button.torchMode, Equals(False))
236+ self.mouse.click()
237+
238 def test_cycle_torch(self):
239+ """Test that torch modes cycles properly"""
240 flash_button = self.main_window.get_flash_button()
241 record_button = self.main_window.get_record_control()
242 self.mouse.move_to_object(record_button)
243 self.mouse.click()
244+ self.mouse.move_to_object(flash_button)
245
246+ for desired_mode in ("off", "on", "off"):
247 #ensure initial state
248- self.assertThat(flash_button.flashState, Equals("off"))
249- self.assertThat(flash_button.torchMode, Equals(True))
250-
251- self.mouse.move_to_object(flash_button)
252-
253- self.mouse.click()
254- self.assertThat(flash_button.flashState, Eventually(Equals("on")))
255- self.assertThat(flash_button.torchMode, Equals(True))
256-
257- self.mouse.click()
258- self.assertThat(flash_button.flashState, Eventually(Equals("off")))
259- self.assertThat(flash_button.torchMode, Equals(True))
260-
261- """When switching between video and picture the previous flash state
262- should be preserved"""
263- def test_remember_state(self):
264+ self.assertThat(flash_button.flashState, Eventually(Equals(desired_mode)))
265+ self.assertThat(flash_button.torchMode, Eventually(Equals(True)))
266+ self.mouse.click()
267+
268+ def test_flash_state_is_rememberred(self):
269+ """When switching between video and picture mode the previous flash state
270+ must be preserved
271+
272+ """
273 flash_button = self.main_window.get_flash_button()
274 record_button = self.main_window.get_record_control()
275
276
277=== modified file 'tests/autopilot/camera_app/tests/test_focus.py'
278--- tests/autopilot/camera_app/tests/test_focus.py 2013-04-17 20:40:53 +0000
279+++ tests/autopilot/camera_app/tests/test_focus.py 2013-04-30 00:10:42 +0000
280@@ -9,28 +9,17 @@
281
282 from __future__ import absolute_import
283
284-from testtools.matchers import Equals, NotEquals, GreaterThan
285 from autopilot.matchers import Eventually
286+from testtools.matchers import Equals, GreaterThan
287
288 from camera_app.tests import CameraAppTestCase
289
290-import unittest
291-import time
292
293 class TestFocus(CameraAppTestCase):
294 """Tests the focus"""
295
296- """ This is needed to wait for the application to start.
297- In the testfarm, the application may take some time to show up."""
298- def setUp(self):
299- super(TestFocus, self).setUp()
300- self.assertThat(self.main_window.get_qml_view().visible, Eventually(Equals(True)))
301-
302- def tearDown(self):
303- super(TestFocus, self).tearDown()
304-
305- """Test focusing in an area where we know the picture is"""
306 def test_focus_valid_and_disappear(self):
307+ """Test focusing in an area where we know the picture is"""
308 camera_window = self.main_window.get_camera()
309 focus_ring = self.main_window.get_focus_ring()
310 toolbar = self.main_window.get_toolbar()
311@@ -72,8 +61,8 @@
312 # After some seconds the focus ring should fade out
313 self.assertThat(focus_ring.opacity, Eventually(Equals(0.0)))
314
315- """Tests clicking outside of the viewfinder image area, where it should not focus"""
316 def test_focus_invalid(self):
317+ """Tests clicking outside of the viewfinder image area, where it should not focus"""
318 camera_window = self.main_window.get_camera()
319 toolbar = self.main_window.get_toolbar()
320 zoom = self.main_window.get_zoom_control()
321@@ -111,8 +100,8 @@
322 self.mouse.click()
323 self.assertEquals(focus_ring.opacity, 0.0)
324
325- """Tests dragging the focus ring"""
326 def test_move_focus_ring(self):
327+ """Tests dragging the focus ring"""
328 camera_window = self.main_window.get_camera()
329 focus_ring = self.main_window.get_focus_ring()
330 feed = self.main_window.get_viewfinder_geometry()
331
332=== modified file 'tests/autopilot/camera_app/tests/test_zoom.py'
333--- tests/autopilot/camera_app/tests/test_zoom.py 2013-04-17 20:40:53 +0000
334+++ tests/autopilot/camera_app/tests/test_zoom.py 2013-04-30 00:10:42 +0000
335@@ -9,27 +9,17 @@
336
337 from __future__ import absolute_import
338
339+from autopilot.matchers import Eventually
340 from testtools.matchers import Equals, NotEquals, GreaterThan, LessThan
341-from autopilot.matchers import Eventually
342
343 from camera_app.tests import CameraAppTestCase
344
345-import time
346
347 class TestCameraZoom(CameraAppTestCase):
348 """Tests the main camera features"""
349
350- """ This is needed to wait for the application to start.
351- In the testfarm, the application may take some time to show up."""
352- def setUp(self):
353- super(TestCameraZoom, self).setUp()
354- self.assertThat(self.main_window.get_qml_view().visible, Eventually(Equals(True)))
355-
356- def tearDown(self):
357- super(TestCameraZoom, self).tearDown()
358-
359- """Tests the zoom slider"""
360 def test_slider(self):
361+ """Tests the zoom slider"""
362 zoom_control = self.main_window.get_zoom_control()
363
364 zoom_button = self.main_window.get_zoom_slider_button()
365@@ -54,8 +44,8 @@
366
367 self.assertThat(zoom_control.value, Eventually(Equals(1.0)))
368
369- """Tests the plus and minus buttons"""
370 def test_plus_minus(self):
371+ """Tests the plus and minus buttons"""
372 zoom_control = self.main_window.get_zoom_control()
373 plus = self.main_window.get_zoom_plus()
374 minus = self.main_window.get_zoom_minus()

Subscribers

People subscribed via source and target branches