Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_functools.TestWraps Class Reference
Inheritance diagram for test.test_functools.TestWraps:
Inheritance graph
[legend]
Collaboration diagram for test.test_functools.TestWraps:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_default_update
def test_default_update_doc
def test_no_update
def test_selective_update
def check_wrapper
def test_missing_attributes
def test_builtin_update

Private Member Functions

def _default_update

Detailed Description

Definition at line 301 of file test_functools.py.


Member Function Documentation

Reimplemented from test.test_functools.TestUpdateWrapper.

Definition at line 303 of file test_functools.py.

00303 
00304     def _default_update(self):
00305         def f():
00306             """This is a test"""
00307             pass
00308         f.attr = 'This is also a test'
00309         @functools.wraps(f)
00310         def wrapper():
00311             pass
00312         self.check_wrapper(wrapper, f)
00313         return wrapper

def test.test_functools.TestUpdateWrapper.check_wrapper (   self,
  wrapper,
  wrapped,
  assigned = functools.WRAPPER_ASSIGNMENTS,
  updated = functools.WRAPPER_UPDATES 
) [inherited]

Definition at line 203 of file test_functools.py.

00203 
00204                       updated=functools.WRAPPER_UPDATES):
00205         # Check attributes were assigned
00206         for name in assigned:
00207             self.assertTrue(getattr(wrapper, name) is getattr(wrapped, name))
00208         # Check attributes were updated
00209         for name in updated:
00210             wrapper_attr = getattr(wrapper, name)
00211             wrapped_attr = getattr(wrapped, name)
00212             for key in wrapped_attr:
00213                 self.assertTrue(wrapped_attr[key] is wrapper_attr[key])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 292 of file test_functools.py.

00292 
00293     def test_builtin_update(self):
00294         # Test for bug #1576241
00295         def wrapper():
00296             pass
00297         functools.update_wrapper(wrapper, max)
00298         self.assertEqual(wrapper.__name__, 'max')
00299         self.assertTrue(wrapper.__doc__.startswith('max('))
00300         self.assertEqual(wrapper.__annotations__, {})

Here is the call graph for this function:

Reimplemented from test.test_functools.TestUpdateWrapper.

Definition at line 314 of file test_functools.py.

00314 
00315     def test_default_update(self):
00316         wrapper = self._default_update()
00317         self.assertEqual(wrapper.__name__, 'f')
00318         self.assertEqual(wrapper.attr, 'This is also a test')

Here is the call graph for this function:

Reimplemented from test.test_functools.TestUpdateWrapper.

Definition at line 321 of file test_functools.py.

00321 
00322     def test_default_update_doc(self):
00323         wrapper = self._default_update()
00324         self.assertEqual(wrapper.__doc__, 'This is a test')

Here is the call graph for this function:

Definition at line 270 of file test_functools.py.

00270 
00271     def test_missing_attributes(self):
00272         def f():
00273             pass
00274         def wrapper():
00275             pass
00276         wrapper.dict_attr = {}
00277         assign = ('attr',)
00278         update = ('dict_attr',)
00279         # Missing attributes on wrapped object are ignored
00280         functools.update_wrapper(wrapper, f, assign, update)
00281         self.assertNotIn('attr', wrapper.__dict__)
00282         self.assertEqual(wrapper.dict_attr, {})
00283         # Wrapper must have expected attributes for updating
00284         del wrapper.dict_attr
00285         with self.assertRaises(AttributeError):
00286             functools.update_wrapper(wrapper, f, assign, update)
00287         wrapper.dict_attr = 1
00288         with self.assertRaises(AttributeError):
00289             functools.update_wrapper(wrapper, f, assign, update)

Reimplemented from test.test_functools.TestUpdateWrapper.

Definition at line 325 of file test_functools.py.

00325 
00326     def test_no_update(self):
00327         def f():
00328             """This is a test"""
00329             pass
00330         f.attr = 'This is also a test'
00331         @functools.wraps(f, (), ())
00332         def wrapper():
00333             pass
00334         self.check_wrapper(wrapper, f, (), ())
00335         self.assertEqual(wrapper.__name__, 'wrapper')
00336         self.assertEqual(wrapper.__doc__, None)
00337         self.assertFalse(hasattr(wrapper, 'attr'))

Reimplemented from test.test_functools.TestUpdateWrapper.

Definition at line 338 of file test_functools.py.

00338 
00339     def test_selective_update(self):
00340         def f():
00341             pass
00342         f.attr = 'This is a different test'
00343         f.dict_attr = dict(a=1, b=2, c=3)
00344         def add_dict_attr(f):
00345             f.dict_attr = {}
00346             return f
00347         assign = ('attr',)
00348         update = ('dict_attr',)
00349         @functools.wraps(f, assign, update)
00350         @add_dict_attr
00351         def wrapper():
00352             pass
00353         self.check_wrapper(wrapper, f, assign, update)
00354         self.assertEqual(wrapper.__name__, 'wrapper')
00355         self.assertEqual(wrapper.__doc__, None)
00356         self.assertEqual(wrapper.attr, 'This is a different test')
00357         self.assertEqual(wrapper.dict_attr, f.dict_attr)


The documentation for this class was generated from the following file: