async def clone( self, udid: str, destination_device_set: Optional[str] = None) -> TargetDescription: arguments = ["--clone", udid] if destination_device_set is not None: arguments.extend( ["--clone-destination-set", destination_device_set]) output = await self._run_companion_command(arguments=arguments) return target_description_from_json(output.splitlines()[-1])
async def list_targets( self, only: Optional[OnlyFilter] = None, timeout: Optional[timedelta] = None) -> List[TargetDescription]: arguments = ["--list", "1"] + _only_arg_from_filter(only=only) output = await self._run_companion_command(arguments=arguments, timeout=timeout) return [ target_description_from_json(data=line.strip()) for line in output.splitlines() if len(line.strip()) ]
async def list_targets( self, only: Optional[TargetType] = None) -> List[TargetDescription]: arguments = ["--list", "1"] if only is not None: arguments.extend([ "--only", "simulator" if only is TargetType.SIMULATOR else "device" ]) output = await self._run_companion_command(arguments=arguments) return [ target_description_from_json(data=line.strip()) for line in output.splitlines() if len(line.strip()) ]
async def boot_headless(self, udid: str, verify: bool = True) -> AsyncGenerator[None, None]: async with self._start_companion_command([ "--headless", "1", "--boot", udid, "--verify-booted", "1" if verify else "0", ]) as process: # The first line written to stdout is information about the booted sim. line = (await none_throws(process.stdout).readline()).decode() target = target_description_from_json(line) self._logger.info(f"{target} is now booted") yield None self._logger.info(f"Done with {target}. Shutting down.")
async def boot_headless( self, udid: str, verify: bool = True, timeout: Optional[timedelta] = None) -> AsyncGenerator[None, None]: async with self._start_companion_command([ "--headless", "1", "--boot", udid, "--verify-booted", "1" if verify else "0", ]) as process: # The first line written to stdout is information about the booted sim. data = await asyncio.wait_for( none_throws(process.stdout).readline(), timeout=None if timeout is None else timeout.total_seconds(), ) line = data.decode() target = target_description_from_json(line) self._logger.info(f"{target} is now booted") yield None self._logger.info(f"Done with {target}. Shutting down.")
def test_target_description_all_optional_fields(self) -> None: target = TARGET_DESCRIPTION_FIXTURE._replace( companion_info=COMPANION_INFO_FIXTURE) self.assertEqual( target, target_description_from_json(json_format_target_info(target)))
def test_target_description_no_optional_fields(self) -> None: self.assertEqual( TARGET_DESCRIPTION_FIXTURE, target_description_from_json( json_format_target_info(TARGET_DESCRIPTION_FIXTURE)), )
async def create(self, device_type: str, os_version: str) -> TargetDescription: output = await self._run_companion_command( arguments=["--create", f"{device_type},{os_version}"] ) return target_description_from_json(output.splitlines()[-1])
async def clone(self, udid: str) -> str: output = await self._run_udid_command(udid=udid, command="clone") cloned = target_description_from_json(output.splitlines()[-1]) return cloned.udid