on xenial help sign in
Tests now use a default lightdm mock if not decorated. Fixes: https://bugs.launchpad.net/bugs/1204772.

Approved by Michał Sawicz, PS Jenkins bot.

commit296538c8b66fcf75f4eaa2c5625ca53106428964 authorChristopher Lee <chris.lee@canonical.com> dateThu 25 Jul 2013, 09:42 (13 years ago) parentc28d978caee0ba
3 files changed+34−33
tests/autopilot/unity8/shell/__init__.py+1−27 tests/autopilot/unity8/shell/tests/__init__.py+33−1 tests/autopilot/unity8/shell/tests/test_hud.py−5
tests/autopilot/unity8/shell/__init__.py+1−27
@@ -21,9 +21,6 @@
2121
2222from functools import wraps
2323import logging
24−import os.path
25−
26−from unity8 import get_mocks_library_path, get_default_extra_mock_libraries
2724
2825
2926logger = logging.getLogger(__name__)
@@ -34,31 +31,8 @@ def with_lightdm_mock(mock_type):
3431 def with_lightdm_mock_internal(fn):
3532 @wraps(fn)
3633 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)
4334 tests_self = args[0]
44− tests_self.patch_environment(
45− 'LD_LIBRARY_PATH',
46− new_ld_library_path
47− )
35+ tests_self.patch_lightdm_mock(mock_type)
4836 return fn(*args, **kwargs)
4937 return wrapper
5038 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
3333import os.path
3434from testtools.matchers import Equals, NotEquals
3535
36−from unity8 import get_lib_path, get_binary_path, get_mocks_library_path
36+from unity8 import (
37+ get_lib_path,
38+ get_binary_path,
39+ get_mocks_library_path,
40+ get_default_extra_mock_libraries,
41+)
3742from unity8.shell.emulators import UnityEmulatorBase
3843from unity8.shell.emulators.dash import Dash
3944from unity8.shell.emulators.main_window import MainWindow
@@ -81,6 +86,7 @@ class UnityTestCase(AutopilotTestCase):
8186 self.addCleanup(self._reset_launcher)
8287
8388 self._proxy = None
89+ self._lightdm_mock_type = None
8490 self.touch = Touch.create()
8591 self._setup_display_details()
8692
@@ -153,6 +159,8 @@ class UnityTestCase(AutopilotTestCase):
153159 binary_path
154160 )
155161
162+ if self._lightdm_mock_type is None:
163+ self.patch_lightdm_mock()
156164 self._setup_extra_mock_environment_patch()
157165
158166 app_proxy = self.launch_test_application(
@@ -170,6 +178,30 @@ class UnityTestCase(AutopilotTestCase):
170178
171179 return app_proxy
172180
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+
173205 def _setup_extra_mock_environment_patch(self):
174206 mocks_library_path = get_mocks_library_path()
175207 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):
3232
3333 scenarios = _get_device_emulation_scenarios()
3434
35− @with_lightdm_mock("single")
3635 def test_show_hud_button_appears(self):
3736 """Swiping up while an app is active must show the 'show hud' button.
3837
@@ -54,7 +53,6 @@ class TestHud(UnityTestCase):
5453 self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
5554 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
5655
57− @with_lightdm_mock("single")
5856 def test_show_hud_appears(self):
5957 """Releasing the touch on the 'show hud' button must display the hud.
6058
@@ -80,7 +78,6 @@ class TestHud(UnityTestCase):
8078 self.touch.release()
8179 self.assertThat(hud.shown, Eventually(Equals(True)))
8280
83− @with_lightdm_mock("single")
8481 def test_hide_hud_click(self):
8582 """Tapping the close button of the Hud must dismiss it."""
8683 self.launch_unity()
@@ -94,7 +91,6 @@ class TestHud(UnityTestCase):
9491 self.touch.tap(x, y)
9592 self.assertThat(hud.shown, Eventually(Equals(False)))
9693
97− @with_lightdm_mock("single")
9894 def test_hide_hud_dragging(self):
9995 """Once open the Hud must close if the upper bar is dragged and
10096 released downward.
@@ -115,7 +111,6 @@ class TestHud(UnityTestCase):
115111 self.touch.drag(start_x, start_y, end_x, end_y)
116112 self.assertThat(hud.shown, Eventually(Equals(False)))
117113
118− @with_lightdm_mock("single")
119114 def test_launcher_hides_hud(self):
120115 """Opening the Launcher while the Hud is active must close the Hud."""
121116 self.launch_unity()