|
| 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