示例#1
0
文件: adb_test.py 项目: yxususe/mobly
    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'))
示例#2
0
文件: adb_test.py 项目: yxususe/mobly
 def test_construct_adb_cmd(self):
     adb_cmd = adb.AdbProxy()._construct_adb_cmd('shell',
                                                 'arg1',
                                                 shell=False)
     self.assertEqual(adb_cmd, ['adb', 'shell', 'arg1'])
示例#3
0
 def test_forward(self):
     with mock.patch.object(adb.AdbProxy, '_exec_cmd') as mock_exec_cmd:
         adb.AdbProxy().forward(MOCK_SHELL_COMMAND)
示例#4
0
 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))
示例#5
0
 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)
示例#6
0
 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')
示例#7
0
 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 ')
示例#8
0
文件: adb_test.py 项目: yxususe/mobly
 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'])
示例#9
0
    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'))
示例#10
0
 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)
示例#11
0
 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)
示例#12
0
 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))
示例#13
0
 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)
示例#14
0
文件: adb_test.py 项目: yxususe/mobly
 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'])
示例#15
0
 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\'')
示例#16
0
文件: adb_test.py 项目: yxususe/mobly
 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"', "\/\/"])
示例#17
0
 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"\' \'\\/\\/\'')
示例#18
0
文件: adb_test.py 项目: yxususe/mobly
 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')
示例#19
0
 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)