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

Inherits fixtures.Fixture.

Public Member Functions

 setUp (self)
 

Public Attributes

 fake_sensors
 

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.

138 def _create_sensors(self):
139 # Wait for lomiri to start running.
140 Eventually(Equals(True)).match(
141 lambda: process_helpers.is_job_running('lomiri'))
142
143 # Wait for the sensors fifo file to be created.
144 fifo_path = '/tmp/sensor-fifo-{0}'.format(
145 process_helpers._get_lomiri_pid())
146 Eventually(Equals(True)).match(
147 lambda: os.path.exists(fifo_path))
148
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')
153
154

◆ _get_lightdm_mock_path()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors._get_lightdm_mock_path (   self)
protected

Definition at line 74 of file fixture_setup.py.

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, "liblightdm")
78 )
79
80 if not os.path.exists(lightdm_mock_path):
81 raise RuntimeError(
82 "LightDM mock does not exist at path {}.".
83 format(lightdm_mock_path)
84 )
85 return lightdm_mock_path
86

◆ _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.

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'))
92
93 qml_import_path = ':'.join(qml_import_path)
94 return qml_import_path
95

◆ _restart_lomiri_with_testability()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors._restart_lomiri_with_testability (   self)
protected

Definition at line 96 of file fixture_setup.py.

96 def _restart_lomiri_with_testability(self):
97 _environment = {}
98
99 data_dirs = get_data_dirs(True)
100 if data_dirs is not None:
101 _environment['XDG_DATA_DIRS'] = data_dirs
102
103 _environment['QML2_IMPORT_PATH'] = (
104 self._get_qml_import_path_with_mock()
105 )
106
107 new_ld_library_path = [
108 get_default_extra_mock_libraries(),
109 self._get_lightdm_mock_path()
110 ]
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
115
116 # FIXME: we shouldn't be doing this
117 # $MIR_SOCKET, fallback to $XDG_RUNTIME_DIR/mir_socket and
118 # /tmp/mir_socket as last resort
119 try:
120 os.unlink(
121 os.getenv('MIR_SOCKET',
122 os.path.join(os.getenv('XDG_RUNTIME_DIR', "/tmp"),
123 "mir_socket")))
124 except OSError:
125 pass
126 try:
127 os.unlink("/tmp/mir_socket")
128 except OSError:
129 pass
130
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.lomiri_proxy = process_helpers.restart_lomiri_with_testability(
135 *args)
136 self.main_win = self.lomiri_proxy.select_single(shell.ShellView)
137

◆ setUp()

lomiri.fixture_setup.LaunchLomiriWithFakeSensors.setUp (   self)
Restart Lomiri with testability and create sensors.

Definition at line 57 of file fixture_setup.py.

57 def setUp(self):
58 """Restart Lomiri with testability and create sensors."""
59 super().setUp()
60 self.useFixture(
61 fixture_setup.InitctlEnvironmentVariable(
62 LOMIRI_PLATFORM_API_TEST_OVERRIDE='sensors'))
63
64 self.addCleanup(process_helpers.stop_job, 'lomiri')
65 restart_thread = threading.Thread(
66 target=self._restart_lomiri_with_testability)
67 restart_thread.start()
68
69 self._create_sensors()
70
71 restart_thread.join()
72 self.fake_sensors = sensors.FakePlatformSensors()
73

Member Data Documentation

◆ fake_sensors

lomiri.fixture_setup.LaunchLomiriWithFakeSensors.fake_sensors

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: