def test_simctl_output_parse_error(command): """If parsing simctl JSON output fails, an exception is raised.""" command.subprocess.check_output.return_value = "this is not JSON" with pytest.raises(BriefcaseCommandError, match="Unable to parse output of xcrun simctl"): get_device_state(command, "2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D")
def test_unknown_device(): "If you ask for an invalid device UDID, an exception is raised." sub = mock.MagicMock() sub.check_output.return_value = simctl_result('no-devices') with pytest.raises(BriefcaseCommandError): get_device_state('dead-beef-dead-beef', sub=sub)
def test_simctl_missing(command): """If simctl is missing or fails to start, an exception is raised.""" command.subprocess.check_output.side_effect = subprocess.CalledProcessError( cmd=["xcrun", "simctl", "list", "-j"], returncode=1) with pytest.raises(BriefcaseCommandError, match="Unable to run xcrun simctl."): get_device_state(command, "2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D")
def test_simctl_missing(): "If simctl is missing or fails to start, an exception is raised." sub = mock.MagicMock() sub.check_output.side_effect = subprocess.CalledProcessError( cmd=['xcrun', 'simctl', 'list', '-j'], returncode=1) with pytest.raises(BriefcaseCommandError): get_device_state('2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D', sub=sub)
def test_known_device_unknown_status(command): """If simctl returns something unexpected as status, we can recover.""" command.subprocess.check_output.return_value = simctl_result( "single-device-unknown") state = get_device_state(command, "2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D") assert state == DeviceState.UNKNOWN
def test_known_device_shutting_down(command): """A valid device that is shutting down can be inspected.""" command.subprocess.check_output.return_value = simctl_result( "single-device-shutting-down") state = get_device_state(command, "2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D") assert state == DeviceState.SHUTTING_DOWN
def test_known_device_booted(command): """A valid, booted device can be inspected.""" command.subprocess.check_output.return_value = simctl_result( "single-device-booted") state = get_device_state(command, "2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D") assert state == DeviceState.BOOTED
def test_known_device_unknown_status(): "If simctl returns something unexpected as status, we can recover" sub = mock.MagicMock() sub.check_output.return_value = simctl_result('single-device-unknown') state = get_device_state('2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D', sub=sub) assert state == DeviceState.UNKNOWN
def test_known_device_shutdown(): "A valid, shut down device can be inspected" sub = mock.MagicMock() sub.check_output.return_value = simctl_result('single-device-shutdown') state = get_device_state('2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D', sub=sub) assert state == DeviceState.SHUTDOWN
def test_known_device_shutting_down(): "A valid device that is shutting down can be inspected" command = mock.MagicMock() command.subprocess.check_output.return_value = simctl_result( 'single-device-shutting-down') state = get_device_state(command, '2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D') assert state == DeviceState.SHUTTING_DOWN
def test_known_device_booted(): "A valid, booted device can be inspected" command = mock.MagicMock() command.subprocess.check_output.return_value = simctl_result( 'single-device-booted') state = get_device_state(command, '2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D') assert state == DeviceState.BOOTED
def test_unknown_device(command): """If you ask for an invalid device UDID, an exception is raised.""" command.subprocess.check_output.return_value = simctl_result("no-devices") with pytest.raises(BriefcaseCommandError): get_device_state(command, "dead-beef-dead-beef")