Merge lp:~om26er/camera-app/fix_autopilot_test_code into lp:camera-app

Proposed by Omer Akram
Status: Rejected
Rejected by: Florian Boucault
Proposed branch: lp:~om26er/camera-app/fix_autopilot_test_code
Merge into: lp:camera-app
Diff against target: 428 lines (+89/-65)
6 files modified
tests/autopilot/camera_app/emulators/main_window.py (+21/-8)
tests/autopilot/camera_app/tests/__init__.py (+7/-6)
tests/autopilot/camera_app/tests/test_capture.py (+21/-16)
tests/autopilot/camera_app/tests/test_flash.py (+9/-10)
tests/autopilot/camera_app/tests/test_focus.py (+24/-16)
tests/autopilot/camera_app/tests/test_zoom.py (+7/-9)
To merge this branch: bzr merge lp:~om26er/camera-app/fix_autopilot_test_code
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ugo Riboni (community) Approve
Review via email: mp+195618@code.launchpad.net

Commit message

fixes pyflakes and pep8 complaints in the autopilot code. Also improves the readability.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ugo Riboni (uriboni) wrote :

Looks ok and passes

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

232. By Omer Akram

fix conflicts, merge trunk

231. By Omer Akram

True in this case is actually a string not bool

230. By Omer Akram

bring docstring inside test cases instead of being outside

229. By Omer Akram

move the check to make sure app window have appeared on screen into a central place, instead of doing the same thing in each Class

228. By Omer Akram

fix pyflakes complaints

227. By Omer Akram

fix all pep8 complaints

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/camera_app/emulators/main_window.py'
2--- tests/autopilot/camera_app/emulators/main_window.py 2013-11-18 10:15:15 +0000
3+++ tests/autopilot/camera_app/emulators/main_window.py 2013-11-22 11:05:37 +0000
4@@ -4,7 +4,7 @@
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License version 3, as published
7 # by the Free Software Foundation.
8-import math
9+
10
11 class MainWindow(object):
12 """An emulator class that makes it easy to interact with the camera-app."""
13@@ -19,14 +19,19 @@
14 def get_focus_ring(self):
15 """Returns the focus ring of the camera"""
16 return self.app.wait_select_single("FocusRing")
17-
18+
19 def get_exposure_button(self):
20 """Returns the button that takes pictures"""
21 return self.app.wait_select_single("ShootButton")
22
23 def get_record_control(self):
24- """Returns the button that switches between photo and video recording"""
25- return self.app.wait_select_single("FadingButton", objectName="recordModeButton")
26+ """Returns the button that switches between photo and video
27+ recording.
28+
29+ """
30+ return self.app.wait_select_single(
31+ "FadingButton",
32+ objectName="recordModeButton")
33
34 def get_flash_button(self):
35 """Returns the flash control button of the camera"""
36@@ -46,15 +51,21 @@
37
38 def get_zoom_slider_button(self):
39 """Returns the zoom slider button"""
40- return self.app.wait_select_single("QQuickImage", objectName="sliderThumb")
41+ return self.app.wait_select_single(
42+ "QQuickImage",
43+ objectName="sliderThumb")
44
45 def get_zoom_plus(self):
46 """Returns the zoom plus button"""
47- return self.app.wait_select_single("AbstractButton", objectName="zoomPlus")
48+ return self.app.wait_select_single(
49+ "AbstractButton",
50+ objectName="zoomPlus")
51
52 def get_zoom_minus(self):
53 """Returns the zoom minus button"""
54- return self.app.wait_select_single("AbstractButton", objectName="zoomMinus")
55+ return self.app.wait_select_single(
56+ "AbstractButton",
57+ objectName="zoomMinus")
58
59 def get_viewfinder_geometry(self):
60 """Returns the viewfinder geometry tracker"""
61@@ -62,7 +73,9 @@
62
63 def get_swap_camera_button(self):
64 """Returns the button that switches between front and back cameras"""
65- return self.app.wait_select_single("CameraToolbarButton", objectName="swapButton")
66+ return self.app.wait_select_single(
67+ "CameraToolbarButton",
68+ objectName="swapButton")
69
70 def get_orientation(self):
71 orientation = self.app.wait_select_single("DeviceOrientation")
72
73=== modified file 'tests/autopilot/camera_app/tests/__init__.py'
74--- tests/autopilot/camera_app/tests/__init__.py 2013-09-26 20:26:08 +0000
75+++ tests/autopilot/camera_app/tests/__init__.py 2013-11-22 11:05:37 +0000
76@@ -7,7 +7,6 @@
77
78 """Camera-app autopilot tests."""
79
80-from os import remove
81 import os.path
82
83 from autopilot.input import Mouse, Touch, Pointer
84@@ -26,11 +25,9 @@
85
86 """
87 if model() == 'Desktop':
88- scenarios = [
89- ('with mouse', dict(input_device_class=Mouse))]
90+ scenarios = [('with mouse', dict(input_device_class=Mouse))]
91 else:
92- scenarios = [
93- ('with touch', dict(input_device_class=Touch))]
94+ scenarios = [('with touch', dict(input_device_class=Touch))]
95
96 local_location = "../../camera-app"
97 deb_location = '/usr/bin/camera-app'
98@@ -45,6 +42,9 @@
99 else:
100 self.launch_click_installed()
101
102+ self.assertThat(
103+ self.main_window.get_qml_view().visible, Eventually(Equals(True)))
104+
105 def launch_test_local(self):
106 self.app = self.launch_test_application(
107 self.local_location)
108@@ -57,7 +57,8 @@
109 self.app = self.launch_test_application(
110 "camera-app",
111 "--fullscreen",
112- "--desktop_file_hint=/usr/share/applications/camera-app.desktop",
113+ "--desktop_file_hint=/usr/share/applications/"
114+ "camera-app.desktop",
115 app_type='qt')
116
117 def launch_click_installed(self):
118
119=== modified file 'tests/autopilot/camera_app/tests/test_capture.py'
120--- tests/autopilot/camera_app/tests/test_capture.py 2013-11-18 13:34:43 +0000
121+++ tests/autopilot/camera_app/tests/test_capture.py 2013-11-22 11:05:37 +0000
122@@ -9,7 +9,7 @@
123
124 from autopilot.matchers import Eventually
125 from autopilot.platform import model
126-from testtools.matchers import Equals, NotEquals, GreaterThan
127+from testtools.matchers import Equals, NotEquals
128
129 from camera_app.tests import CameraAppTestCase
130
131@@ -22,25 +22,25 @@
132 class TestCapture(CameraAppTestCase):
133 """Tests the main camera features"""
134
135- """ This is needed to wait for the application to start.
136- In the testfarm, the application may take some time to show up."""
137 def setUp(self):
138 super(TestCapture, self).setUp()
139- self.assertThat(
140- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
141
142 def tearDown(self):
143 super(TestCapture, self).tearDown()
144
145- """Test taking a picture"""
146- @unittest.skipIf(model() == 'Galaxy Nexus', 'Unusable with Mir enabled on maguro')
147+ @unittest.skipIf(
148+ model() == 'Galaxy Nexus',
149+ 'Unusable with Mir enabled on maguro')
150 def test_take_picture(self):
151- toolbar = self.main_window.get_toolbar()
152+ """Test taking a picture."""
153 exposure_button = self.main_window.get_exposure_button()
154 pictures_dir = path.expanduser("~/Pictures")
155
156 # Remove all pictures from ~/Pictures that match our pattern
157- files = [f for f in os.listdir(pictures_dir) if f[0:5] == "image" and path.isfile(path.join(pictures_dir, f))]
158+ files = [
159+ f for f in os.listdir(pictures_dir) if f[0:5] == "image"
160+ and path.isfile(path.join(pictures_dir, f))
161+ ]
162 for f in files:
163 os.remove(path.join(pictures_dir, f))
164
165@@ -56,7 +56,10 @@
166 # is actually there
167 one_picture_on_disk = False
168 for i in range(0, 10):
169- files = [f for f in os.listdir(pictures_dir) if f[0:5] == "image" and path.isfile(path.join(pictures_dir, f))]
170+ files = [
171+ f for f in os.listdir(pictures_dir) if f[0:5] == "image"
172+ and path.isfile(path.join(pictures_dir, f))
173+ ]
174 if len(files) == 1:
175 one_picture_on_disk = True
176 break
177@@ -66,13 +69,13 @@
178 # check that the camera is able to capture another photo
179 self.assertThat(exposure_button.enabled, Eventually(Equals(True)))
180
181- """Tests clicking on the record control and checks if the flash changes
182- to torch off mode and the recording time appears"""
183 @unittest.skip('Video recording not working for V1.0')
184 def test_record_video(self):
185+ """Tests clicking on the record control and checks if the flash changes
186+ to torch off mode and the recording time appears.
187+
188+ """
189 # Get all the elements
190- camera_window = self.main_window.get_camera()
191- toolbar = self.main_window.get_toolbar()
192 record_control = self.main_window.get_record_control()
193 flash_button = self.main_window.get_flash_button()
194 stop_watch = self.main_window.get_stop_watch()
195@@ -138,10 +141,12 @@
196 self.assertThat(
197 flash_button.torchMode, Eventually(Equals(torchmode_old_state)))
198
199- """Test that the shoot button gets disabled for a while then re-enabled
200- after shooting"""
201 @unittest.skip("Disabled this test due race condition see bug 1227373")
202 def test_shoot_button_disable(self):
203+ """Test that the shoot button gets disabled for a while then re-enabled
204+ after shooting.
205+
206+ """
207 exposure_button = self.main_window.get_exposure_button()
208
209 # The focus ring should be invisible in the beginning
210
211=== modified file 'tests/autopilot/camera_app/tests/test_flash.py'
212--- tests/autopilot/camera_app/tests/test_flash.py 2013-11-18 13:34:43 +0000
213+++ tests/autopilot/camera_app/tests/test_flash.py 2013-11-22 11:05:37 +0000
214@@ -12,25 +12,20 @@
215
216 from camera_app.tests import CameraAppTestCase
217
218-import time
219 import unittest
220
221
222 class TestCameraFlash(CameraAppTestCase):
223 """Tests the flash"""
224
225- """ This is needed to wait for the application to start.
226- In the testfarm, the application may take some time to show up."""
227 def setUp(self):
228 super(TestCameraFlash, self).setUp()
229- self.assertThat(
230- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
231
232 def tearDown(self):
233 super(TestCameraFlash, self).tearDown()
234
235- """Test that flash modes cycle properly"""
236 def test_cycle_flash(self):
237+ """Test that flash modes cycle properly."""
238 flash_button = self.main_window.get_flash_button()
239
240 #ensure initial state
241@@ -51,9 +46,9 @@
242 self.assertThat(flash_button.flashState, Eventually(Equals("off")))
243 self.assertThat(flash_button.torchMode, Equals(False))
244
245- """Test that torch modes cycles properly"""
246 @unittest.skip('Video recording not working for V1.0')
247 def test_cycle_torch(self):
248+ """Test that torch modes cycles properly."""
249 flash_button = self.main_window.get_flash_button()
250 record_button = self.main_window.get_record_control()
251 self.pointing_device.click_object(record_button)
252@@ -72,10 +67,12 @@
253 self.assertThat(flash_button.flashState, Eventually(Equals("off")))
254 self.assertThat(flash_button.torchMode, Equals(True))
255
256- """When switching between video and picture the previous flash state
257- should be preserved"""
258 @unittest.skip('Video recording not working for V1.0')
259 def test_remember_state(self):
260+ """When switching between video and picture the previous flash state
261+ should be preserved.
262+
263+ """
264 flash_button = self.main_window.get_flash_button()
265 record_button = self.main_window.get_record_control()
266 initial_flash_state = flash_button.flashState
267@@ -85,7 +82,9 @@
268 self.pointing_device.move_to_object(flash_button)
269 self.pointing_device.click()
270 self.assertThat(
271- flash_button.flashState, Eventually(NotEquals(initial_flash_state)))
272+ flash_button.flashState,
273+ Eventually(NotEquals(initial_flash_state))
274+ )
275 second_flash_state = flash_button.flashState
276 self.pointing_device.click()
277 self.assertThat(
278
279=== modified file 'tests/autopilot/camera_app/tests/test_focus.py'
280--- tests/autopilot/camera_app/tests/test_focus.py 2013-11-18 14:18:52 +0000
281+++ tests/autopilot/camera_app/tests/test_focus.py 2013-11-22 11:05:37 +0000
282@@ -9,31 +9,28 @@
283
284 from autopilot.matchers import Eventually
285 from autopilot.platform import model
286-from testtools.matchers import Equals, NotEquals, GreaterThan
287+from testtools.matchers import Equals, GreaterThan
288 from camera_app.tests import CameraAppTestCase
289
290 import unittest
291-import time
292
293
294 class TestFocus(CameraAppTestCase):
295 """Tests the focus"""
296
297- """ This is needed to wait for the application to start.
298- In the testfarm, the application may take some time to show up."""
299 def setUp(self):
300 super(TestFocus, self).setUp()
301- self.assertThat(
302- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
303
304 def tearDown(self):
305 super(TestFocus, self).tearDown()
306
307- """Test focusing in an area where we know the picture is"""
308- @unittest.skipIf(model() == 'Galaxy Nexus', 'Unusable with Mir enabled on maguro')
309+ @unittest.skipIf(
310+ model() == 'Galaxy Nexus',
311+ 'Unusable with Mir enabled on maguro'
312+ )
313 def test_focus_valid_and_disappear(self):
314+ """Test focusing in an area where we know the picture is."""
315 focus_ring = self.main_window.get_focus_ring()
316- toolbar = self.main_window.get_toolbar()
317 feed = self.main_window.get_viewfinder_geometry()
318 switch_cameras = self.main_window.get_swap_camera_button()
319 exposure_button = self.main_window.get_exposure_button()
320@@ -60,7 +57,10 @@
321 self.assertThat(exposure_button.enabled, Eventually(Equals(True)))
322
323 # Click in the center of the viewfinder area
324- click_coords =[feed.globalRect[2] // 2 + feed.globalRect[0], feed.globalRect[3] // 2 + feed.globalRect[1]]
325+ click_coords = [
326+ feed.globalRect[2] // 2 + feed.globalRect[0],
327+ feed.globalRect[3] // 2 + feed.globalRect[1]
328+ ]
329 self.pointing_device.move(click_coords[0], click_coords[1])
330 self.pointing_device.click()
331
332@@ -73,10 +73,15 @@
333 # After some seconds the focus ring should fade out
334 self.assertThat(focus_ring.opacity, Eventually(Equals(0.0)))
335
336- @unittest.skipIf(model() == 'Galaxy Nexus', 'Unusable with Mir enabled on maguro')
337+ @unittest.skipIf(
338+ model() == 'Galaxy Nexus',
339+ 'Unusable with Mir enabled on maguro'
340+ )
341 def test_focus_invalid(self):
342 """Tests clicking outside of the viewfinder image area, where it should
343- not focus."""
344+ not focus.
345+
346+ """
347 toolbar = self.main_window.get_toolbar()
348 zoom = self.main_window.get_zoom_control()
349 feed = self.main_window.get_viewfinder_geometry()
350@@ -98,8 +103,8 @@
351
352 # Check if there's a gap between the viewfinder feed and the zoom
353 # control. If there is, test that focusing there won't show the focus
354- #ring.
355- if zoom.y > feed.height: # Feed is aligned to the top of the window
356+ # ring.
357+ if zoom.y > feed.height: # Feed is aligned to the top of the window
358 x, y, h, w = zoom.globalRect
359 click_coords = [x + (h / 2), y - 2]
360 self.pointing_device.move(click_coords[0], click_coords[1])
361@@ -119,9 +124,12 @@
362 self.pointing_device.click()
363 self.assertThat(focus_ring.opacity, Eventually(Equals(0.0)))
364
365- """Tests dragging the focus ring"""
366- @unittest.skipIf(model() == 'Galaxy Nexus', 'Unusable with Mir enabled on maguro')
367+ @unittest.skipIf(
368+ model() == 'Galaxy Nexus',
369+ 'Unusable with Mir enabled on maguro'
370+ )
371 def test_move_focus_ring(self):
372+ """Tests dragging the focus ring."""
373 focus_ring = self.main_window.get_focus_ring()
374 feed = self.main_window.get_viewfinder_geometry()
375 switch_cameras = self.main_window.get_swap_camera_button()
376
377=== modified file 'tests/autopilot/camera_app/tests/test_zoom.py'
378--- tests/autopilot/camera_app/tests/test_zoom.py 2013-11-18 13:34:43 +0000
379+++ tests/autopilot/camera_app/tests/test_zoom.py 2013-11-22 11:05:37 +0000
380@@ -12,25 +12,20 @@
381
382 from camera_app.tests import CameraAppTestCase
383
384-import time
385 import unittest
386
387
388 class TestCameraZoom(CameraAppTestCase):
389- """Tests the main camera features"""
390+ """ Tests the main camera features. """
391
392- """ This is needed to wait for the application to start.
393- In the testfarm, the application may take some time to show up."""
394 def setUp(self):
395 super(TestCameraZoom, self).setUp()
396- self.assertThat(
397- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
398
399 def tearDown(self):
400 super(TestCameraZoom, self).tearDown()
401
402- """Tests the zoom slider"""
403 def test_slider(self):
404+ """Tests the zoom slider."""
405 zoom_control = self.main_window.get_zoom_control()
406 zoom_button = self.main_window.get_zoom_slider_button()
407
408@@ -106,7 +101,9 @@
409 self.pointing_device.move_to_object(minus)
410 self.pointing_device.click()
411 self.assertThat(
412- zoom_control.value, Eventually(NotEquals(zoom_control.maximumValue)))
413+ zoom_control.value,
414+ Eventually(NotEquals(zoom_control.maximumValue))
415+ )
416
417 value_before_plus = zoom_control.value
418
419@@ -115,7 +112,8 @@
420 self.assertThat(
421 zoom_control.value, Eventually(GreaterThan(value_before_plus)))
422
423- # Test that keeping the minus button pressed eventually reaches min zoom
424+ # Test that keeping the minus button pressed eventually reaches
425+ # min zoom.
426 self.pointing_device.move_to_object(minus)
427 self.pointing_device.press()
428 self.assertThat(zoom_control.value, Eventually(Equals(1.0)))

Subscribers

People subscribed via source and target branches