def _parse_devices(self, lines): """ Continue to parse devices from ``simctl list``. :param lines: A generator for the output lines from ``simctl list``. :type lines: genexpr :return: None """ current_runtime = None for line in lines: version_match = self.version_re.match(line) if version_match: current_runtime = self.runtime(version=Version.from_string(version_match.group('version')), is_internal_runtime=bool(version_match.group('internal'))) assert current_runtime continue unavailable_version_match = self.unavailable_version_re.match(line) if unavailable_version_match: current_runtime = None continue device_match = self.devices_re.match(line) if not device_match: if line != '== Device Pairs ==': raise RuntimeError('Expected == Device Pairs == header but got: "{}"'.format(line)) break if current_runtime: device = Simulator.Device(name=device_match.group('name').rstrip(), udid=device_match.group('udid'), available=device_match.group('availability') is None, runtime=current_runtime, host=self._host) current_runtime.devices.append(device)
def xcode_sdk_version(self, sdk_name): if self.is_mac(): # Assumes that xcrun does not write to standard output on failure (e.g. SDK does not exist). xcrun_output = self.executive.run_command(['xcrun', '--sdk', sdk_name, '--show-sdk-version'], return_stderr=False, ignore_errors=True).rstrip() if xcrun_output: return Version.from_string(xcrun_output) return None
def device_version(self): if self.get_option('version'): return Version.from_string(self.get_option('version')) return IOSSimulatorPort._version_from_name( self._name) if IOSSimulatorPort._version_from_name( self._name) else self.host.platform.xcode_sdk_version( 'iphonesimulator')
def test_string_constructor(self): v = Version.from_string('1.2.3.4.5') self.assertEqual(v.major, 1) self.assertEqual(v.minor, 2) self.assertEqual(v.tiny, 3) self.assertEqual(v.micro, 4) self.assertEqual(v.nano, 5)
def __init__(self, sys_module, platform_module, executive): self._executive = executive self._platform_module = platform_module self.os_name = self._determine_os_name(sys_module.platform) self.os_version = None self._is_cygwin = sys_module.platform == 'cygwin' if self.os_name.startswith('mac'): self.os_version = Version.from_string(platform_module.mac_ver()[0]) elif self.os_name.startswith('win'): self.os_version = self._win_version() elif self.os_name == 'linux' or self.os_name == 'freebsd' or self.os_name == 'openbsd' or self.os_name == 'netbsd': return else: # Most other platforms (namely iOS) return conforming version strings. self.os_version = Version.from_string(platform_module.release())
def ios_version(self): runtime_identifier = self.get_option('runtime') if self.get_option('version'): return Version.from_string(self.get_option('version')) if runtime_identifier: return Runtime.from_identifier(runtime_identifier).version return IOSSimulatorPort._version_from_name( self._name) if IOSSimulatorPort._version_from_name( self._name) else self.host.platform.xcode_sdk_version( 'iphonesimulator')
def __init__(self, sys_module, platform_module, executive): self._executive = executive self._platform_module = platform_module self.os_name = self._determine_os_name(sys_module.platform) self.os_version = None self._is_cygwin = sys_module.platform == 'cygwin' if self.os_name.startswith('mac'): self.os_version = Version.from_string(platform_module.mac_ver()[0]) elif self.os_name.startswith('win'): self.os_version = self._win_version() else: # Most other platforms (namely iOS) return conforming version strings. version = re.search(r'\d+.\d+(.\d+)?', platform_module.release()) if version: self.os_version = Version.from_string(version.group(0)) else: _log.debug('No OS version number found')
def simulator_runtime(self): runtime_identifier = self.get_option('runtime') if runtime_identifier: runtime = Runtime.from_identifier(runtime_identifier) elif self.get_option('version'): runtime = Runtime.from_version( Version.from_string(self.get_option('version'))) else: runtime = Runtime.from_version( self.host.platform.xcode_sdk_version('iphonesimulator')) return runtime
def strip_name_formatting(name): # <OS> major.minor.tiny should map to <OS> major if ' ' in name: try: name = '{}{}'.format( ''.join(name.split(' ')[:-1]), Version.from_string(name.split(' ')[-1]).major) except ValueError: pass else: try: split = re.split(r'\d', name) name = '{}{}'.format( split[0], Version.from_string(name[(len(split) - 1):]).major) except ValueError: pass # Strip out any spaces, make everything lower-case result = name.replace(' ', '').lower() return result
def _parse_runtimes(self, lines): """ Continue to parse runtimes from ``simctl list``. :param lines: A generator for the output lines from ``simctl list``. :type lines: genexpr :return: None """ for line in lines: runtime_match = self.runtime_re.match(line) or self.new_runtime_re.match(line) if not runtime_match: if line != '== Devices ==': raise RuntimeError('Expected == Devices == header but got: "{}"'.format(line)) break runtime = Runtime(version=Version.from_string(runtime_match.group('version')), identifier=runtime_match.group('identifier'), available=runtime_match.group('availability') is None, is_internal_runtime=('Internal' in runtime_match.group('os'))) self.runtimes.append(runtime) self._parse_devices(lines)
def device_version(self): if self.get_option('version'): return Version.from_string(self.get_option('version')) if not self.DEVICE_MANAGER: raise RuntimeError(self.NO_ON_DEVICE_TESTING) if not self.DEVICE_MANAGER.available_devices(host=self.host): raise RuntimeError('No devices are available') version = None for device in self.DEVICE_MANAGER.available_devices(host=self.host): if not device.platform.is_ios(): continue if not version: version = device.platform.os_version else: if device.platform.os_version != version: raise RuntimeError('Multiple connected devices have different iOS versions') return version
def ios_version(self): if self.get_option('version'): return Version.from_string(self.get_option('version')) if not apple_additions(): raise RuntimeError(self.NO_ON_DEVICE_TESTING) if not self._device_for_worker_number_map(): raise RuntimeError('No devices are available') version = None for device in self._device_for_worker_number_map(): if not version: version = device.platform.os_version else: if device.platform.os_version != version: raise RuntimeError( 'Multiple connected devices have different iOS versions' ) return version
def device_version(self): if self.get_option('version'): return Version.from_string(self.get_option('version')) return WatchSimulatorPort._version_from_name( self._name) or self.host.platform.xcode_sdk_version( 'watchsimulator')
def _version_from_name(name): if len(name.split('-')) > 2 and name.split('-')[2].isdigit(): return Version.from_string(name.split('-')[2]) return None
def __init__(self, runtime_dict): self.build_version = runtime_dict['buildversion'] self.os_variant = runtime_dict['name'].split(' ')[0] self.version = Version.from_string(runtime_dict['version']) self.identifier = runtime_dict['identifier'] self.name = runtime_dict['name']
def svn_version(self): return Version.from_string(self._run_svn(['--version', '--quiet']))
def xcode_version(self): if not self.is_mac(): raise NotImplementedError return Version.from_string( self._executive.run_command(['xcodebuild', '-version']).split()[1])