def test_swapping_devices(self): SimulatedDeviceTest.reset_simulated_device_manager() host = SimulatedDeviceTest.mock_host_for_simctl() SimulatedDeviceManager.available_devices(host) # We won't test the creation and deletion of simulators, only managing existing sims SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.platform_device.device_type == DeviceType.from_string('iPhone 8'), host)[0], SimulatedDevice.DeviceState.BOOTED) SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.platform_device.device_type == DeviceType.from_string('iPhone X'), host)[0], SimulatedDevice.DeviceState.BOOTED) SimulatedDeviceManager.initialize_devices(DeviceRequest(DeviceType.from_string('iPhone 8')), host=host) self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES)) self.assertEquals('17104B4F-E77D-4019-98E6-621FE3CC3653', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid) self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state()) # Now swap for the X SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN) SimulatedDeviceManager.swap(SimulatedDeviceManager.INITIALIZED_DEVICES[0], DeviceRequest(DeviceType.from_string('iPhone X')), host) self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES)) self.assertEquals('4E6E7393-C4E3-4323-AA8B-4A42A45AE7B8', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid) self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state()) SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN) SimulatedDeviceManager.tear_down(host) self.assertIsNone(SimulatedDeviceManager.INITIALIZED_DEVICES)
def default_child_processes(self): def booted_ios_devices_filter(device): if not device.platform_device.is_booted_or_booting(): return False return device.platform_device.device_type in DeviceType(software_variant='iOS', software_version=self.ios_version()) if self.get_option('dedicated_simulators', False): num_booted_sims = len(SimulatedDeviceManager.device_by_filter(booted_ios_devices_filter, host=self.host)) if num_booted_sims: return num_booted_sims return SimulatedDeviceManager.max_supported_simulators(self.host)
def test_available_devices(self): SimulatedDeviceTest.reset_simulated_device_manager() host = SimulatedDeviceTest.mock_host_for_simctl() SimulatedDeviceManager.available_devices(host) # There should only be 1 iPhone X, iPhone 8 and iPhone SE self.assertEquals( 1, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('iPhone X'), host))) self.assertEquals( 1, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('iPhone 8'), host))) # There should be 2 5s and 6s self.assertEquals( 2, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('iPhone 5s'), host))) self.assertEquals( 2, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('iPhone 6s'), host))) # 19 iPhones self.assertEquals( 19, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('iPhone'), host))) # 11 iPads self.assertEquals( 11, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('iPad'), host))) # 18 Apple watches self.assertEquals( 6, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('Apple Watch'), host))) # 3 Apple TVs self.assertEquals( 3, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType. from_string('Apple TV'), host))) # 18 devices running iOS 11.0 self.assertEquals( 18, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType( software_variant='iOS', software_version=Version(11, 0, 1)), host))) # 11 iPhones running iOS 11.0 self.assertEquals( 11, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType( hardware_family='iPhone', software_version=Version(11, 0, 1)), host))) # 1 device running iOS 12 self.assertEquals( 1, len( SimulatedDeviceManager.device_by_filter( lambda device: device.device_type == DeviceType( software_variant='iOS', software_version=Version(12, 0, 0)), host)))