Beispiel #1
0
    def test_create_process(self, mock_get_current_gt, mock_tpool_proxy,
                            mock_popen):
        cmd = ['fake_cmd']

        popen_obj, ret_cmd = utils.create_process(
            cmd,
            run_as_root=mock.sentinel.run_as_root,
            addl_env={mock.sentinel.key1: mock.sentinel.val1},
            tpool_proxy=True)

        exp_env = {
            mock.sentinel.key0: mock.sentinel.val0,
            mock.sentinel.key1: mock.sentinel.val1
        }

        mock_popen.assert_called_once_with(cmd,
                                           shell=False,
                                           stdin=utils.subprocess.PIPE,
                                           stdout=utils.subprocess.PIPE,
                                           stderr=utils.subprocess.PIPE,
                                           env=exp_env,
                                           preexec_fn=None,
                                           close_fds=False)

        file_type = getattr(six.moves.builtins, 'file', io.IOBase)
        mock_tpool_proxy.assert_called_once_with(mock_popen.return_value,
                                                 autowrap=(file_type, ))

        self.assertEqual(mock_tpool_proxy.return_value, popen_obj)
        self.assertEqual(ret_cmd, cmd)
Beispiel #2
0
    def test_create_process(self, mock_get_current_gt,
                            mock_tpool_proxy, mock_popen):
        cmd = ['fake_cmd']

        popen_obj, ret_cmd = utils.create_process(
            cmd,
            run_as_root=mock.sentinel.run_as_root,
            addl_env={mock.sentinel.key1: mock.sentinel.val1},
            tpool_proxy=True)

        exp_env = {mock.sentinel.key0: mock.sentinel.val0,
                   mock.sentinel.key1: mock.sentinel.val1}

        mock_popen.assert_called_once_with(
            cmd,
            shell=False,
            stdin=utils.subprocess.PIPE,
            stdout=utils.subprocess.PIPE,
            stderr=utils.subprocess.PIPE,
            env=exp_env,
            preexec_fn=None,
            close_fds=False)

        file_type = getattr(six.moves.builtins, 'file', io.IOBase)
        mock_tpool_proxy.assert_called_once_with(
            mock_popen.return_value, autowrap=(file_type, ))

        self.assertEqual(mock_tpool_proxy.return_value, popen_obj)
        self.assertEqual(ret_cmd, cmd)