aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannis Leidel2012-05-13 12:51:55 +0200
committerJannis Leidel2012-05-13 12:51:55 +0200
commit676eebd9600eb938804b652ce572a30e3ee6626e (patch)
treebdc011b9dfce6827b99261d6352f9a36990ef9a2
parentd069759f014cc5605a448be67782ff9a00836037 (diff)
downloaddjango-debug-toolbar-676eebd9600eb938804b652ce572a30e3ee6626e.tar.bz2
Added support for class methods.
-rw-r--r--debug_toolbar/utils/tracking/__init__.py3
-rw-r--r--tests/tests.py34
2 files changed, 18 insertions, 19 deletions
diff --git a/debug_toolbar/utils/tracking/__init__.py b/debug_toolbar/utils/tracking/__init__.py
index 6d4b0e3..766c248 100644
--- a/debug_toolbar/utils/tracking/__init__.py
+++ b/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)
diff --git a/tests/tests.py b/tests/tests.py
index c599b6b..5a05050 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -315,23 +315,23 @@ class TrackingTestCase(BaseTestCase):
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 = {}