本文整理汇总了Python中fudge.Fake.next_call方法的典型用法代码示例。如果您正苦于以下问题:Python Fake.next_call方法的具体用法?Python Fake.next_call怎么用?Python Fake.next_call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fudge.Fake
的用法示例。
在下文中一共展示了Fake.next_call方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_settings_read_attribute_with_no_section_returns_none
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import next_call [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")
示例2: test_settings_read_attribute_as_bool
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import next_call [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")
示例3: password_response
# 需要导入模块: from fudge import Fake [as 别名]
# 或者: from fudge.Fake import next_call [as 别名]
def password_response(password, times_called=None, silent=True):
"""
Context manager which patches ``getpass.getpass`` to return ``password``.
``password`` may be a single string or an iterable of strings:
* If single string, given password is returned every time ``getpass`` is
called.
* If iterable, iterated over for each call to ``getpass``, after which
``getpass`` will error.
If ``times_called`` is given, it is used to add a ``Fake.times_called``
clause to the mock object, e.g. ``.times_called(1)``. Specifying
``times_called`` alongside an iterable ``password`` list is unsupported
(see Fudge docs on ``Fake.next_call``).
If ``silent`` is True, no prompt will be printed to ``sys.stderr``.
"""
fake = Fake('getpass', callable=True)
# Assume stringtype or iterable, turn into mutable iterable
if isinstance(password, StringTypes):
passwords = [password]
else:
passwords = list(password)
# Optional echoing of prompt to mimic real behavior of getpass
# NOTE: also echo a newline if the prompt isn't a "passthrough" from the
# server (as it means the server won't be sending its own newline for us).
echo = lambda x, y: y.write(x + ("\n" if x != " " else ""))
# Always return first (only?) password right away
fake = fake.returns(passwords.pop(0))
if not silent:
fake = fake.calls(echo)
# If we had >1, return those afterwards
for pw in passwords:
fake = fake.next_call().returns(pw)
if not silent:
fake = fake.calls(echo)
# Passthrough times_called
if times_called:
fake = fake.times_called(times_called)
return patched_context(getpass, 'getpass', fake)