test_sshclient.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:os-xenapi 作者: openstack 项目源码 文件源码
def test_ssh(self, mock_exec, mock_conn, mock_set):
        mock_log = mock.Mock()
        mock_channel = mock.Mock()
        mock_exec.return_value = (fake_channel_file(['input']),
                                  fake_channel_file(['out_line1',
                                                     'out_line2'],
                                                    mock_channel),
                                  fake_channel_file(['err_line1',
                                                     'err_line2']))
        mock_channel.recv_exit_status.return_value = 0

        client = sshclient.SSHClient('ip', 'username', password='password',
                                     log=mock_log)
        out, err = client.ssh('fake_command', output=True)

        mock_log.debug.assert_called()
        mock_exec.assert_called()
        mock_log.info.assert_called_with('out_line1\nout_line2')
        mock_log.error.assert_called_with('err_line1\nerr_line2')
        mock_channel.recv_exit_status.assert_called_with()
        self.assertEqual(out, 'out_line1\nout_line2')
        self.assertEqual(err, 'err_line1\nerr_line2')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号