def test_execute_and_process_stdout_returns_stderr(self, mock_popen): self._mock_execute_and_process_stdout_process(mock_popen) err = adb.AdbProxy()._execute_and_process_stdout( ['fake_cmd'], shell=False, handler=mock.MagicMock()) self.assertEqual(MOCK_DEFAULT_STDERR, err.decode('utf-8'))
def test_construct_adb_cmd(self): adb_cmd = adb.AdbProxy()._construct_adb_cmd('shell', 'arg1', shell=False) self.assertEqual(adb_cmd, ['adb', 'shell', 'arg1'])
def test_forward(self): with mock.patch.object(adb.AdbProxy, '_exec_cmd') as mock_exec_cmd: adb.AdbProxy().forward(MOCK_SHELL_COMMAND)
def test_has_shell_command_with_existing_command(self): with mock.patch.object(adb.AdbProxy, '_exec_cmd') as mock_exec_cmd: mock_exec_cmd.return_value = MOCK_COMMAND_OUTPUT self.assertTrue( adb.AdbProxy().has_shell_command(MOCK_SHELL_COMMAND))
def test_exec_cmd_with_negative_timeout_value(self): with self.assertRaisesRegex(ValueError, 'Timeout is not a positive value: -1'): adb.AdbProxy()._exec_cmd( ['fake_cmd'], shell=False, timeout=-1, stderr=None)
def test_construct_adb_cmd_with_shell_true_with_serial_with_list(self): adb_cmd = adb.AdbProxy('12345')._construct_adb_cmd('shell', ['arg1', 'arg2'], shell=True) self.assertEqual(adb_cmd, '"adb" -s "12345" shell arg1 arg2')
def test_construct_adb_cmd_with_shell_true_with_one_command(self): adb_cmd = adb.AdbProxy()._construct_adb_cmd( 'shell ls /asdafsfd/asdf-asfd/asa', [], shell=True) self.assertEqual(adb_cmd, '"adb" shell ls /asdafsfd/asdf-asfd/asa ')
def test_construct_adb_cmd_with_serial_with_list(self): adb_cmd = adb.AdbProxy('12345')._construct_adb_cmd('shell', ['arg1', 'arg2'], shell=False) self.assertEqual(adb_cmd, ['adb', '-s', '12345', 'shell', 'arg1', 'arg2'])
def test_exec_cmd_with_timeout_success(self, mock_psutil_process, mock_popen): self._mock_process(mock_psutil_process, mock_popen) reply = adb.AdbProxy()._exec_cmd(['fake_cmd'], shell=False, timeout=1) self.assertEqual('out', reply.decode('utf-8'))
def test_exec_cmd_timed_out_without_serial(self, mock_run_command): mock_run_command.side_effect = adb.psutil.TimeoutExpired('Timed out') with self.assertRaisesRegex( adb.AdbTimeoutError, 'Timed out executing command "adb ' 'fake-cmd" after 0.01s.') as context: adb.AdbProxy().fake_cmd(timeout=0.01)
def test_exec_cmd_with_negative_timeout_value(self, mock_psutil_process, mock_popen): self._mock_process(mock_psutil_process, mock_popen) with self.assertRaisesRegex(adb.Error, 'Timeout is not a positive value: -1'): adb.AdbProxy()._exec_cmd(['fake_cmd'], shell=False, timeout=-1)
def test_has_shell_command_with_missing_command_on_newer_devices(self): with mock.patch.object(adb.AdbProxy, '_exec_cmd') as mock_exec_cmd: mock_exec_cmd.return_value = MOCK_DEFAULT_COMMAND_OUTPUT mock_exec_cmd.side_effect = adb.AdbError(MOCK_ADB_SHELL_COMMAND_CHECK, '', '', 1) self.assertFalse(adb.AdbProxy().has_shell_command(MOCK_SHELL_COMMAND))
def test_exec_adb_cmd_with_shell_true(self): with mock.patch.object(adb.AdbProxy, '_exec_cmd') as mock_exec_cmd: mock_exec_cmd.return_value = MOCK_DEFAULT_COMMAND_OUTPUT adb.AdbProxy().shell('arg1 arg2', shell=True) mock_exec_cmd.assert_called_once_with( '"adb" shell arg1 arg2', shell=True, timeout=None, stderr=None)
def test_construct_adb_cmd_with_one_arg_command_list(self): adb_cmd = adb.AdbProxy()._construct_adb_cmd( 'shell', ['ls /asdafsfd/asdf-asfd/asa'], shell=False) self.assertEqual(adb_cmd, ['adb', 'shell', 'ls /asdafsfd/asdf-asfd/asa'])
def test_construct_adb_cmd_with_shell_true_with_one_arg_command_list(self): adb_cmd = adb.AdbProxy()._construct_adb_cmd( 'shell', ['ls /asdafsfd/asdf-asfd/asa'], shell=True) self.assertEqual(adb_cmd, '"adb" shell \'ls /asdafsfd/asdf-asfd/asa\'')
def test_construct_adb_cmd_with_special_characters(self): adb_cmd = adb.AdbProxy()._construct_adb_cmd('shell', ['a b', '"blah"', '\/\/'], shell=False) self.assertEqual(adb_cmd, ['adb', 'shell', 'a b', '"blah"', "\/\/"])
def test_construct_adb_cmd_with_shell_true_with_auto_quotes(self): adb_cmd = adb.AdbProxy()._construct_adb_cmd('shell', ['a b', '"blah"', r'\/\/'], shell=True) self.assertEqual(adb_cmd, '"adb" shell \'a b\' \'"blah"\' \'\\/\\/\'')
def test_construct_adb_cmd_with_shell_true(self): adb_cmd = adb.AdbProxy()._construct_adb_cmd('shell', 'arg1 arg2', shell=True) self.assertEqual(adb_cmd, '"adb" shell arg1 arg2')
def test_exec_cmd_with_negative_timeout_value(self, mock_psutil_process, mock_popen): self._mock_process(mock_psutil_process, mock_popen) with self.assertRaisesRegex(adb.AdbError, "Timeout is a negative value: .*"): adb.AdbProxy()._exec_cmd(["fake_cmd"], shell=False, timeout=-1)