From e31211c578854d63128a30c036e40eee5c43edc7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 29 Oct 2015 14:25:58 -0400 Subject: - convert wrap_callable() to a general purpose update_wrapper-like function; the caller still passes in the "wrapper" - move tests for wrap_callable() to be generic util tests - changelog for pullreq github:204 --- test/base/test_utils.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'test/base/test_utils.py') diff --git a/test/base/test_utils.py b/test/base/test_utils.py index 8074de53e..c1027ec8e 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -313,6 +313,75 @@ class MemoizedAttrTest(fixtures.TestBase): eq_(canary.mock_calls, [mock.call.attr(), mock.call.method()]) +class WrapCallableTest(fixtures.TestBase): + def test_wrapping_update_wrapper_fn(self): + def my_fancy_default(): + """run the fancy default""" + return 10 + + c = util.wrap_callable(lambda: my_fancy_default, my_fancy_default) + + eq_(c.__name__, "my_fancy_default") + eq_(c.__doc__, "run the fancy default") + + def test_wrapping_update_wrapper_fn_nodocstring(self): + def my_fancy_default(): + return 10 + + c = util.wrap_callable(lambda: my_fancy_default, my_fancy_default) + eq_(c.__name__, "my_fancy_default") + eq_(c.__doc__, None) + + def test_wrapping_update_wrapper_cls(self): + class MyFancyDefault(object): + """a fancy default""" + + def __call__(self): + """run the fancy default""" + return 10 + + def_ = MyFancyDefault() + c = util.wrap_callable(lambda: def_(), def_) + + eq_(c.__name__, "MyFancyDefault") + eq_(c.__doc__, "run the fancy default") + + def test_wrapping_update_wrapper_cls_noclsdocstring(self): + class MyFancyDefault(object): + + def __call__(self): + """run the fancy default""" + return 10 + + def_ = MyFancyDefault() + c = util.wrap_callable(lambda: def_(), def_) + eq_(c.__name__, "MyFancyDefault") + eq_(c.__doc__, "run the fancy default") + + def test_wrapping_update_wrapper_cls_nomethdocstring(self): + class MyFancyDefault(object): + """a fancy default""" + + def __call__(self): + return 10 + + def_ = MyFancyDefault() + c = util.wrap_callable(lambda: def_(), def_) + eq_(c.__name__, "MyFancyDefault") + eq_(c.__doc__, "a fancy default") + + def test_wrapping_update_wrapper_cls_noclsdocstring_nomethdocstring(self): + class MyFancyDefault(object): + + def __call__(self): + return 10 + + def_ = MyFancyDefault() + c = util.wrap_callable(lambda: def_(), def_) + eq_(c.__name__, "MyFancyDefault") + eq_(c.__doc__, None) + + class ToListTest(fixtures.TestBase): def test_from_string(self): eq_( -- cgit v1.2.1