improve test code coverage of adb_shell command
@@ -7,6 +7,8 @@ __author__ = 'Grzegorz Latuszek'
__copyright__ = 'Copyright (C) 2020, Nokia'
__email__ = 'grzegorz.latuszek@nokia.com'
+import pytest
+
def test_calling_adb_shell_returns_expected_result(buffer_connection):
from moler.cmd.adb import adb_shell
@@ -24,3 +26,16 @@ def test_calling_adb_shell_with_serial_number_returns_expected_result(buffer_con
buffer_connection.remote_inject_response([adb_shell.COMMAND_OUTPUT_selected_device])
result = cmd_adb_shell()
assert result == adb_shell.COMMAND_RESULT_selected_device
+
+
+@pytest.mark.parametrize('cause', ['command not found', 'No such file or directory'])
+def test_calling_adb_shell_raises_CommandFailure_with_error_msg_from_cause(buffer_connection,
+ cause):
+ from moler.exceptions import CommandFailure
+ from moler.cmd.adb import adb_shell
+ buffer_connection.remote_inject_response(["adb shell\n{}\nxyz@debian ~$ ".format(cause)])
+ cmd_adb_shell = adb_shell.AdbShell(connection=buffer_connection.moler_connection,
+ expected_prompt= r'shell@adbhost:/ \$')
+ with pytest.raises(CommandFailure) as error:
+ cmd_adb_shell()
+ assert "failed with >>Found error regex in line '{}'<<".format(cause) in str(error.value)
