async def run_with_companion(self, args: Namespace, companion: Companion) -> None: if args.headless: async with companion.boot_headless(udid=self.get_udid(args)): await signal_handler_event("headless_boot").wait() else: await companion.boot(udid=self.get_udid(args))
async def _run_impl(self, args: Namespace) -> None: await self.run_with_companion( args=args, companion=Companion( companion_path=args.companion_path, device_set_path=None, logger=self.logger, ), )
async def test_spawn_tcp_server(self) -> None: spawner = Companion(companion_path="idb_path", device_set_path=None, logger=mock.Mock()) spawner._log_file_path = mock.Mock() udid = "someUdid" with mock.patch( "idb.common.companion.asyncio.create_subprocess_exec", new=AsyncMock(), ) as exec_mock, mock.patch("idb.common.companion.open"): process_mock = mock.Mock() process_mock.stdout.readline = AsyncMock( return_value=json.dumps({ "hostname": "myHost", "grpc_port": 1234 }).encode("utf-8")) exec_mock.return_value = process_mock (_, port) = await spawner.spawn_tcp_server( config=CompanionServerConfig( udid=udid, only=TargetType.SIMULATOR, log_file_path=None, cwd=None, tmp_path=None, reparent=True, ), port=None, ) exec_mock.assert_called_once_with( "idb_path", "--udid", "someUdid", "--grpc-port", "0", "--only", "simulator", stdout=mock.ANY, stderr=mock.ANY, stdin=mock.ANY, cwd=None, env=os.environ, preexec_fn=os.setpgrp, ) self.assertEqual(port, 1234)
async def for_companion( cls, companion: Companion, udid: str, logger: logging.Logger ) -> AsyncGenerator["IdbClient", None]: with tempfile.NamedTemporaryFile() as temp: # Remove the tempfile so we can bind to it first. os.remove(temp.name) async with companion.unix_domain_server( udid=udid, path=temp.name ) as resolved_path, IdbClient.build( address=DomainSocketAddress(path=resolved_path), is_local=True, logger=logger, ) as client: yield client
def __init__( self, companion_path: Optional[str] = None, device_set_path: Optional[str] = None, prune_dead_companion: bool = True, logger: Optional[logging.Logger] = None, ) -> None: os.makedirs(BASE_IDB_FILE_PATH, exist_ok=True) self._logger: logging.Logger = (logger if logger else logging.getLogger("idb_grpc_client")) self._companion_set = CompanionSet(logger=self._logger) self._companion: Optional[Companion] = (Companion( companion_path=companion_path, device_set_path=device_set_path, logger=self._logger, ) if companion_path is not None else None) self._prune_dead_companion = prune_dead_companion
def setUp(self) -> None: self.udid = "someUdid" self.spawner = Companion(companion_path="idb_path", device_set_path=None, logger=mock.Mock()) self.spawner._log_file_path = mock.Mock() self.companion_server_config = CompanionServerConfig( udid=self.udid, only=TargetType.SIMULATOR, log_file_path=None, cwd=None, tmp_path=None, reparent=True, ) self.exec_mock_common_args = { "stdout": mock.ANY, "stderr": mock.ANY, "stdin": mock.ANY, "cwd": None, "preexec_fn": os.setpgrp, }