1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
import subprocess
from unittest.mock import MagicMock
import pytest
from briefcase.exceptions import BriefcaseCommandError, InvalidDeviceError
def test_booted(adb, capsys):
"""A booted device returns true."""
# Mock out the adb response for an emulator
adb.run = MagicMock(return_value="1\n")
# Invoke avd_name
assert adb.has_booted()
# Validate call parameters.
adb.run.assert_called_once_with("shell", "getprop", "sys.boot_completed")
def test_not_booted(adb, capsys):
"""A non-booted device returns False."""
# Mock out the adb response for an emulator
adb.run = MagicMock(return_value="\n")
# Invoke avd_name
assert not adb.has_booted()
# Validate call parameters.
adb.run.assert_called_once_with("shell", "getprop", "sys.boot_completed")
def test_adb_failure(adb, capsys):
"""If ADB fails, an error is raised."""
# Mock out the adb response for an emulator
adb.run = MagicMock(
side_effect=subprocess.CalledProcessError(returncode=69, cmd="emu avd name")
)
# Invoke avd_name
with pytest.raises(BriefcaseCommandError):
adb.has_booted()
# Validate call parameters.
adb.run.assert_called_once_with("shell", "getprop", "sys.boot_completed")
def test_invalid_device(adb, capsys):
"""If the device ID is invalid, an error is raised."""
# Mock out the adb response for an emulator
adb.run = MagicMock(side_effect=InvalidDeviceError("device", "exampleDevice"))
# Invoke avd_name
with pytest.raises(BriefcaseCommandError):
adb.has_booted()
# Validate call parameters.
adb.run.assert_called_once_with("shell", "getprop", "sys.boot_completed")
|