def test_cmp(self):
        def cb1(arg):
            pass

        def cb2(arg):
            pass

        p1 = weakmethod.WeakMethodProxy(self.c.method)
        p2 = weakmethod.WeakMethodProxy(self.c.method)
        self.assertNotEqual(id(p1), id(p2))
        self.assertEqual(p1, p2)
        del self.c

        def cmp(a, b):
            return a == b

        self.assertRaises(ReferenceError, cmp, p1, p2)
 def test_func(self):
     c = TestClass()
     o = c.method
     p1 = weakref.proxy(o)
     p2 = weakmethod.proxy(o)
     self.assertNotEqual(p1, p2)
     p3 = weakmethod.WeakMethodProxy(o)
     self.assertNotEqual(p1, p3)
 def test_repr(self):
     r = weakmethod.WeakMethodProxy(self.c.method)
     inner = repr(self.c.method)
     outer = repr(r)
     self.assertTrue(inner in outer)
     del self.c
     outer = repr(r)
     self.assertFalse(inner in outer)
     self.assertTrue("None" in outer)
    def test_fallback(self):
        def fb(*arg):
            return arg + arg

        r = weakmethod.WeakMethodProxy(self.c.method, fallback=fb)
        result = r(1, 2, 3)
        self.assertEqual(result, (1, 2, 3))
        del self.c
        result = r(1, 2, 3)
        self.assertEqual(result, (1, 2, 3) * 2)
    def test_strong_callback(self):
        foo = [None]

        def cb(arg):
            foo[0] = arg

        r = weakmethod.WeakMethodProxy(self.c.method, callback=cb)
        result = r(1, 2, 3)
        self.assertEqual(result, (1, 2, 3))
        self.assertEqual(foo[0], None)
        del self.c
        self.assertRaises(ReferenceError, r)
        self.assertEqual(id(foo[0]), id(r))
 def test_hash(self):
     r = weakmethod.WeakMethodProxy(self.c.method)
     self.assertRaises(TypeError, hash, r)
     del self.c
     self.assertRaises(TypeError, hash, r)
 def test_strong(self):
     r = weakmethod.WeakMethodProxy(self.c.method)
     result = r(1, 2, 3)
     self.assertEqual(result, (1, 2, 3))
     del self.c
     self.assertRaises(ReferenceError, r)
 def test_weak(self):
     r = weakmethod.WeakMethodProxy(TestClass().method)
     self.assertRaises(ReferenceError, r)
 def test_create(self):
     r = weakmethod.WeakMethodProxy(self.c.method)