本文整理汇总了Python中pypy.interpreter.argument.Arguments.parse_obj方法的典型用法代码示例。如果您正苦于以下问题:Python Arguments.parse_obj方法的具体用法?Python Arguments.parse_obj怎么用?Python Arguments.parse_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.interpreter.argument.Arguments
的用法示例。
在下文中一共展示了Arguments.parse_obj方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_args_parsing
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import parse_obj [as 别名]
def test_args_parsing(self):
space = DummySpace()
args = Arguments(space, [])
calls = []
def _match_signature(w_firstarg, scope_w, signature,
defaults_w=None, w_kw_defs=None, blindargs=0):
defaults_w = [] if defaults_w is None else defaults_w
calls.append((w_firstarg, scope_w, signature.argnames, signature.has_vararg(),
signature.has_kwarg(), defaults_w, w_kw_defs, blindargs))
args._match_signature = _match_signature
scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], None, None))
assert len(calls) == 1
assert calls[0] == (None, [None, None], ["a", "b"], False, False,
[], None, 0)
assert calls[0][1] is scope_w
calls = []
scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], "args", None),
blindargs=1)
assert len(calls) == 1
assert calls[0] == (None, [None, None, None], ["a", "b"], True, False,
[], None, 1)
calls = []
scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], "args", "kw"),
defaults_w=['x', 'y'])
assert len(calls) == 1
assert calls[0] == (None, [None, None, None, None], ["a", "b"],
True, True,
["x", "y"], None, 0)
calls = []
scope_w = args.parse_obj("obj", "foo", Signature(["a", "b"], "args", "kw"),
defaults_w=['x', 'y'], blindargs=1)
assert len(calls) == 1
assert calls[0] == ("obj", [None, None, None, None], ["a", "b"],
True, True,
["x", "y"], None, 1)
class FakeArgErr(ArgErr):
def getmsg(self):
return "msg"
def _match_signature(*args):
raise FakeArgErr()
args._match_signature = _match_signature
excinfo = py.test.raises(OperationError, args.parse_obj, "obj", "foo",
Signature(["a", "b"], None, None))
assert excinfo.value.w_type is TypeError
assert excinfo.value.get_w_value(space) == "foo() msg"