Skip to content

Commit

Permalink
Merge pull request #1697 from rmartin16/emulator-avd
Browse files Browse the repository at this point in the history
Exclude logging output from emulator list
  • Loading branch information
freakboy3742 committed Mar 14, 2024
2 parents 622d9b8 + 911e02b commit d4e2a43
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
1 change: 1 addition & 0 deletions changes/1697.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A spurious Android emulator named ``@INFO`` will no longer be included in the list of available emulators.
19 changes: 10 additions & 9 deletions src/briefcase/integrations/android_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,28 +814,29 @@ def verify_emulator_skin(self, skin: str):
extract_dir=skin_path,
**({"filter": "data"} if sys.version_info >= (3, 12) else {}),
)
except (shutil.ReadError, EOFError) as err:
except (shutil.ReadError, EOFError) as e:
raise BriefcaseCommandError(
f"Unable to unpack {skin} device skin."
) from err
) from e

# Delete the downloaded file.
skin_tgz_path.unlink()

def emulators(self) -> list[str]:
"""Find the list of emulators that are available."""
try:
# Capture `stderr` so that if the process exits with failure, the
# stderr data is in `e.output`.
output = self.tools.subprocess.check_output(
emulators = self.tools.subprocess.check_output(
[self.emulator_path, "-list-avds"]
).strip()
# AVD names are returned one per line.
if len(output) == 0:
return []
return output.split("\n")
except subprocess.CalledProcessError as e:
raise BriefcaseCommandError("Unable to obtain Android emulator list") from e
else:
return [
emu
for emu in emulators.split("\n")
# ignore any logging output included in output list
if emu and not emu.startswith(("INFO |", "WARNING |", "ERROR |"))
]

def devices(self) -> dict[str, dict[str, str | bool]]:
"""Find the devices that are attached and available to ADB."""
Expand Down
53 changes: 28 additions & 25 deletions tests/integrations/android_sdk/AndroidSDK/test_emulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,35 @@
from briefcase.exceptions import BriefcaseCommandError


def test_no_emulators(mock_tools, android_sdk):
"""If there are no emulators, an empty list is returned."""
mock_tools.subprocess.check_output.return_value = ""

assert android_sdk.emulators() == []


def test_one_emulator(mock_tools, android_sdk):
"""If there is a single emulator, it is returned."""
mock_tools.subprocess.check_output.return_value = "first\n"

assert android_sdk.emulators() == ["first"]


def test_multiple_emulators(mock_tools, android_sdk):
"""If there are multiple emulators, they are all returned."""
mock_tools.subprocess.check_output.return_value = "first\nsecond\nthird\n"

assert android_sdk.emulators() == ["first", "second", "third"]


def test_adb_error(mock_tools, android_sdk):
"""If there is a problem invoking adb, an error is returned."""
@pytest.mark.parametrize(
"output, expected_list",
[
("", []),
("first\n", ["first"]),
("first\nsecond\nthird\n", ["first", "second", "third"]),
("first\n\nsecond", ["first", "second"]),
(
"first\nINFO | Storing crashdata in\nsecond\nWARNING | nothing to see\n"
"third\nERROR | lot to see here",
["first", "second", "third"],
),
],
)
def test_no_emulators(mock_tools, android_sdk, output, expected_list):
"""The returned list of emulators is properly parsed."""
mock_tools.subprocess.check_output.return_value = output

assert android_sdk.emulators() == expected_list


def test_emulator_error(mock_tools, android_sdk):
"""If there is a problem invoking emulator, an error is returned."""
mock_tools.subprocess.check_output.side_effect = subprocess.CalledProcessError(
returncode=69, cmd="adb devices -l"
returncode=69, cmd="emulator -list-avd"
)

with pytest.raises(BriefcaseCommandError):
with pytest.raises(
BriefcaseCommandError,
match=r"Unable to obtain Android emulator list",
):
android_sdk.emulators()

0 comments on commit d4e2a43

Please sign in to comment.