def test_connect(self): os_system_history = [] os.system = os_system_history.append self.assertFalse(is_service_running()) # no daemon runs, should try to run it via pkexec instead. # It fails due to the patch and therefore exits the process self.assertRaises(SystemExit, Daemon.connect) self.assertEqual(len(os_system_history), 1) self.assertIsNone(Daemon.connect(False)) class FakeConnection: pass type(SystemBus()).get = lambda *args: FakeConnection() self.assertIsInstance(Daemon.connect(), FakeConnection) self.assertIsInstance(Daemon.connect(False), FakeConnection)
def setUp(self): self.process = multiprocessing.Process( target=os.system, args=('key-mapper-service -d', )) self.process.start() time.sleep(0.5) # should not use pkexec, but rather connect to the previously # spawned process self.interface = Daemon.connect()
def start_processes(self): """Start helper and daemon via pkexec to run in the background.""" # this function is overwritten in tests self.dbus = Daemon.connect() debug = ' -d' if is_debug() else '' cmd = f'pkexec key-mapper-control --command helper {debug}' logger.debug('Running `%s`', cmd) exit_code = os.system(cmd) if exit_code != 0: logger.error('Failed to pkexec the helper, code %d', exit_code) sys.exit()