本文整理汇总了Python中fudge.Fake.SSHException方法的典型用法代码示例。如果您正苦于以下问题:Python Fake.SSHException方法的具体用法?Python Fake.SSHException怎么用?Python Fake.SSHException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fudge.Fake
的用法示例。
在下文中一共展示了Fake.SSHException方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connect_does_not_prompt_password_when_ssh_raises_channel_exception
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import SSHException [as 别名]
def test_connect_does_not_prompt_password_when_ssh_raises_channel_exception(self):
def raise_channel_exception_once(*args, **kwargs):
if raise_channel_exception_once.should_raise_channel_exception:
raise_channel_exception_once.should_raise_channel_exception = False
raise ssh.ChannelException(2, 'Connect failed')
raise_channel_exception_once.should_raise_channel_exception = True
def generate_fake_client():
fake_client = Fake('SSHClient', allows_any_call=True, expect_call=True)
fake_client.provides('connect').calls(raise_channel_exception_once)
return fake_client
fake_ssh = Fake('ssh', allows_any_call=True)
fake_ssh.provides('SSHClient').calls(generate_fake_client)
# We need the real exceptions here to preserve the inheritence structure
fake_ssh.SSHException = ssh.SSHException
fake_ssh.ChannelException = ssh.ChannelException
patched_connect = patch_object('fabric.network', 'ssh', fake_ssh)
patched_password = patch_object('fabric.network', 'prompt_for_password', Fake('prompt_for_password', callable = True).times_called(0))
try:
connect('user', 'localhost', 22, HostConnectionCache())
finally:
# Restore ssh
patched_connect.restore()
patched_password.restore()