Back to index

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

List of all members.

Public Member Functions

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

Private Member Functions

def _default_update

Detailed Description

Definition at line 199 of file test_functools.py.


Member Function Documentation

Reimplemented in test.test_functools.TestWraps.

Definition at line 214 of file test_functools.py.

00214 
00215     def _default_update(self):
00216         def f(a:'This is a new annotation'):
00217             """This is a test"""
00218             pass
00219         f.attr = 'This is also a test'
00220         def wrapper(b:'This is the prior annotation'):
00221             pass
00222         functools.update_wrapper(wrapper, f)
00223         return wrapper, f

Here is the call graph for this function:

Here is the caller graph for this function:

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

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 in test.test_functools.TestWraps.

Definition at line 224 of file test_functools.py.

00224 
00225     def test_default_update(self):
00226         wrapper, f = self._default_update()
00227         self.check_wrapper(wrapper, f)
00228         self.assertIs(wrapper.__wrapped__, f)
00229         self.assertEqual(wrapper.__name__, 'f')
00230         self.assertEqual(wrapper.attr, 'This is also a test')
00231         self.assertEqual(wrapper.__annotations__['a'], 'This is a new annotation')
00232         self.assertNotIn('b', wrapper.__annotations__)

Here is the call graph for this function:

Reimplemented in test.test_functools.TestWraps.

Definition at line 235 of file test_functools.py.

00235 
00236     def test_default_update_doc(self):
00237         wrapper, f = self._default_update()
00238         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 in test.test_functools.TestWraps.

Definition at line 239 of file test_functools.py.

00239 
00240     def test_no_update(self):
00241         def f():
00242             """This is a test"""
00243             pass
00244         f.attr = 'This is also a test'
00245         def wrapper():
00246             pass
00247         functools.update_wrapper(wrapper, f, (), ())
00248         self.check_wrapper(wrapper, f, (), ())
00249         self.assertEqual(wrapper.__name__, 'wrapper')
00250         self.assertEqual(wrapper.__doc__, None)
00251         self.assertEqual(wrapper.__annotations__, {})
00252         self.assertFalse(hasattr(wrapper, 'attr'))

Reimplemented in test.test_functools.TestWraps.

Definition at line 253 of file test_functools.py.

00253 
00254     def test_selective_update(self):
00255         def f():
00256             pass
00257         f.attr = 'This is a different test'
00258         f.dict_attr = dict(a=1, b=2, c=3)
00259         def wrapper():
00260             pass
00261         wrapper.dict_attr = {}
00262         assign = ('attr',)
00263         update = ('dict_attr',)
00264         functools.update_wrapper(wrapper, f, assign, update)
00265         self.check_wrapper(wrapper, f, assign, update)
00266         self.assertEqual(wrapper.__name__, 'wrapper')
00267         self.assertEqual(wrapper.__doc__, None)
00268         self.assertEqual(wrapper.attr, 'This is a different test')
00269         self.assertEqual(wrapper.dict_attr, f.dict_attr)


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