def test_args_parsing_into_scope(self): space = DummySpace() args = Arguments(space, []) calls = [] def _match_signature(w_firstarg, scope_w, signature, defaults_w=[], blindargs=0): calls.append((w_firstarg, scope_w, signature.argnames, signature.has_vararg(), signature.has_kwarg(), defaults_w, blindargs)) args._match_signature = _match_signature scope_w = [None, None] args.parse_into_scope(None, scope_w, "foo", Signature(["a", "b"], None, None)) assert len(calls) == 1 assert calls[0] == (None, scope_w, ["a", "b"], False, False, [], 0) assert calls[0][1] is scope_w calls = [] scope_w = [None, None, None, None] args.parse_into_scope(None, scope_w, "foo", Signature(["a", "b"], "args", "kw"), defaults_w=['x', 'y']) assert len(calls) == 1 assert calls[0] == (None, scope_w, ["a", "b"], True, True, ["x", "y"], 0) calls = [] scope_w = [None, None, None, None] args.parse_into_scope("obj", scope_w, "foo", Signature(["a", "b"], "args", "kw"), defaults_w=['x', 'y']) assert len(calls) == 1 assert calls[0] == ("obj", scope_w, ["a", "b"], True, True, ["x", "y"], 0) class FakeArgErr(ArgErr): def getmsg(self, fname): return "msg " + fname def _match_signature(*args): raise FakeArgErr() args._match_signature = _match_signature excinfo = py.test.raises(OperationError, args.parse_into_scope, "obj", [None, None], "foo", Signature(["a", "b"], None, None)) assert excinfo.value.w_type is TypeError assert excinfo.value._w_value == "msg foo"