Browse files

Added support for class methods.

  • Loading branch information...
1 parent d069759 commit 676eebd9600eb938804b652ce572a30e3ee6626e @jezdez jezdez committed May 13, 2012
Showing with 18 additions and 19 deletions.
  1. +1 −2 debug_toolbar/utils/tracking/__init__.py
  2. +17 −17 tests/tests.py
View
3 debug_toolbar/utils/tracking/__init__.py
@@ -51,8 +51,7 @@ def _replace_function(func, wrapped):
module = import_module(func.__module__)
setattr(module, func.__name__, wrapped)
elif getattr(func, 'im_self', None):
- # TODO: classmethods
- raise NotImplementedError
+ setattr(func.im_self, func.__name__, classmethod(wrapped))
elif hasattr(func, 'im_class'):
# for unbound methods
setattr(func.im_class, func.__name__, wrapped)
View
34 tests/tests.py
@@ -315,23 +315,23 @@ def test(**kwargs):
self.assertTrue('foo' in foo['kwargs'])
self.assertEquals(foo['kwargs']['foo'], 'bar')
- # callbacks['before'] = {}
- #
- # @pre_dispatch(TrackingTestCase.class_method)
- # def test(**kwargs):
- # foo.update(kwargs)
- #
- # self.assertTrue(hasattr(TrackingTestCase.class_method, '__wrapped__'))
- # self.assertEquals(len(callbacks['before']), 1)
- #
- # TrackingTestCase.class_method()
- #
- # self.assertTrue('sender' in foo, foo)
- # # best we can do
- # self.assertEquals(foo['sender'].__name__, 'class_method')
- # self.assertTrue('start' in foo, foo)
- # self.assertTrue('stop' not in foo, foo)
- # self.assertTrue('args' in foo, foo)
+ callbacks['before'] = {}
+
+ @pre_dispatch(TrackingTestCase.class_method)
+ def test(**kwargs):
+ foo.update(kwargs)
+
+ self.assertTrue(hasattr(TrackingTestCase.class_method, '__wrapped__'))
+ self.assertEquals(len(callbacks['before']), 1)
+
+ TrackingTestCase.class_method()
+
+ self.assertTrue('sender' in foo, foo)
+ # best we can do
+ self.assertEquals(foo['sender'].__name__, 'class_method')
+ self.assertTrue('start' in foo, foo)
+ self.assertTrue('stop' not in foo, foo)
+ self.assertTrue('args' in foo, foo)
def test_post_hook(self):
foo = {}

0 comments on commit 676eebd

Please sign in to comment.