本文整理汇总了Python中fudge.Fake类的典型用法代码示例。如果您正苦于以下问题:Python Fake类的具体用法?Python Fake怎么用?Python Fake使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fake类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_has_attr_fail
def test_has_attr_fail(self):
class Config(object):
color = 'red'
widget = Fake("widget").expects("configure")\
.with_args(arg.has_attr(size=12))
widget.configure(Config())
示例2: test_expectations_with_multiple_return_values
def test_expectations_with_multiple_return_values(self):
db = Fake("db").expects("get_id").returns(1).expects("set_id").next_call(for_method="get_id").returns(2)
eq_(db.get_id(), 1)
eq_(db.set_id(), None)
eq_(db.get_id(), 2)
fudge.verify()
示例3: test_connect_does_not_prompt_password_when_ssh_raises_channel_exception
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()
示例4: test_has_attr_fail_wrong_value
def test_has_attr_fail_wrong_value(self):
class Config(object):
color = 'red'
widget = Fake("widget").expects("configure")\
.with_args(arg.has_attr(color="green"))
widget.configure(Config())
示例5: test_settings_read_attribute_as_int
def test_settings_read_attribute_as_int():
clear_expectations()
fake_config = Fake("config")
fake_config.expects("get").with_args("name", "setting").returns("10")
ss = SettingsSection(None, "name", fake_config)
assert ss.as_int("setting") == 10
示例6: test_chained_fakes_honor_order
def test_chained_fakes_honor_order(self):
Thing = Fake("thing").remember_order().expects("__init__")
holder = Thing.expects("get_holder").returns_fake()
holder = holder.expects("init")
thing = Thing()
holder = thing.get_holder()
# missing thing.init()
fudge.verify()
示例7: test_contains_list
def test_contains_list(self):
db = Fake("db").expects("execute_statements").with_args(
arg.contains("select * from foo"))
db.execute_statements([
"update foo",
"select * from foo",
"drop table foo"
])
fudge.verify()
示例8: test_too_many_calls
def test_too_many_calls(self):
db = Fake("db")\
.remember_order()\
.expects("get_id").returns(1)\
.expects("set_id")
eq_(db.get_id(), 1)
eq_(db.set_id(), None)
# extra :
eq_(db.get_id(), 1)
示例9: test_has_attr_ok
def test_has_attr_ok(self):
class Config(object):
size = 12
color = 'red'
weight = 'heavy'
widget = Fake("widget").expects("configure")\
.with_args(arg.has_attr(size=12,color='red'))
widget.configure(Config())
示例10: test_returns
def test_returns(self):
db = Fake("db")\
.provides("get_id").returns(1)\
.provides("set_id")\
.next_call(for_method="get_id").returns(2)
# print [c.return_val for c in db._declared_calls["get_id"]._calls]
eq_(db.get_id(), 1)
eq_(db.set_id(), None)
eq_(db.get_id(), 2)
示例11: test_settings_read_attribute_with_no_section_returns_none
def test_settings_read_attribute_with_no_section_returns_none():
clear_expectations()
fake_config = Fake("config")
fake_config.expects("get").with_args("name", "setting_true_1").raises(NoSectionError("name"))
fake_config.next_call("get").with_args("name", "setting_true_2").raises(NoOptionError("name", "setting_true_2"))
ss = SettingsSection(None, "name", fake_config)
assert not ss.as_bool("setting_true_1")
assert not ss.as_bool("setting_true_2")
示例12: test_repr_shortens_long_values
def test_repr_shortens_long_values(self):
fake = Fake("widget").provides("set_bits").with_args(
"12345678910111213141516171819202122232425262728293031"
)
try:
fake.set_bits()
except AssertionError, exc:
eq_(str(exc),
"fake:widget.set_bits('123456789101112131415161718192021222324252627...') "
"was called unexpectedly with args ()")
示例13: test_task_will_invoke_provided_class
def test_task_will_invoke_provided_class():
def foo(): pass
fake = Fake()
fake.expects("__init__").with_args(foo)
fudge.clear_calls()
fudge.clear_expectations()
foo = decorators.task(foo, task_class=fake)
fudge.verify()
示例14: test_multiple_returns_affect_order
def test_multiple_returns_affect_order(self):
db = Fake("db")\
.remember_order()\
.expects("get_id").returns(1)\
.expects("set_id")\
.next_call(for_method="get_id").returns(2)
eq_(db.get_id(), 1)
eq_(db.set_id(), None)
eq_(db.get_id(), 2)
fudge.verify()
示例15: test_controller_cache_is_server_cache
def test_controller_cache_is_server_cache():
clear_expectations()
clear()
fake_server = Fake('server')
fake_server.cache = "cache"
controller = Controller()
controller.server = fake_server
assert controller.cache == "cache"