on xenial help sign in
Removed need to specifically decorate test for lightdm mock, now defaults to use 'single'.
caee0baChristopher Lee
tests/autopilot/unity8/shell/__init__.py+1−27
@@ -21,9 +21,6 @@
21
21
22from functools import wraps
22from functools import wraps
23import logging
23import logging
24−import os.path
25−
26−from unity8 import get_mocks_library_path, get_default_extra_mock_libraries
27
24
28
25
29logger = logging.getLogger(__name__)
26logger = logging.getLogger(__name__)
@@ -34,31 +31,8 @@ def with_lightdm_mock(mock_type):
34 def with_lightdm_mock_internal(fn):
31 def with_lightdm_mock_internal(fn):
35 @wraps(fn)
32 @wraps(fn)
36 def wrapper(*args, **kwargs):
33 def wrapper(*args, **kwargs):
37− logger.info("Setting up LightDM mock type '%s'", mock_type)
38− new_ld_library_path = "%s:%s" % (
39− get_default_extra_mock_libraries(),
40− _get_ld_library_path(mock_type)
41− )
42− logger.info("New library path: %s", new_ld_library_path)
43 tests_self = args[0]
34 tests_self = args[0]
44− tests_self.patch_environment(
35+ tests_self.patch_lightdm_mock(mock_type)
45− 'LD_LIBRARY_PATH',
46− new_ld_library_path
47− )
48 return fn(*args, **kwargs)
36 return fn(*args, **kwargs)
49 return wrapper
37 return wrapper
50 return with_lightdm_mock_internal
38 return with_lightdm_mock_internal
51−
52−
53−def _get_ld_library_path(mock_type):
54− lib_path = get_mocks_library_path()
55− new_ld_library_path = os.path.abspath(
56− os.path.join(lib_path, "LightDM", mock_type)
57− )
58−
59− if not os.path.exists(new_ld_library_path):
60− raise RuntimeError(
61− "LightDM mock '%s' does not exist at path '%s'."
62− % (mock_type, new_ld_library_path)
63− )
64− return new_ld_library_path
tests/autopilot/unity8/shell/tests/__init__.py+33−1
@@ -33,7 +33,12 @@ import logging
33import os.path
33import os.path
34from testtools.matchers import Equals, NotEquals
34from testtools.matchers import Equals, NotEquals
35
35
36+from unity8 import (
37+ get_lib_path,
38+ get_binary_path,
36−from unity8 import get_lib_path, get_binary_path, get_mocks_library_path
39+ get_mocks_library_path,
40+ get_default_extra_mock_libraries,
41+)
37from unity8.shell.emulators import UnityEmulatorBase
42from unity8.shell.emulators import UnityEmulatorBase
38from unity8.shell.emulators.dash import Dash
43from unity8.shell.emulators.dash import Dash
39from unity8.shell.emulators.main_window import MainWindow
44from unity8.shell.emulators.main_window import MainWindow
@@ -81,6 +86,7 @@ class UnityTestCase(AutopilotTestCase):
81 self.addCleanup(self._reset_launcher)
86 self.addCleanup(self._reset_launcher)
82
87
83 self._proxy = None
88 self._proxy = None
89+ self._lightdm_mock_type = None
84 self.touch = Touch.create()
90 self.touch = Touch.create()
85 self._setup_display_details()
91 self._setup_display_details()
86
92
@@ -153,6 +159,8 @@ class UnityTestCase(AutopilotTestCase):
153 binary_path
159 binary_path
154 )
160 )
155
161
162+ if self._lightdm_mock_type is None:
163+ self.patch_lightdm_mock()
156 self._setup_extra_mock_environment_patch()
164 self._setup_extra_mock_environment_patch()
157
165
158 app_proxy = self.launch_test_application(
166 app_proxy = self.launch_test_application(
@@ -170,6 +178,30 @@ class UnityTestCase(AutopilotTestCase):
170
178
171 return app_proxy
179 return app_proxy
172
180
181+ def patch_lightdm_mock(self, mock_type='single'):
182+ self._lightdm_mock_type = mock_type
183+ logger.info("Setting up LightDM mock type '%s'", mock_type)
184+ new_ld_library_path = "%s:%s" % (
185+ get_default_extra_mock_libraries(),
186+ self._get_lightdm_mock_path(mock_type)
187+ )
188+ logger.info("New library path: %s", new_ld_library_path)
189+
190+ self.patch_environment('LD_LIBRARY_PATH', new_ld_library_path)
191+
192+ def _get_lightdm_mock_path(self, mock_type):
193+ lib_path = get_mocks_library_path()
194+ lightdm_mock_path = os.path.abspath(
195+ os.path.join(lib_path, "LightDM", mock_type)
196+ )
197+
198+ if not os.path.exists(lightdm_mock_path):
199+ raise RuntimeError(
200+ "LightDM mock '%s' does not exist at path '%s'."
201+ % (mock_type, lightdm_mock_path)
202+ )
203+ return lightdm_mock_path
204+
173 def _setup_extra_mock_environment_patch(self):
205 def _setup_extra_mock_environment_patch(self):
174 mocks_library_path = get_mocks_library_path()
206 mocks_library_path = get_mocks_library_path()
175 self.patch_environment('QML2_IMPORT_PATH', mocks_library_path)
207 self.patch_environment('QML2_IMPORT_PATH', mocks_library_path)
tests/autopilot/unity8/shell/tests/test_hud.py−5
@@ -32,7 +32,6 @@ class TestHud(UnityTestCase):
32
32
33 scenarios = _get_device_emulation_scenarios()
33 scenarios = _get_device_emulation_scenarios()
34
34
35− @with_lightdm_mock("single")
36 def test_show_hud_button_appears(self):
35 def test_show_hud_button_appears(self):
37 """Swiping up while an app is active must show the 'show hud' button.
36 """Swiping up while an app is active must show the 'show hud' button.
38
37
@@ -54,7 +53,6 @@ class TestHud(UnityTestCase):
54 self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
53 self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
55 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
54 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
56
55
57− @with_lightdm_mock("single")
58 def test_show_hud_appears(self):
56 def test_show_hud_appears(self):
59 """Releasing the touch on the 'show hud' button must display the hud.
57 """Releasing the touch on the 'show hud' button must display the hud.
60
58
@@ -80,7 +78,6 @@ class TestHud(UnityTestCase):
80 self.touch.release()
78 self.touch.release()
81 self.assertThat(hud.shown, Eventually(Equals(True)))
79 self.assertThat(hud.shown, Eventually(Equals(True)))
82
80
83− @with_lightdm_mock("single")
84 def test_hide_hud_click(self):
81 def test_hide_hud_click(self):
85 """Tapping the close button of the Hud must dismiss it."""
82 """Tapping the close button of the Hud must dismiss it."""
86 self.launch_unity()
83 self.launch_unity()
@@ -94,7 +91,6 @@ class TestHud(UnityTestCase):
94 self.touch.tap(x, y)
91 self.touch.tap(x, y)
95 self.assertThat(hud.shown, Eventually(Equals(False)))
92 self.assertThat(hud.shown, Eventually(Equals(False)))
96
93
97− @with_lightdm_mock("single")
98 def test_hide_hud_dragging(self):
94 def test_hide_hud_dragging(self):
99 """Once open the Hud must close if the upper bar is dragged and
95 """Once open the Hud must close if the upper bar is dragged and
100 released downward.
96 released downward.
@@ -115,7 +111,6 @@ class TestHud(UnityTestCase):
115 self.touch.drag(start_x, start_y, end_x, end_y)
111 self.touch.drag(start_x, start_y, end_x, end_y)
116 self.assertThat(hud.shown, Eventually(Equals(False)))
112 self.assertThat(hud.shown, Eventually(Equals(False)))
117
113
118− @with_lightdm_mock("single")
119 def test_launcher_hides_hud(self):
114 def test_launcher_hides_hud(self):
120 """Opening the Launcher while the Hud is active must close the Hud."""
115 """Opening the Launcher while the Hud is active must close the Hud."""
121 self.launch_unity()
116 self.launch_unity()