Skip to content

Commit 676eebd

Browse files
committed
Added support for class methods.
1 parent d069759 commit 676eebd

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

debug_toolbar/utils/tracking/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def _replace_function(func, wrapped):
5151
module = import_module(func.__module__)
5252
setattr(module, func.__name__, wrapped)
5353
elif getattr(func, 'im_self', None):
54-
# TODO: classmethods
55-
raise NotImplementedError
54+
setattr(func.im_self, func.__name__, classmethod(wrapped))
5655
elif hasattr(func, 'im_class'):
5756
# for unbound methods
5857
setattr(func.im_class, func.__name__, wrapped)

tests/tests.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,23 @@ def test(**kwargs):
315315
self.assertTrue('foo' in foo['kwargs'])
316316
self.assertEquals(foo['kwargs']['foo'], 'bar')
317317

318-
# callbacks['before'] = {}
319-
#
320-
# @pre_dispatch(TrackingTestCase.class_method)
321-
# def test(**kwargs):
322-
# foo.update(kwargs)
323-
#
324-
# self.assertTrue(hasattr(TrackingTestCase.class_method, '__wrapped__'))
325-
# self.assertEquals(len(callbacks['before']), 1)
326-
#
327-
# TrackingTestCase.class_method()
328-
#
329-
# self.assertTrue('sender' in foo, foo)
330-
# # best we can do
331-
# self.assertEquals(foo['sender'].__name__, 'class_method')
332-
# self.assertTrue('start' in foo, foo)
333-
# self.assertTrue('stop' not in foo, foo)
334-
# self.assertTrue('args' in foo, foo)
318+
callbacks['before'] = {}
319+
320+
@pre_dispatch(TrackingTestCase.class_method)
321+
def test(**kwargs):
322+
foo.update(kwargs)
323+
324+
self.assertTrue(hasattr(TrackingTestCase.class_method, '__wrapped__'))
325+
self.assertEquals(len(callbacks['before']), 1)
326+
327+
TrackingTestCase.class_method()
328+
329+
self.assertTrue('sender' in foo, foo)
330+
# best we can do
331+
self.assertEquals(foo['sender'].__name__, 'class_method')
332+
self.assertTrue('start' in foo, foo)
333+
self.assertTrue('stop' not in foo, foo)
334+
self.assertTrue('args' in foo, foo)
335335

336336
def test_post_hook(self):
337337
foo = {}

0 commit comments

Comments
 (0)