def test_bind_attributes_missing_raises(foo): obj = Mock() del obj.a with pytest.raises(TypeError): util.bind_attributes(foo, obj)
def test_bind_attributes(foo): obj = Mock() a = PropertyMock(return_value=1) type(obj).a = a b = PropertyMock(return_value=2) type(obj).b = b c = PropertyMock(return_value=3) type(obj).c = c args, kwargs = util.bind_attributes(foo, obj) foo(*args, **kwargs)
def test_bind_attributes_default_args(): def foo(a, b, c=42): assert a == 1 assert b == 2 assert c == 42 obj = Mock() a = PropertyMock(return_value=1) type(obj).a = a b = PropertyMock(return_value=2) type(obj).b = b del obj.c args, kwargs = util.bind_attributes(foo, obj) foo(*args, **kwargs)
def test_bind_attributes_exclude_first(foo): obj = Mock() del obj.a util.bind_attributes(foo, obj, exclude_first=True)
def test_bind_attributes_exclude(foo): obj = Mock() del obj.a del obj.c util.bind_attributes(foo, obj, exclude=['a', 'c'])