Skip to content

Commit 33edbe4

Browse files
Increase test coverage
1 parent 3d66622 commit 33edbe4

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

adb/adb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ def connect(self, host: str = None, timeout: Optional[int] = None) -> str:
228228
output = self.execute(connect_cmd, timeout=timeout)
229229

230230
# Make sure the connect operation ended successfully.
231-
if output and 'unable to connect' in output.lower():
231+
if output and any(error in output.lower()
232+
for error in ['unable to connect', 'cannot connect', 'cannot resolve']):
232233
raise RuntimeError('Something went wrong during the connect operation: {0}'.format(output))
233234
else:
234235
return output
@@ -250,7 +251,7 @@ def remount(self, timeout: Optional[int] = None) -> str:
250251
else:
251252
raise RuntimeError('Something went wrong during the remount operation: {0}'.format(output))
252253

253-
def reboot(self, timeout: Optional[int] = None) -> None:
254+
def reboot(self, timeout: Optional[int] = None) -> str:
254255
"""
255256
Reboot the Android device connected through adb.
256257

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pytest-cov==2.6.1
1+
pytest-cov==2.8.1
2+
pytest-ordering==0.6

test/test_adb.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ def test_adb_device_connected(self, adb_instance: ADB):
5858
assert isinstance(connected_devices[0], str)
5959
assert connected_devices[0] is not ''
6060

61+
def test_adb_connection_error(self, adb_instance: ADB):
62+
with pytest.raises(RuntimeError):
63+
adb_instance.connect('unknown', timeout=30)
64+
65+
@pytest.mark.second_to_last
66+
def test_adb_remount_error(self, adb_instance: ADB):
67+
with pytest.raises(RuntimeError):
68+
# This should fail because "adb root" was not executed.
69+
adb_instance.remount(timeout=30)
70+
71+
@pytest.mark.last
72+
def test_adb_reboot(self, adb_instance: ADB):
73+
result = adb_instance.reboot(timeout=300)
74+
assert result == ''
75+
6176

6277
class TestCommandExecution(object):
6378

0 commit comments

Comments
 (0)