Skip to content

Commit 10b8f2d

Browse files
committed
test search device function in tooling
1 parent 7f40afb commit 10b8f2d

3 files changed

Lines changed: 79 additions & 1 deletion

File tree

poetry.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ regex = "^2022.9.13"
2222
schema = "^0.7.5"
2323
py7zr = "^0.20.0"
2424
pytest-cov = "^4.0.0"
25+
pytest-mock = "^3.10.0"
2526

2627
[tool.poetry.dev-dependencies]
2728

tests/test_tool_utils.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""Test interactions with tools like adb and fastboot"""
2+
3+
# This file is part of OpenAndroidInstaller.
4+
# OpenAndroidInstaller is free software: you can redistribute it and/or modify it under the terms of
5+
# the GNU General Public License as published by the Free Software Foundation,
6+
# either version 3 of the License, or (at your option) any later version.
7+
8+
# OpenAndroidInstaller is distributed in the hope that it will be useful, but WITHOUT ANY
9+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11+
12+
# You should have received a copy of the GNU General Public License along with OpenAndroidInstaller.
13+
# If not, see <https://www.gnu.org/licenses/>."""
14+
# Author: Tobias Sterbak
15+
16+
from pathlib import Path
17+
from subprocess import CalledProcessError
18+
19+
from openandroidinstaller.tool_utils import search_device
20+
21+
22+
def test_search_device_success(mocker):
23+
"""Test if search works fine."""
24+
mocker.patch(
25+
"openandroidinstaller.tool_utils.check_output",
26+
return_value=b"[ro.product.device]: [sargo]",
27+
)
28+
29+
# test linux
30+
device_code = search_device(
31+
platform="linux", bin_path=Path("openandroidinstaller/bin/")
32+
)
33+
34+
assert device_code == "sargo"
35+
36+
# test windows
37+
device_code = search_device(
38+
platform="windows", bin_path=Path("openandroidinstaller/bin/")
39+
)
40+
41+
assert device_code == "sargo"
42+
43+
44+
def test_search_device_failure(mocker):
45+
"""Test if search failure is escalated properly."""
46+
47+
def patched_check_output(*args, **kwargs):
48+
raise CalledProcessError(returncode=1, cmd="search device failed")
49+
50+
mocker.patch(
51+
"openandroidinstaller.tool_utils.check_output",
52+
patched_check_output,
53+
)
54+
55+
device_code = search_device(
56+
platform="linux", bin_path=Path("openandroidinstaller/bin/")
57+
)
58+
59+
assert device_code == None

0 commit comments

Comments
 (0)