on xenial help sign in
Unity8 tests now make use of the helper functions (added in the pre-req branch) so that the helper functions are tested as part of daily business.

Approved by PS Jenkins bot, Michał Sawicz.

commit03c4f5f88c5f433b467d1655040cbdfd26341ee2 authorChristopher Lee <chris.lee@canonical.com> dateWed 20 Nov 2013, 04:08 (13 years ago) parenta60fcd269c36ae
4 files changed+109−99
tests/autopilot/unity8/process_helpers.py+65−38 tests/autopilot/unity8/shell/tests/__init__.py+8−21 tests/autopilot/unity8/shell/tests/test_hud.py+11−10 tests/autopilot/unity8/shell/tests/test_notifications.py+25−30
tests/autopilot/unity8/process_helpers.py+65−38
@@ -21,18 +21,25 @@ from autopilot.introspection import (
2121 get_proxy_object_for_existing_process,
2222 ProcessSearchError,
2323)
24+import logging
2425import subprocess
2526from unity8.shell.emulators import UnityEmulatorBase
2627from unity8.shell.emulators.main_window import MainWindow
2728
29+logger = logging.getLogger(__name__)
30+
2831
2932class CannotAccessUnity(Exception):
3033 pass
3134
3235
33−def unlock_unity():
36+def unlock_unity(unity_proxy_obj=None):
3437 """Helper function that attempts to unlock the unity greeter.
3538
39+ If unity_proxy_object is None create a proxy object by querying for the
40+ running unity process.
41+ Otherwise re-use the passed proxy object.
42+
3643 :raises RuntimeError: if the greeter attempts and fails to be unlocked.
3744
3845 :raises RuntimeWarning: when the greeter cannot be found because it is
@@ -43,30 +50,42 @@ def unlock_unity():
4350 upstart job cannot be found at all.
4451
4552 """
46− pid = _get_unity_pid()
47− try:
48− unity = get_proxy_object_for_existing_process(
49− pid=pid,
50− emulator_base=UnityEmulatorBase,
51− )
52− main_window = MainWindow(unity)
53−
54− greeter = main_window.get_greeter()
55− if greeter is None:
56− raise RuntimeWarning("Greeter appears to be already unlocked.")
57− greeter.swipe()
58− except ProcessSearchError as e:
59− raise CannotAccessUnity(
60− "Cannot introspect unity, make sure that it has been started "
61− "with testability. Perhaps use the function "
62− "'restart_unity_with_testability' this module provides."
63− "(%s)"
64− % str(e)
65− )
53+ if unity_proxy_obj is None:
54+ try:
55+ pid = _get_unity_pid()
56+ unity = _get_unity_proxy_object(pid)
57+ main_window = MainWindow(unity)
58+ except ProcessSearchError as e:
59+ raise CannotAccessUnity(
60+ "Cannot introspect unity, make sure that it has been started "
61+ "with testability. Perhaps use the function "
62+ "'restart_unity_with_testability' this module provides."
63+ "(%s)"
64+ % str(e)
65+ )
66+ else:
67+ main_window = MainWindow(unity_proxy_obj)
68+
69+ greeter = main_window.get_greeter()
70+ if greeter is None:
71+ raise RuntimeWarning("Greeter appears to be already unlocked.")
72+ greeter.swipe()
73+
74+
75+def restart_unity_with_testability(*args):
76+ """Restarts (or starts) unity with testability enabled.
77+
78+ Passes *args arguments to the launched process.
79+
80+ """
81+ args += ("QT_LOAD_TESTABILITY=1",)
82+ return restart_unity(*args)
83+
6684
85+def restart_unity(*args):
86+ """Restarts (or starts) unity8 using the provided arguments.
6787
68−def restart_unity_with_testability():
69− """Restarts (or just starts) unity8 with the testability driver loaded
88+ Passes *args arguments to the launched process.
7089
7190 :raises subprocess.CalledProcessError: if unable to stop or start the
7291 unity8 upstart job.
@@ -75,27 +94,28 @@ def restart_unity_with_testability():
7594 status = _get_unity_status()
7695 if "start/" in status:
7796 try:
78− print("Stopping unity.")
79− subprocess.check_call([
80− 'initctl',
81− 'stop',
82− 'unity8',
83− ])
97+ output = subprocess.check_output(['initctl', 'stop', 'unity8'])
98+ logger.info(output)
8499 except subprocess.CalledProcessError as e:
85− e.args += ("Failed to stop running instance of unity8", )
100+ e.args += (
101+ "Failed to stop running instance of unity8: %s" % e.output,
102+ )
86103 raise
87104
88105 try:
89− print("Starting unity with testability.")
90− subprocess.check_call([
91− 'initctl',
92− 'start',
93− 'unity8',
94− 'QT_LOAD_TESTABILITY=1',
95− ])
106+ command = ['initctl', 'start', 'unity8'] + list(args)
107+ output = subprocess.check_output(
108+ command,
109+ stderr=subprocess.STDOUT,
110+ universal_newlines=True,
111+ )
112+ logger.info(output)
113+ pid = _get_unity_pid()
96114 except subprocess.CalledProcessError as e:
97− e.args += ("Failed to start unity8 with testability ", )
115+ e.args += ("Failed to start unity8: %s" % e.output,)
98116 raise
117+ else:
118+ return _get_unity_proxy_object(pid)
99119
100120
101121def _get_unity_status():
@@ -114,3 +134,10 @@ def _get_unity_pid():
114134 if not "start/" in status:
115135 raise CannotAccessUnity("Unity is not in the running state.")
116136 return int(status.split()[-1])
137+
138+
139+def _get_unity_proxy_object(pid):
140+ return get_proxy_object_for_existing_process(
141+ pid=pid,
142+ emulator_base=UnityEmulatorBase,
143+ )
tests/autopilot/unity8/shell/tests/__init__.py+8−21
@@ -28,7 +28,6 @@ from autopilot.platform import model
2828from autopilot.testcase import AutopilotTestCase
2929from autopilot.matchers import Eventually
3030from autopilot.input import Touch
31−from autopilot.introspection import get_proxy_object_for_existing_process
3231from autopilot.display import Display
3332import logging
3433import os.path
@@ -43,7 +42,7 @@ from unity8 import (
4342 get_default_extra_mock_libraries,
4443 get_data_dirs
4544)
46−from unity8.shell.emulators import UnityEmulatorBase
45+from unity8.process_helpers import restart_unity_with_testability
4746from unity8.shell.emulators.dash import Dash
4847from unity8.shell.emulators.main_window import MainWindow
4948
@@ -105,7 +104,7 @@ class UnityTestCase(AutopilotTestCase):
105104 ),
106105 "upstart")
107106 )
108− )
107+ )
109108 sys.exit(1)
110109
111110 if "start/" in output:
@@ -303,32 +302,20 @@ class UnityTestCase(AutopilotTestCase):
303302
304303 binary_arg = "BINARY=%s" % binary_path
305304 extra_args = "ARGS=%s" % " ".join(args)
306−
307− output = subprocess.check_output(
308− [
309− "/sbin/initctl",
310− "start",
311− "unity8",
312− binary_arg,
313− extra_args,
314− ] + ["%s=%s" % (k, v) for k, v in self._environment.iteritems()],
315− stderr=subprocess.STDOUT,
316− )
305+ env_args = ["%s=%s" % (k, v) for k, v in self._environment.iteritems()]
306+ all_args = [binary_arg, extra_args] + env_args
317307
318308 self.addCleanup(self._cleanup_launching_upstart_unity)
319309
320− pid = int(output.split()[-1])
321−
322− return get_proxy_object_for_existing_process(
323− pid=pid,
324− emulator_base=UnityEmulatorBase,
325− )
310+ return restart_unity_with_testability(*all_args)
326311
327312 def _cleanup_launching_upstart_unity(self):
328313 logger.info("Stopping unity")
329314 try:
330315 subprocess.check_output(
331− ["/sbin/initctl", "stop", "unity8"], stderr=subprocess.STDOUT)
316+ ["/sbin/initctl", "stop", "unity8"],
317+ stderr=subprocess.STDOUT
318+ )
332319 except subprocess.CalledProcessError:
333320 logger.warning("Appears unity was already stopped!")
334321
tests/autopilot/unity8/shell/tests/test_hud.py+11−10
@@ -19,6 +19,7 @@
1919
2020from __future__ import absolute_import
2121
22+from unity8.process_helpers import unlock_unity
2223from unity8.shell import with_lightdm_mock, DragMixin
2324from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2425
@@ -38,8 +39,8 @@ class TestHud(UnityTestCase, DragMixin):
3839 The button must disappear when touching somewhere on the screen except the button itself.
3940
4041 """
41− self.launch_unity()
42− self.main_window.get_greeter().swipe()
42+ unity_proxy = self.launch_unity()
43+ unlock_unity(unity_proxy)
4344 window = self.main_window.get_qml_view()
4445 hud_show_button = self.main_window.get_hud_show_button()
4546 edge_drag_area = self.main_window.get_hud_edge_drag_area()
@@ -80,8 +81,8 @@ class TestHud(UnityTestCase, DragMixin):
8081 Test that the hud button stays on screen and tapping it opens the hud.
8182
8283 """
83− self.launch_unity()
84− self.main_window.get_greeter().swipe()
84+ unity_proxy = self.launch_unity()
85+ unlock_unity(unity_proxy)
8586 window = self.main_window.get_qml_view()
8687 hud_show_button = self.main_window.get_hud_show_button()
8788 hud = self.main_window.get_hud()
@@ -117,8 +118,8 @@ class TestHud(UnityTestCase, DragMixin):
117118
118119 def test_hide_hud_click(self):
119120 """Tapping the close button of the Hud must dismiss it."""
120− self.launch_unity()
121− self.main_window.get_greeter().swipe()
121+ unity_proxy = self.launch_unity()
122+ unlock_unity(unity_proxy)
122123 hud = self.main_window.get_hud()
123124
124125 self._launch_test_app_from_app_screen()
@@ -134,8 +135,8 @@ class TestHud(UnityTestCase, DragMixin):
134135 released downward.
135136
136137 """
137− self.launch_unity()
138− self.main_window.get_greeter().swipe()
138+ unity_proxy = self.launch_unity()
139+ unlock_unity(unity_proxy)
139140 window = self.main_window.get_qml_view()
140141 hud = self.main_window.get_hud()
141142
@@ -152,8 +153,8 @@ class TestHud(UnityTestCase, DragMixin):
152153
153154 def test_launcher_hides_hud(self):
154155 """Opening the Launcher while the Hud is active must close the Hud."""
155− self.launch_unity()
156− self.main_window.get_greeter().swipe()
156+ unity_proxy = self.launch_unity()
157+ unlock_unity(unity_proxy)
157158 hud = self.main_window.get_hud()
158159 launcher = self.main_window.get_launcher()
159160
tests/autopilot/unity8/shell/tests/test_notifications.py+25−30
@@ -21,6 +21,7 @@
2121
2222from __future__ import absolute_import
2323
24+from unity8.process_helpers import unlock_unity
2425from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2526
2627from testtools.matchers import Equals, NotEquals
@@ -118,9 +119,8 @@ class InteractiveNotificationBase(NotificationsBase):
118119
119120 def test_interactive(self):
120121 """Interactive notification must react upon click on itself."""
121− self.launch_unity()
122− greeter = self.main_window.get_greeter()
123− greeter.swipe()
122+ unity_proxy = self.launch_unity()
123+ unlock_unity(unity_proxy)
124124
125125 notify_list = self._get_notifications_list()
126126
@@ -158,9 +158,8 @@ class InteractiveNotificationBase(NotificationsBase):
158158 def test_sd_incoming_call(self):
159159 """Rejecting a call should make notification expand and
160160 offer more options."""
161− self.launch_unity()
162− greeter = self.main_window.get_greeter()
163− greeter.swipe()
161+ unity_proxy = self.launch_unity()
162+ unlock_unity(unity_proxy)
164163
165164 notify_list = self._get_notifications_list()
166165
@@ -336,9 +335,8 @@ class EphemeralNotificationsTests(NotificationsBase):
336335
337336 def test_icon_summary_body(self):
338337 """Notification must display the expected summary and body text."""
339− self.launch_unity()
340− greeter = self.main_window.get_greeter()
341− greeter.swipe()
338+ unity_proxy = self.launch_unity()
339+ unlock_unity(unity_proxy)
342340
343341 notify_list = self._get_notifications_list()
344342
@@ -377,9 +375,8 @@ class EphemeralNotificationsTests(NotificationsBase):
377375 def test_icon_summary(self):
378376 """Notification must display the expected summary and secondary
379377 icon."""
380− self.launch_unity()
381− greeter = self.main_window.get_greeter()
382− greeter.swipe()
378+ unity_proxy = self.launch_unity()
379+ unlock_unity(unity_proxy)
383380
384381 notify_list = self._get_notifications_list()
385382
@@ -416,9 +413,8 @@ class EphemeralNotificationsTests(NotificationsBase):
416413 def test_urgency_order(self):
417414 """Notifications must be displayed in order according to their
418415 urgency."""
419− self.launch_unity()
420− greeter = self.main_window.get_greeter()
421− greeter.swipe()
416+ unity_proxy = self.launch_unity()
417+ unlock_unity(unity_proxy)
422418
423419 notify_list = self._get_notifications_list()
424420
@@ -504,9 +500,8 @@ class EphemeralNotificationsTests(NotificationsBase):
504500
505501 def test_summary_and_body(self):
506502 """Notification must display the expected summary- and body-text."""
507− self.launch_unity()
508− greeter = self.main_window.get_greeter()
509− greeter.swipe()
503+ unity_proxy = self.launch_unity()
504+ unlock_unity(unity_proxy)
510505
511506 notify_list = self._get_notifications_list()
512507
@@ -518,6 +513,7 @@ class EphemeralNotificationsTests(NotificationsBase):
518513
519514 notification = notify_list.wait_select_single(
520515 'Notification', objectName='notification1')
516+
521517 self._assert_notification(
522518 notification,
523519 summary,
@@ -529,9 +525,8 @@ class EphemeralNotificationsTests(NotificationsBase):
529525
530526 def test_summary_only(self):
531527 """Notification must display only the expected summary-text."""
532− self.launch_unity()
533− greeter = self.main_window.get_greeter()
534− greeter.swipe()
528+ unity_proxy = self.launch_unity()
529+ unlock_unity(unity_proxy)
535530
536531 notify_list = self._get_notifications_list()
537532
@@ -548,9 +543,8 @@ class EphemeralNotificationsTests(NotificationsBase):
548543 def test_update_notification_same_layout(self):
549544 """Notification must allow updating its contents while being
550545 displayed."""
551− self.launch_unity()
552− greeter = self.main_window.get_greeter()
553− greeter.swipe()
546+ unity_proxy = self.launch_unity()
547+ unlock_unity(unity_proxy)
554548
555549 notify_list = self._get_notifications_list()
556550
@@ -587,9 +581,8 @@ class EphemeralNotificationsTests(NotificationsBase):
587581 def test_update_notification_layout_change(self):
588582 """Notification must allow updating its contents and layout while
589583 being displayed."""
590− self.launch_unity()
591− greeter = self.main_window.get_greeter()
592− greeter.swipe()
584+ unity_proxy = self.launch_unity()
585+ unlock_unity(unity_proxy)
593586
594587 notify_list = self._get_notifications_list()
595588
@@ -612,6 +605,7 @@ class EphemeralNotificationsTests(NotificationsBase):
612605
613606 get_notification = lambda: notify_list.wait_select_single(
614607 'Notification', objectName='notification1')
608+
615609 self._assert_notification(
616610 get_notification(),
617611 summary,
@@ -633,9 +627,8 @@ class EphemeralNotificationsTests(NotificationsBase):
633627
634628 def test_append_hint(self):
635629 """Notification has to accumulate body-text using append-hint."""
636− self.launch_unity()
637− greeter = self.main_window.get_greeter()
638− greeter.swipe()
630+ unity_proxy = self.launch_unity()
631+ unlock_unity(unity_proxy)
639632
640633 notify_list = self._get_notifications_list()
641634
@@ -654,6 +647,7 @@ class EphemeralNotificationsTests(NotificationsBase):
654647
655648 get_notification = lambda: notify_list.wait_select_single(
656649 'Notification', objectName='notification1')
650+
657651 notification = get_notification()
658652 self._assert_notification(
659653 notification,
@@ -685,6 +679,7 @@ class EphemeralNotificationsTests(NotificationsBase):
685679 hints=[('x-canonical-append', 'true')]
686680 )
687681 notification.show()
682+
688683 get_notification = lambda: notify_list.wait_select_single(
689684 'Notification',
690685 objectName='notification1'