def test_builtin_update(self):
     # Test for bug #1576241
     def wrapper():
         pass
     functools.update_wrapper(wrapper, max)
     self.assertEqual(wrapper.__name__, 'max')
     self.assertTrue(wrapper.__doc__.startswith('max('))
Beispiel #2
0
    def test_builtin_update(self):
        # Test for bug #1576241
        def wrapper():
            pass

        functools.update_wrapper(wrapper, max)
        self.assertEqual(wrapper.__name__, 'max')
        self.assertTrue(wrapper.__doc__.startswith('max('))
    def __init__(self, func):
        self.func = func
        self.default_kwargs = {}

        self._own_instance = None
        update_wrapper(self, func)

        if is_func_bound(func):
            self.__self__ = func.__self__
 def _default_update(self):
     def f(a):
         """This is a test"""
         pass
     f.attr = 'This is also a test'
     def wrapper(b):
         pass
     functools.update_wrapper(wrapper, f)
     return wrapper, f
Beispiel #5
0
    def _default_update(self):
        def f(a):
            """This is a test"""
            pass

        f.attr = 'This is also a test'

        def wrapper(b):
            pass

        functools.update_wrapper(wrapper, f)
        return wrapper, f
 def test_no_update(self):
     def f():
         """This is a test"""
         pass
     f.attr = 'This is also a test'
     def wrapper():
         pass
     functools.update_wrapper(wrapper, f, (), ())
     self.check_wrapper(wrapper, f, (), ())
     self.assertEqual(wrapper.__name__, 'wrapper')
     self.assertEqual(wrapper.__doc__, None)
     self.assertFalse(hasattr(wrapper, 'attr'))
Beispiel #7
0
    def test_no_update(self):
        def f():
            """This is a test"""
            pass

        f.attr = 'This is also a test'

        def wrapper():
            pass

        functools.update_wrapper(wrapper, f, (), ())
        self.check_wrapper(wrapper, f, (), ())
        self.assertEqual(wrapper.__name__, 'wrapper')
        self.assertEqual(wrapper.__doc__, None)
        self.assertFalse(hasattr(wrapper, 'attr'))
 def test_selective_update(self):
     def f():
         pass
     f.attr = 'This is a different test'
     f.dict_attr = dict(a=1, b=2, c=3)
     def wrapper():
         pass
     wrapper.dict_attr = {}
     assign = ('attr',)
     update = ('dict_attr',)
     functools.update_wrapper(wrapper, f, assign, update)
     self.check_wrapper(wrapper, f, assign, update)
     self.assertEqual(wrapper.__name__, 'wrapper')
     self.assertEqual(wrapper.__doc__, None)
     self.assertEqual(wrapper.attr, 'This is a different test')
     self.assertEqual(wrapper.dict_attr, f.dict_attr)
Beispiel #9
0
    def test_selective_update(self):
        def f():
            pass

        f.attr = 'This is a different test'
        f.dict_attr = dict(a=1, b=2, c=3)

        def wrapper():
            pass

        wrapper.dict_attr = {}
        assign = ('attr', )
        update = ('dict_attr', )
        functools.update_wrapper(wrapper, f, assign, update)
        self.check_wrapper(wrapper, f, assign, update)
        self.assertEqual(wrapper.__name__, 'wrapper')
        self.assertEqual(wrapper.__doc__, None)
        self.assertEqual(wrapper.attr, 'This is a different test')
        self.assertEqual(wrapper.dict_attr, f.dict_attr)
 def test_missing_attributes(self):
     def f():
         pass
     def wrapper():
         pass
     wrapper.dict_attr = {}
     assign = ('attr',)
     update = ('dict_attr',)
     # Missing attributes on wrapped object are ignored
     functools.update_wrapper(wrapper, f, assign, update)
     self.assertNotIn('attr', wrapper.__dict__)
     self.assertEqual(wrapper.dict_attr, {})
     # Wrapper must have expected attributes for updating
     del wrapper.dict_attr
     with self.assertRaises(AttributeError):
         functools.update_wrapper(wrapper, f, assign, update)
     wrapper.dict_attr = 1
     with self.assertRaises(AttributeError):
         functools.update_wrapper(wrapper, f, assign, update)
Beispiel #11
0
    def test_missing_attributes(self):
        def f():
            pass

        def wrapper():
            pass

        wrapper.dict_attr = {}
        assign = ('attr', )
        update = ('dict_attr', )
        # Missing attributes on wrapped object are ignored
        functools.update_wrapper(wrapper, f, assign, update)
        self.assertNotIn('attr', wrapper.__dict__)
        self.assertEqual(wrapper.dict_attr, {})
        # Wrapper must have expected attributes for updating
        del wrapper.dict_attr
        with self.assertRaises(AttributeError):
            functools.update_wrapper(wrapper, f, assign, update)
        wrapper.dict_attr = 1
        with self.assertRaises(AttributeError):
            functools.update_wrapper(wrapper, f, assign, update)
Beispiel #12
0
    def wrap(self, view):
        def wrapper(*args, **kwargs):
            return self.admin_site.admin_view(view)(*args, **kwargs)

        wrapper.model_admin = self
        return update_wrapper(wrapper, view)