Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_known_device_booted():
"A valid, booted device can be inspected"
sub = mock.MagicMock()
sub.check_output.return_value = simctl_result('single-device-booted')
state = get_device_state('2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D', sub=sub)
assert state == DeviceState.BOOTED
def test_run_app_simulator_shut_down(first_app_config, tmp_path):
"An iOS App can be started when the simulator is shut down"
command = iOSXcodeRunCommand(base_path=tmp_path)
# A valid target device will be selected.
command.select_target_device = mock.MagicMock(
return_value=(
'2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D', '13.2', 'iPhone 11'
)
)
# Simulator is shut down
command.get_device_state = mock.MagicMock(return_value=DeviceState.SHUTDOWN)
command.subprocess = mock.MagicMock()
# Run the app
command.run_app(first_app_config)
# The correct sequence of commands was issued.
command.subprocess.run.assert_has_calls([
# Boot the device
mock.call(
['xcrun', 'simctl', 'boot', '2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D'],
check=True,
),
# Open the simulator
mock.call(
[
def test_run_app_simulator_booted(first_app_config, tmp_path):
"An iOS App can be started when the simulator is already booted"
command = iOSXcodeRunCommand(base_path=tmp_path)
# A valid target device will be selected.
command.select_target_device = mock.MagicMock(
return_value=(
'2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D', '13.2', 'iPhone 11'
)
)
# Simulator is already booted
command.get_device_state = mock.MagicMock(return_value=DeviceState.BOOTED)
command.subprocess = mock.MagicMock()
# Run the app
command.run_app(first_app_config)
# The correct sequence of commands was issued.
command.subprocess.run.assert_has_calls([
# Open the simulator
mock.call(
[
'open',
'-a', 'Simulator',
'--args',
'-CurrentDeviceUDID', '2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D'
],
def test_known_device_shutting_down():
"A valid device that is shutting down can be inspected"
sub = mock.MagicMock()
sub.check_output.return_value = simctl_result('single-device-shutting-down')
state = get_device_state('2D3503A3-6EB9-4B37-9B17-C7EFEF2FA32D', sub=sub)
assert state == DeviceState.SHUTTING_DOWN
be asked to select a device at runtime.
:param base_path: The path to the project directory.
"""
udid, iOS_version, device = self.select_target_device(udid)
print()
print("Targeting an {device} running iOS {iOS_version} (device UDID {udid})".format(
device=device,
iOS_version=iOS_version,
udid=udid,
))
# The simulator needs to be booted before being started.
# If it's shut down, we can boot it again; but if it's currently
# shutting down, we need to wait for it to shut down before restarting.
device_state = self.get_device_state(udid, sub=self.subprocess)
if device_state not in {DeviceState.SHUTDOWN, DeviceState.BOOTED}:
print('Waiting for simulator...', flush=True, end='')
while device_state not in {DeviceState.SHUTDOWN, DeviceState.BOOTED}:
self.sleep(2)
print('.', flush=True, end='')
device_state = self.get_device_state(udid, sub=self.subprocess)
# We now know the simulator is either shut down or booted;
# if it's shut down, start it again.
if device_state == DeviceState.SHUTDOWN:
try:
print("Booting {device} simulator running iOS {iOS_version}...".format(
device=device,
iOS_version=iOS_version,
)
)
self.subprocess.run(
))
# The simulator needs to be booted before being started.
# If it's shut down, we can boot it again; but if it's currently
# shutting down, we need to wait for it to shut down before restarting.
device_state = self.get_device_state(udid, sub=self.subprocess)
if device_state not in {DeviceState.SHUTDOWN, DeviceState.BOOTED}:
print('Waiting for simulator...', flush=True, end='')
while device_state not in {DeviceState.SHUTDOWN, DeviceState.BOOTED}:
self.sleep(2)
print('.', flush=True, end='')
device_state = self.get_device_state(udid, sub=self.subprocess)
# We now know the simulator is either shut down or booted;
# if it's shut down, start it again.
if device_state == DeviceState.SHUTDOWN:
try:
print("Booting {device} simulator running iOS {iOS_version}...".format(
device=device,
iOS_version=iOS_version,
)
)
self.subprocess.run(
['xcrun', 'simctl', 'boot', udid],
check=True
)
except subprocess.CalledProcessError:
raise BriefcaseCommandError(
"Unable to boot {device} simulator running iOS {iOS_version}".format(
device=device,
iOS_version=iOS_version,
)