Skip to content
This repository
Browse code

Added support for class methods.

  • Loading branch information...
commit 676eebd9600eb938804b652ce572a30e3ee6626e 1 parent d069759
Jannis Leidel jezdez authored

Showing 2 changed files with 18 additions and 19 deletions. Show diff stats Hide diff stats

  1. +1 2  debug_toolbar/utils/tracking/__init__.py
  2. +17 17 tests/tests.py
3  debug_toolbar/utils/tracking/__init__.py
@@ -51,8 +51,7 @@ def _replace_function(func, wrapped):
51 51 module = import_module(func.__module__)
52 52 setattr(module, func.__name__, wrapped)
53 53 elif getattr(func, 'im_self', None):
54   - # TODO: classmethods
55   - raise NotImplementedError
  54 + setattr(func.im_self, func.__name__, classmethod(wrapped))
56 55 elif hasattr(func, 'im_class'):
57 56 # for unbound methods
58 57 setattr(func.im_class, func.__name__, wrapped)
34 tests/tests.py
@@ -315,23 +315,23 @@ def test(**kwargs):
315 315 self.assertTrue('foo' in foo['kwargs'])
316 316 self.assertEquals(foo['kwargs']['foo'], 'bar')
317 317
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)
335 335
336 336 def test_post_hook(self):
337 337 foo = {}

0 comments on commit 676eebd

Please sign in to comment.
Something went wrong with that request. Please try again.