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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
import subprocess
import pytest
from briefcase.exceptions import BriefcaseCommandError
def test_forward(mock_tools, adb):
"""A port forwarding."""
# Invoke forward
adb.forward(5555, 6666)
# Validate call parameters.
mock_tools.subprocess.check_output.assert_called_once_with(
[
mock_tools.android_sdk.adb_path,
"-s",
"exampleDevice",
"forward",
"tcp:5555",
"tcp:6666",
],
)
def test_forward_failure(adb, mock_tools):
"""If port forwarding fails, the error is caught."""
# Mock out the run command on an adb instance
mock_tools.subprocess.check_output.side_effect = subprocess.CalledProcessError(
returncode=1, cmd=""
)
with pytest.raises(BriefcaseCommandError):
adb.forward(5555, 6666)
def test_forward_remove(mock_tools, adb):
"""A port forwarding removal."""
# Invoke forward remove
adb.forward_remove(5555)
# Validate call parameters.
mock_tools.subprocess.check_output.assert_called_once_with(
[
mock_tools.android_sdk.adb_path,
"-s",
"exampleDevice",
"forward",
"--remove",
"tcp:5555",
],
)
def test_forward_remove_failure(adb, mock_tools):
"""If port forwarding removal fails, the error is caught."""
# Mock out the run command on an adb instance
mock_tools.subprocess.check_output.side_effect = subprocess.CalledProcessError(
returncode=1, cmd=""
)
with pytest.raises(BriefcaseCommandError):
adb.forward_remove(5555)
def test_reverse(mock_tools, adb):
"""A port reversing."""
# Invoke reverse
adb.reverse(5555, 6666)
# Validate call parameters.
mock_tools.subprocess.check_output.assert_called_once_with(
[
mock_tools.android_sdk.adb_path,
"-s",
"exampleDevice",
"reverse",
"tcp:5555",
"tcp:6666",
],
)
def test_reverse_failure(adb, mock_tools):
"""If port reversing fails, the error is caught."""
# Mock out the run command on an adb instance
mock_tools.subprocess.check_output.side_effect = subprocess.CalledProcessError(
returncode=1, cmd=""
)
with pytest.raises(BriefcaseCommandError):
adb.reverse(5555, 6666)
def test_reverse_remove(mock_tools, adb):
"""A port reversing removal."""
# Invoke reverse remove
adb.reverse_remove(5555)
# Validate call parameters.
mock_tools.subprocess.check_output.assert_called_once_with(
[
mock_tools.android_sdk.adb_path,
"-s",
"exampleDevice",
"reverse",
"--remove",
"tcp:5555",
],
)
def test_reverse_remove_failure(adb, mock_tools):
"""If port reversing removal fails, the error is caught."""
# Mock out the run command on an adb instance
mock_tools.subprocess.check_output.side_effect = subprocess.CalledProcessError(
returncode=1, cmd=""
)
with pytest.raises(BriefcaseCommandError):
adb.reverse_remove(5555)
|