Loading...
Searching...
No Matches
lomiri.fixture_setup.LaunchLomiriWithFakeSensors Class Reference

## Public Member Functions

| setUp (self)

## Public Attributes

| fake_sensors = sensors.FakePlatformSensors()

## Static Public Attributes

| lomiri_proxy = None
| main_win = None

## Protected Member Functions

| _get_lightdm_mock_path (self)
| _get_qml_import_path_with_mock (self)
| _restart_lomiri_with_testability (self)
| _create_sensors (self)

## Detailed Description

    Fixture to launch Lomiri with an injectable sensors backend.

    :ivar lomiri_proxy: The Autopilot proxy object for the Lomiri shell.

Definition at line 46 of file fixture_setup.py.

## Member Function Documentation

## _create_sensors()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors._create_sensors | ( |  | self | ) |

protected

Definition at line 138 of file fixture_setup.py.

def _create_sensors(self):
# Wait for lomiri to start running.
Eventually(Equals(True)).match(
lambda: process_helpers.is_job_running('lomiri'))
# Wait for the sensors fifo file to be created.
fifo_path = '/tmp/sensor-fifo-{0}'.format(
process_helpers._get_lomiri_pid())
Eventually(Equals(True)).match(
lambda: os.path.exists(fifo_path))
with open(fifo_path, 'w') as fifo:
fifo.write('create accel 0 1000 0.1\n')
fifo.write('create light 0 10 1\n')
fifo.write('create proximity\n')

## _get_lightdm_mock_path()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors._get_lightdm_mock_path | ( |  | self | ) |

protected

Definition at line 74 of file fixture_setup.py.

def _get_lightdm_mock_path(self):
lib_path = get_mocks_library_path()
lightdm_mock_path = os.path.abspath(
os.path.join(lib_path, "liblightdm")
)
if not os.path.exists(lightdm_mock_path):
raise RuntimeError(
"LightDM mock does not exist at path {}.".
format(lightdm_mock_path)
)
return lightdm_mock_path

## _get_qml_import_path_with_mock()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors._get_qml_import_path_with_mock | ( |  | self | ) |

protected

    Return the QML2_IMPORT_PATH value with the mock path prepended.

Definition at line 87 of file fixture_setup.py.

def _get_qml_import_path_with_mock(self):
"""Return the QML2_IMPORT_PATH value with the mock path prepended."""
qml_import_path = [get_mocks_library_path()]
if os.getenv('QML2_IMPORT_PATH') is not None:
qml_import_path.append(os.getenv('QML2_IMPORT_PATH'))
qml_import_path = ':'.join(qml_import_path)
return qml_import_path

## _restart_lomiri_with_testability()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors._restart_lomiri_with_testability | ( |  | self | ) |

protected

Definition at line 96 of file fixture_setup.py.

def _restart_lomiri_with_testability(self):
_environment = {}
data_dirs = get_data_dirs(True)
if data_dirs is not None:
_environment['XDG_DATA_DIRS'] = data_dirs
_environment['QML2_IMPORT_PATH'] = (
self._get_qml_import_path_with_mock()
)
new_ld_library_path = [
get_default_extra_mock_libraries(),
self._get_lightdm_mock_path()
]
if os.getenv('LD_LIBRARY_PATH') is not None:
new_ld_library_path.append(os.getenv('LD_LIBRARY_PATH'))
new_ld_library_path = ':'.join(new_ld_library_path)
_environment['LD_LIBRARY_PATH'] = new_ld_library_path
# FIXME: we shouldn't be doing this
# $MIR_SOCKET, fallback to $XDG_RUNTIME_DIR/mir_socket and
# /tmp/mir_socket as last resort
try:
os.unlink(
os.getenv('MIR_SOCKET',
os.path.join(os.getenv('XDG_RUNTIME_DIR', "/tmp"),
"mir_socket")))
except OSError:
pass
try:
os.unlink("/tmp/mir_socket")
except OSError:
pass
binary_arg = "BINARY=%s" % get_binary_path()
env_args = ["%s=%s" % (k, v) for k, v in _environment.items()]
args = [binary_arg] + env_args
self.lomiri_proxy = process_helpers.restart_lomiri_with_testability(
*args)
self.main_win = self.lomiri_proxy.select_single(shell.ShellView)

## setUp()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors.setUp | ( |  | self | ) |

    Restart Lomiri with testability and create sensors.

Definition at line 57 of file fixture_setup.py.

def setUp(self):
"""Restart Lomiri with testability and create sensors."""
super().setUp()
self.useFixture(
fixture_setup.InitctlEnvironmentVariable(
LOMIRI_PLATFORM_API_TEST_OVERRIDE='sensors'))
self.addCleanup(process_helpers.stop_job, 'lomiri')
restart_thread = threading.Thread(
target=self._restart_lomiri_with_testability)
restart_thread.start()
self._create_sensors()
restart_thread.join()
self.fake_sensors = sensors.FakePlatformSensors()

## Member Data Documentation

## fake_sensors

lomiri.fixture_setup.LaunchLomiriWithFakeSensors.fake_sensors = sensors.FakePlatformSensors()

Definition at line 72 of file fixture_setup.py.

## lomiri_proxy

lomiri.fixture_setup.LaunchLomiriWithFakeSensors.lomiri_proxy = None

static

Definition at line 54 of file fixture_setup.py.

## main_win

lomiri.fixture_setup.LaunchLomiriWithFakeSensors.main_win = None

static

Definition at line 55 of file fixture_setup.py.

The documentation for this class was generated from the following file:

- tests/autopilot/lomiri/fixture_setup.py