26 import ubuntuuitoolkit
27 from autopilot
import introspection
28 from autopilot.matchers
import Eventually
29 from testtools.matchers
import Equals
30 from ubuntuuitoolkit
import fixture_setup
34 get_mocks_library_path,
35 get_default_extra_mock_libraries,
43 logger = logging.getLogger(__name__)
48 """Fixture to launch Unity8 with an injectable sensors backend.
50 :ivar unity_proxy: The Autopilot proxy object for the Unity shell.
58 """Restart Unity8 with testability and create sensors."""
61 fixture_setup.InitctlEnvironmentVariable(
62 UBUNTU_PLATFORM_API_TEST_OVERRIDE=
'sensors'))
64 self.addCleanup(process_helpers.stop_job,
'unity8')
65 restart_thread = threading.Thread(
67 restart_thread.start()
74 def _get_lightdm_mock_path(self):
75 lib_path = get_mocks_library_path()
76 lightdm_mock_path = os.path.abspath(
77 os.path.join(lib_path,
"IntegratedLightDM",
"liblightdm")
80 if not os.path.exists(lightdm_mock_path):
82 "LightDM mock does not exist at path {}.".
83 format(lightdm_mock_path)
85 return lightdm_mock_path
87 def _get_qml_import_path_with_mock(self):
88 """Return the QML2_IMPORT_PATH value with the mock path prepended."""
89 qml_import_path = [get_mocks_library_path()]
90 if os.getenv(
'QML2_IMPORT_PATH')
is not None:
91 qml_import_path.append(os.getenv(
'QML2_IMPORT_PATH'))
93 qml_import_path =
':'.join(qml_import_path)
94 return qml_import_path
96 def _restart_unity_with_testability(self):
99 data_dirs = get_data_dirs(
True)
100 if data_dirs
is not None:
101 _environment[
'XDG_DATA_DIRS'] = data_dirs
103 _environment[
'QML2_IMPORT_PATH'] = (
107 new_ld_library_path = [
108 get_default_extra_mock_libraries(),
111 if os.getenv(
'LD_LIBRARY_PATH')
is not None:
112 new_ld_library_path.append(os.getenv(
'LD_LIBRARY_PATH'))
113 new_ld_library_path =
':'.join(new_ld_library_path)
114 _environment[
'LD_LIBRARY_PATH'] = new_ld_library_path
121 os.getenv(
'MIR_SOCKET',
122 os.path.join(os.getenv(
'XDG_RUNTIME_DIR',
"/tmp"),
127 os.unlink(
"/tmp/mir_socket")
131 binary_arg =
"BINARY=%s" % get_binary_path()
132 env_args = [
"%s=%s" % (k, v)
for k, v
in _environment.items()]
133 args = [binary_arg] + env_args
134 self.
unity_proxy = process_helpers.restart_unity_with_testability(
138 def _create_sensors(self):
140 Eventually(Equals(
True)).match(
141 lambda: process_helpers.is_job_running(
'unity8'))
144 fifo_path =
'/tmp/sensor-fifo-{0}'.format(
145 process_helpers._get_unity_pid())
146 Eventually(Equals(
True)).match(
147 lambda: os.path.exists(fifo_path))
149 with open(fifo_path,
'w')
as fifo:
150 fifo.write(
'create accel 0 1000 0.1\n')
151 fifo.write(
'create light 0 10 1\n')
152 fifo.write(
'create proximity\n')
157 """Fixture to launch Unity8 with testability.
159 :ivar unity_proxy: The Autopilot proxy object for the Unity shell.
166 """Initialize the fixture instance.
168 :param str binary_path: The path to the Dash app binary.
169 :param cli_arguments: The arguments to pass when launching the
170 :param variables: The variables to use when launching the app.
171 :type variables: A dictionary.
179 """Restart unity with testability when the fixture is used."""
184 def restart_unity(self):
187 def restart_unity_with_testability(self):
192 '{}={}'.format(key, value)
for key, value
in self.variables.items()
194 all_args = [binary_arg] + variable_args
196 self.
unity_proxy = process_helpers.restart_unity_with_testability(
199 def _unlink_mir_socket(self):
205 os.getenv(
'MIR_SOCKET',
206 os.path.join(os.getenv(
'XDG_RUNTIME_DIR',
"/tmp"),
211 os.unlink(
"/tmp/mir_socket")
215 def stop_unity(self):
216 process_helpers.stop_job(
'unity8')
221 """Fixture to launch the Dash app."""
224 """Initialize an instance.
226 :param str binary_path: The path to the Dash app binary.
227 :param variables: The variables to use when launching the app.
228 :type variables: A dictionary.
236 """Launch the dash app when the fixture is used."""
241 def launch_application(self):
243 testability_arg =
'QT_LOAD_TESTABILITY={}'.format(1)
245 '{}={}'.format(key, value)
for key, value
in self.variables.items()
247 all_args = [binary_arg, testability_arg] + env_args
249 pid = process_helpers.start_job(
'unity8-dash', *all_args)
250 return introspection.get_proxy_object_for_existing_process(
252 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
255 def stop_application(self):
256 process_helpers.stop_job(
'unity8-dash')
259 class DisplayRotationLock(fixtures.Fixture):
267 original_state = self._is_rotation_lock_enabled()
268 if self.enable != original_state:
269 self.addCleanup(self._set_rotation_lock, original_state)
270 self._set_rotation_lock(self.enable)
272 def _is_rotation_lock_enabled(self):
275 'com.ubuntu.touch.system',
278 output = subprocess.check_output(command, universal_newlines=
True)
279 return True if output.count(
'true')
else False
281 def _set_rotation_lock(self, value):
282 value_string =
'true' if value
else 'false'
285 'com.ubuntu.touch.system',
286 'rotation-lock', value_string
288 subprocess.check_output(command)
293 """Fixture to launch the indicator test service."""
295 def __init__(self, action_delay, ensure_not_running=True):
296 """Initialize an instance.
298 :param action_delay: The delay to use when activating actions.
299 Measured in milliseconds. Value of -1 will result in infinite delay.
300 :type action_delay: An integer.
301 :param boolean ensure_not_running: Make sure service is not running
304 super(LaunchMockIndicatorService, self).
__init__()
315 def launch_service(self):
316 logger.info(
"Starting unity-mock-indicator-service")
317 binary_path = get_binary_path(
'unity-mock-indicator-service')
318 binary_arg =
'BINARY={}'.format(binary_path)
320 all_args = [binary_arg, env_args]
321 process_helpers.start_job(
'unity-mock-indicator-service', *all_args)
323 def stop_service(self):
324 logger.info(
"Stopping unity-mock-indicator-service")
325 process_helpers.stop_job(
'unity-mock-indicator-service')
327 def ensure_service_not_running(self):
328 if process_helpers.is_job_running(
'unity-mock-indicator-service'):
def restart_unity_with_testability(self)
def _get_qml_import_path_with_mock(self)
def __init__(self, binary_path, variables)
def launch_application(self)
def __init__(self, binary_path, variables)
def _get_lightdm_mock_path(self)
def ensure_service_not_running(self)
def _unlink_mir_socket(self)
def _restart_unity_with_testability(self)
def _create_sensors(self)
def stop_application(self)