Beispiel #1
0
    def test_method_get(self):
        space = self.space

        # Create some function for this test only
        def m(self):
            return self

        func = Function(space, PyCode._from_code(self.space, m.func_code),
                        space.newdict())
        # Some shorthands
        obj1 = space.wrap(23)
        obj2 = space.wrap(42)
        args = Arguments(space, [])
        # Check method returned from func.__get__()
        w_meth1 = descr_function_get(space, func, obj1, space.type(obj1))
        meth1 = space.unwrap(w_meth1)
        assert isinstance(meth1, Method)
        assert meth1.call_args(args) == obj1
        # Check method returned from method.__get__()
        # --- meth1 is already bound so meth1.__get__(*) is meth1.
        w_meth2 = meth1.descr_method_get(obj2, space.type(obj2))
        meth2 = space.unwrap(w_meth2)
        assert isinstance(meth2, Method)
        assert meth2.call_args(args) == obj1
        # Check method returned from unbound_method.__get__()
        w_meth3 = descr_function_get(space, func, None, space.type(obj2))
        meth3 = space.unwrap(w_meth3)
        w_meth4 = meth3.descr_method_get(obj2, space.w_None)
        meth4 = space.unwrap(w_meth4)
        assert isinstance(meth4, Method)
        assert meth4.call_args(args) == obj2
        # Check method returned from unbound_method.__get__()
        # --- with an incompatible class
        w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_str)
        assert space.is_w(w_meth5, w_meth3)
 def test_method_get(self):
     space = self.space
     # Create some function for this test only
     def m(self): return self
     func = Function(space, PyCode._from_code(self.space, m.func_code),
                     space.newdict())
     # Some shorthands
     obj1 = space.wrap(23)
     obj2 = space.wrap(42)
     args = Arguments(space, [])
     # Check method returned from func.__get__()
     w_meth1 = descr_function_get(space, func, obj1, space.type(obj1))
     meth1 = space.unwrap(w_meth1)
     assert isinstance(meth1, Method)
     assert meth1.call_args(args) == obj1
     # Check method returned from method.__get__()
     # --- meth1 is already bound so meth1.__get__(*) is meth1.
     w_meth2 = meth1.descr_method_get(obj2, space.type(obj2))
     meth2 = space.unwrap(w_meth2)
     assert isinstance(meth2, Method)
     assert meth2.call_args(args) == obj1
     # Check method returned from unbound_method.__get__()
     w_meth3 = descr_function_get(space, func, None, space.type(obj2))
     meth3 = space.unwrap(w_meth3)
     w_meth4 = meth3.descr_method_get(obj2, space.w_None)
     meth4 = space.unwrap(w_meth4)
     assert isinstance(meth4, Method)
     assert meth4.call_args(args) == obj2
     # Check method returned from unbound_method.__get__()
     # --- with an incompatible class
     w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_str)
     assert space.is_w(w_meth5, w_meth3)
Beispiel #3
0
 def test_fail_call(self):
     space = self.space
     w_meth = descr_function_get(space, self.fn, space.wrap(5),
                                 space.type(space.wrap(5)))
     meth = space.unwrap(w_meth)
     args = Arguments(space, [space.wrap("spam"), space.wrap("egg")])
     self.space.raises_w(self.space.w_TypeError, meth.call_args, args)
Beispiel #4
0
 def test_call(self):
     space = self.space
     w_meth = descr_function_get(space, self.fn, space.wrap(5),
                                 space.type(space.wrap(5)))
     meth = space.unwrap(w_meth)
     w_result = meth.call_args(Arguments(space, [space.wrap(42)]))
     assert space.unwrap(w_result) == 42
    def test_method_get(self):
        space = self.space

        # Create some function for this test only
        def m(self):
            return self

        func = Function(space, PyCode._from_code(self.space, m.func_code),
                        space.newdict())
        # Some shorthands
        obj1 = space.wrap(23)
        obj2 = space.wrap(42)
        args = Arguments(space, [])
        # Check method returned from func.__get__()
        w_meth1 = descr_function_get(space, func, obj1, space.type(obj1))
        meth1 = space.unwrap(w_meth1)
        assert isinstance(meth1, Method)
        assert meth1.call_args(args) == obj1
        # Check method returned from method.__get__()
        # --- meth1 is already bound so meth1.__get__(*) is meth1.
        w_meth2 = meth1.descr_method_get(obj2, space.type(obj2))
        meth2 = space.unwrap(w_meth2)
        assert isinstance(meth2, Method)
        assert meth2.call_args(args) == obj1
        # Check method returned from unbound_method.__get__()
        w_meth3 = descr_function_get(space, func, space.w_None,
                                     space.type(obj2))
        meth3 = space.unwrap(w_meth3)
        w_meth4 = meth3.descr_method_get(obj2, space.w_None)
        meth4 = space.unwrap(w_meth4)
        assert isinstance(meth4, Method)
        assert meth4.call_args(args) == obj2
        # Check method returned from unbound_method.__get__()
        # --- with an incompatible class
        w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_text)
        assert space.is_w(w_meth5, w_meth3)
        # Same thing, with an old-style class
        w_oldclass = space.call_function(space.builtin.get('__metaclass__'),
                                         space.wrap('OldClass'),
                                         space.newtuple([]), space.newdict())
        w_meth6 = meth3.descr_method_get(space.wrap('hello'), w_oldclass)
        assert space.is_w(w_meth6, w_meth3)
        # Reverse order of old/new styles
        w_meth7 = descr_function_get(space, func, space.w_None, w_oldclass)
        meth7 = space.unwrap(w_meth7)
        w_meth8 = meth7.descr_method_get(space.wrap('hello'), space.w_text)
        assert space.is_w(w_meth8, w_meth7)
Beispiel #6
0
 def test_method_get(self):
     space = self.space
     # Create some function for this test only
     def m(self): return self
     func = Function(space, PyCode._from_code(self.space, m.func_code),
                     space.newdict())
     # Some shorthands
     obj1 = space.wrap(23)
     obj2 = space.wrap(42)
     args = Arguments(space, [])
     # Check method returned from func.__get__()
     w_meth1 = descr_function_get(space, func, obj1, space.type(obj1))
     meth1 = space.unwrap(w_meth1)
     assert isinstance(meth1, Method)
     assert meth1.call_args(args) == obj1
     # Check method returned from method.__get__()
     # --- meth1 is already bound so meth1.__get__(*) is meth1.
     w_meth2 = meth1.descr_method_get(obj2, space.type(obj2))
     meth2 = space.unwrap(w_meth2)
     assert isinstance(meth2, Method)
     assert meth2.call_args(args) == obj1
     # Check method returned from unbound_method.__get__()
     w_meth3 = descr_function_get(space, func, space.w_None, space.type(obj2))
     meth3 = space.unwrap(w_meth3)
     w_meth4 = meth3.descr_method_get(obj2, space.w_None)
     meth4 = space.unwrap(w_meth4)
     assert isinstance(meth4, Method)
     assert meth4.call_args(args) == obj2
     # Check method returned from unbound_method.__get__()
     # --- with an incompatible class
     w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_str)
     assert space.is_w(w_meth5, w_meth3)
     # Same thing, with an old-style class
     w_oldclass = space.call_function(
         space.builtin.get('__metaclass__'),
         space.wrap('OldClass'), space.newtuple([]), space.newdict())
     w_meth6 = meth3.descr_method_get(space.wrap('hello'), w_oldclass)
     assert space.is_w(w_meth6, w_meth3)
     # Reverse order of old/new styles
     w_meth7 = descr_function_get(space, func, space.w_None, w_oldclass)
     meth7 = space.unwrap(w_meth7)
     w_meth8 = meth7.descr_method_get(space.wrap('hello'), space.w_str)
     assert space.is_w(w_meth8, w_meth7)
Beispiel #7
0
 def test_method_get(self):
     space = self.space
     # Create some function for this test only
     func = self.compile("def m(self): return self")
     # Some shorthands
     obj1 = space.wrap(23)
     obj2 = space.wrap(42)
     args = Arguments(space, [])
     # Check method returned from func.__get__()
     w_meth1 = descr_function_get(space, func, obj1, space.type(obj1))
     meth1 = space.unwrap(w_meth1)
     assert isinstance(meth1, Method)
     assert meth1.call_args(args) == obj1
     # Check method returned from method.__get__()
     # --- meth1 is already bound so meth1.__get__(*) is meth1.
     w_meth2 = meth1.descr_method_get(obj2, space.type(obj2))
     meth2 = space.unwrap(w_meth2)
     assert isinstance(meth2, Method)
     assert meth2.call_args(args) == obj1
     # Check method returned from unbound_method.__get__()
     w_meth3 = descr_function_get(space, func, space.w_None,
                                  space.type(obj2))
     meth3 = space.unwrap(w_meth3)
     assert meth3 is func
Beispiel #8
0
 def _c_call_return_trace(self, frame, w_func, args, event):
     if self.profilefunc is None:
         frame.getorcreatedebug().is_being_profiled = False
     else:
         # undo the effect of the CALL_METHOD bytecode, which would be
         # that even on a built-in method call like '[].append()',
         # w_func is actually the unbound function 'append'.
         from pypy.interpreter.function import FunctionWithFixedCode
         if isinstance(w_func, FunctionWithFixedCode) and args is not None:
             w_firstarg = args.firstarg()
             if w_firstarg is not None:
                 from pypy.interpreter.function import descr_function_get
                 w_func = descr_function_get(self.space, w_func, w_firstarg,
                                             self.space.type(w_firstarg))
         #
         self._trace(frame, event, w_func)
Beispiel #9
0
 def test_get(self):
     space = self.space
     w_meth = descr_function_get(space, self.fn, space.wrap(5),
                                 space.type(space.wrap(5)))
     meth = space.unwrap(w_meth)
     assert isinstance(meth, Method)
 def test_fail_call(self):
     space = self.space
     w_meth = descr_function_get(space, self.fn, space.wrap(5), space.type(space.wrap(5)))
     meth = space.unwrap(w_meth)
     args = Arguments(space, [space.wrap("spam"), space.wrap("egg")])
     self.space.raises_w(self.space.w_TypeError, meth.call_args, args)
 def test_call(self):
     space = self.space
     w_meth = descr_function_get(space, self.fn, space.wrap(5), space.type(space.wrap(5)))
     meth = space.unwrap(w_meth)
     w_result = meth.call_args(Arguments(space, [space.wrap(42)]))
     assert space.unwrap(w_result) == 42
 def test_get(self):
     space = self.space
     w_meth = descr_function_get(space, self.fn, space.wrap(5), space.type(space.wrap(5)))
     meth = space.unwrap(w_meth)
     assert isinstance(meth, Method)