本文整理汇总了Python中fudge.Fake.expects方法的典型用法代码示例。如果您正苦于以下问题:Python Fake.expects方法的具体用法?Python Fake.expects怎么用?Python Fake.expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fudge.Fake
的用法示例。
在下文中一共展示了Fake.expects方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_settings_read_attribute_as_int
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
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
示例2: test_task_will_invoke_provided_class
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
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()
示例3: test_settings_read_attribute_with_no_section_returns_none
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
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")
示例4: test_task_passes_args_to_the_task_class
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
def test_task_passes_args_to_the_task_class():
random_vars = ("some text", random.randint(100, 200))
def foo(): pass
fake = Fake()
fake.expects("__init__").with_args(foo, *random_vars)
fudge.clear_calls()
fudge.clear_expectations()
foo = decorators.task(foo, task_class=fake, *random_vars)
fudge.verify()
示例5: test_settings_read_attribute_as_bool
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
def test_settings_read_attribute_as_bool():
clear_expectations()
fake_config = Fake("config")
fake_config.expects("get").with_args("name", "setting_true_1").returns("True")
fake_config.next_call("get").with_args("name", "setting_true_2").returns("true")
fake_config.next_call("get").with_args("name", "setting_false_1").returns("False")
fake_config.next_call("get").with_args("name", "setting_false_2").returns("false")
ss = SettingsSection(None, "name", fake_config)
assert ss.as_bool("setting_true_1")
assert ss.as_bool("setting_true_2")
assert not ss.as_bool("setting_false_1")
assert not ss.as_bool("setting_false_2")
示例6: test_healthcheck_action_returns_working_if_no_text_in_config
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
def test_healthcheck_action_returns_working_if_no_text_in_config():
clear_expectations()
clear()
settings_health_check.Ion = Fake('Ion')
settings_health_check.Ion.healthcheck_text = None
fake_server_health_check = Fake('server')
fake_server_health_check.expects('test_connection').returns(True)
controller = Controller()
controller.server = fake_server_health_check
assert controller.healthcheck() == "WORKING"
示例7: test_healthcheck_action
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
def test_healthcheck_action():
clear_expectations()
clear()
settings_health_check.Ion = Fake('Ion')
settings_health_check.Ion.healthcheck_text = "CUSTOMTEXT"
fake_server_health_check = Fake('server')
fake_server_health_check.expects('test_connection').returns(True)
controller = Controller()
controller.server = fake_server_health_check
assert controller.healthcheck() == "CUSTOMTEXT"
示例8: test_chained_fakes_honor_order
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
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()
示例9: test_healthcheck_action_fails_if_database_not_found
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
def test_healthcheck_action_fails_if_database_not_found():
clear_expectations()
clear()
settings_health_check.Ion = Fake('Ion')
settings_health_check.Ion.healthcheck_text = None
fake_server_health_check = Fake('server')
controller = Controller()
controller.server = fake_server_health_check
fake_server_health_check.expects('test_connection').returns(False)
fake_server_health_check.test_connection_error = ValueError('Fake error')
try:
controller.healthcheck()
except RuntimeError, err:
assert str(err) == "The connection to the database failed with error: Fake error"
return
示例10: test_route_decorator_registers_route_with_custom_name
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
def test_route_decorator_registers_route_with_custom_name():
clear_expectations()
clear()
class TestController(Controller):
@route("/something", name="named_route")
def SomeAction(self):
pass
assert TestController.__routes__
assert TestController.__routes__[0][0] == 'named_route'
assert TestController.__routes__[0][1]['route'] == '/something'
assert TestController.__routes__[0][1]['method'] == 'SomeAction'
dispatcher = Fake("dispatcher")
dispatcher.expects("connect").with_args("test_SomeAction", "/something", controller=arg.any_value(), action="SomeAction")
@with_fakes
def test_register_routes():
clear_expectations()
clear()
class TestController(Controller):
@route("/something")
def SomeAction(self):
pass
ctrl = TestController()
ctrl.register_routes(dispatcher)
template_context = Fake('context').has_attr(settings=Fake('settings'))
示例11: test_disconnecting_from_not_connected_raises
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import expects [as 别名]
@with_patched_object(Db, "connstr", fake_conn_str)
def test_disconnecting_from_not_connected_raises():
clear_expectations()
db = Db(connection_context)
try:
db.disconnect()
except RuntimeError, err:
assert str(err) == "You have to connect before disconnecting"
return
assert False, "Should not have gotten this far"
closable_session = Fake('closable_session')
closable_session.expects('close')
@with_fakes
@with_patched_object(db, "create_engine", fake_create_engine)
@with_patched_object(db, "session", closable_session)
@with_patched_object(Db, "connstr", fake_conn_str)
def test_disconnection_calls_close():
clear_expectations()
db = Db(connection_context)
db.connect()
db.disconnect()
assert not db.is_connected
@with_fakes