test_util_ssh.py 文件源码

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

项目:commissaire 作者: projectatomic 项目源码 文件源码
def test_temporarysshkey_remove_failure(self):
        """
        Verify TemporarySSHKey.remove reacts properly to failure.
        """
        mock_logger = mock.MagicMock(logging.Logger('test'))
        key = TemporarySSHKey(TEST_HOST_CREDS, mock_logger)
        key.create()
        with mock.patch('os.unlink') as _unlink:
            _unlink.side_effect = Exception
            self.assertTrue(os.path.isfile(key.path))
            key.remove()
            self.assertTrue(os.path.isfile(key.path))
            # We should have a warning in the log
            mock_logger.warn.assert_called_once_with(
                mock.ANY, mock.ANY, mock.ANY)
        # Clean up the file
        key.remove()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号