本文整理汇总了Python中fudge.Fake.provides方法的典型用法代码示例。如果您正苦于以下问题:Python Fake.provides方法的具体用法?Python Fake.provides怎么用?Python Fake.provides使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fudge.Fake
的用法示例。
在下文中一共展示了Fake.provides方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connect_does_not_prompt_password_when_ssh_raises_channel_exception
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import provides [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()
示例2: test_wrapped_column_has_sort_url
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import provides [as 别名]
def test_wrapped_column_has_sort_url():
meta = Fake().has_attr(order_by="nu")
table = Fake().has_attr(_meta=meta)
column_a = Fake().has_attr(name="nu")
column_b = Fake().has_attr(name="xi")
# mock out url building, to avoid awakening django.
table.provides("get_url").calls(lambda order_by: ["omicron", order_by])
wrapped_column_a = WrappedColumn(table, column_a)
wrapped_column_b = WrappedColumn(table, column_b)
assert wrapped_column_a.sort_url == ["omicron", "-nu"]
assert wrapped_column_b.sort_url == ["omicron", "xi"]
示例3: generate_fake_client
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import provides [as 别名]
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