#!/usr/bin/env python
"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/qp/lib/test/utest_delegation.py $
$Id: utest_delegation.py 28598 2006-08-16 19:16:51Z dbinger $
"""
from qp.lib.delegation import delegate, delegate_passing_self
from sancho.utest import UTest

class Test(UTest):

    def a(self):
        class A(object):
            def get_args1(self, *args, **kwargs):
                return (self, args, kwargs)
            def get_args2(self, *args, **kwargs):
                return (self, args, kwargs)
        class B(object):
            def __init__(self):
                self.c = A()
                self.d = A()
        delegate(B, 'c.get_args1')
        delegate_passing_self(B, 'd.get_args2')
        b = B()
        assert b.get_args1() == (b.c, (), {}), b.get_args1()
        assert b.get_args2() == (b.d, (b,), {})

if __name__ == '__main__':
    Test()
