@@ -279,134 +279,135 @@ def module_func(*args, **kwargs):
279
279
"""Used by dispatch tests"""
280
280
return 'blah'
281
281
282
- if not six .PY3 :
283
- class TrackingTestCase (BaseTestCase ):
284
- @classmethod
285
- def class_method (cls , * args , ** kwargs ):
286
- return 'blah'
287
-
288
- def class_func (self , * args , ** kwargs ):
289
- """Used by dispatch tests"""
290
- return 'blah'
291
-
292
- def test_pre_hook (self ):
293
- foo = {}
294
-
295
- @pre_dispatch (module_func )
296
- def test (** kwargs ):
297
- foo .update (kwargs )
298
-
299
- self .assertTrue (hasattr (module_func , '__wrapped__' ))
300
- self .assertEqual (len (callbacks ['before' ]), 1 )
301
-
302
- module_func ('hi' , foo = 'bar' )
303
-
304
- self .assertTrue ('sender' in foo , foo )
305
- # best we can do
306
- self .assertEqual (foo ['sender' ].__name__ , 'module_func' )
307
- self .assertTrue ('start' in foo , foo )
308
- self .assertTrue (foo ['start' ] > 0 )
309
- self .assertTrue ('stop' not in foo , foo )
310
- self .assertTrue ('args' in foo , foo )
311
- self .assertTrue (len (foo ['args' ]), 1 )
312
- self .assertEqual (foo ['args' ][0 ], 'hi' )
313
- self .assertTrue ('kwargs' in foo , foo )
314
- self .assertTrue (len (foo ['kwargs' ]), 1 )
315
- self .assertTrue ('foo' in foo ['kwargs' ])
316
- self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
317
-
318
- callbacks ['before' ] = {}
319
-
320
- @pre_dispatch (TrackingTestCase .class_func )
321
- def test (** kwargs ):
322
- foo .update (kwargs )
323
-
324
- self .assertTrue (hasattr (TrackingTestCase .class_func , '__wrapped__' ))
325
- self .assertEqual (len (callbacks ['before' ]), 1 )
326
-
327
- self .class_func ('hello' , foo = 'bar' )
328
-
329
- self .assertTrue ('sender' in foo , foo )
330
- # best we can do
331
- self .assertEqual (foo ['sender' ].__name__ , 'class_func' )
332
- self .assertTrue ('start' in foo , foo )
333
- self .assertTrue (foo ['start' ] > 0 )
334
- self .assertTrue ('stop' not in foo , foo )
335
- self .assertTrue ('args' in foo , foo )
336
- self .assertTrue (len (foo ['args' ]), 2 )
337
- self .assertEqual (foo ['args' ][1 ], 'hello' )
338
- self .assertTrue ('kwargs' in foo , foo )
339
- self .assertTrue (len (foo ['kwargs' ]), 1 )
340
- self .assertTrue ('foo' in foo ['kwargs' ])
341
- self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
342
-
343
- callbacks ['before' ] = {}
344
-
345
- @pre_dispatch (TrackingTestCase .class_method )
346
- def test (** kwargs ):
347
- foo .update (kwargs )
348
-
349
- self .assertTrue (hasattr (TrackingTestCase .class_method , '__wrapped__' ))
350
- self .assertEqual (len (callbacks ['before' ]), 1 )
351
-
352
- TrackingTestCase .class_method ()
353
-
354
- self .assertTrue ('sender' in foo , foo )
355
- # best we can do
356
- self .assertEqual (foo ['sender' ].__name__ , 'class_method' )
357
- self .assertTrue ('start' in foo , foo )
358
- self .assertTrue ('stop' not in foo , foo )
359
- self .assertTrue ('args' in foo , foo )
360
-
361
- def test_post_hook (self ):
362
- foo = {}
363
-
364
- @post_dispatch (module_func )
365
- def test (** kwargs ):
366
- foo .update (kwargs )
367
-
368
- self .assertTrue (hasattr (module_func , '__wrapped__' ))
369
- self .assertEqual (len (callbacks ['after' ]), 1 )
370
-
371
- module_func ('hi' , foo = 'bar' )
372
-
373
- self .assertTrue ('sender' in foo , foo )
374
- # best we can do
375
- self .assertEqual (foo ['sender' ].__name__ , 'module_func' )
376
- self .assertTrue ('start' in foo , foo )
377
- self .assertTrue (foo ['start' ] > 0 )
378
- self .assertTrue ('stop' in foo , foo )
379
- self .assertTrue (foo ['stop' ] > foo ['start' ])
380
- self .assertTrue ('args' in foo , foo )
381
- self .assertTrue (len (foo ['args' ]), 1 )
382
- self .assertEqual (foo ['args' ][0 ], 'hi' )
383
- self .assertTrue ('kwargs' in foo , foo )
384
- self .assertTrue (len (foo ['kwargs' ]), 1 )
385
- self .assertTrue ('foo' in foo ['kwargs' ])
386
- self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
387
-
388
- callbacks ['after' ] = {}
389
-
390
- @post_dispatch (TrackingTestCase .class_func )
391
- def test (** kwargs ):
392
- foo .update (kwargs )
393
-
394
- self .assertTrue (hasattr (TrackingTestCase .class_func , '__wrapped__' ))
395
- self .assertEqual (len (callbacks ['after' ]), 1 )
396
-
397
- self .class_func ('hello' , foo = 'bar' )
398
-
399
- self .assertTrue ('sender' in foo , foo )
400
- # best we can do
401
- self .assertEqual (foo ['sender' ].__name__ , 'class_func' )
402
- self .assertTrue ('start' in foo , foo )
403
- self .assertTrue (foo ['start' ] > 0 )
404
- self .assertTrue ('stop' in foo , foo )
405
- self .assertTrue (foo ['stop' ] > foo ['start' ])
406
- self .assertTrue ('args' in foo , foo )
407
- self .assertTrue (len (foo ['args' ]), 2 )
408
- self .assertEqual (foo ['args' ][1 ], 'hello' )
409
- self .assertTrue ('kwargs' in foo , foo )
410
- self .assertTrue (len (foo ['kwargs' ]), 1 )
411
- self .assertTrue ('foo' in foo ['kwargs' ])
412
- self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
282
+
283
+ @unittest .skipIf (six .PY3 , "replace_call is not supported on Python 3" )
284
+ class TrackingTestCase (BaseTestCase ):
285
+ @classmethod
286
+ def class_method (cls , * args , ** kwargs ):
287
+ return 'blah'
288
+
289
+ def class_func (self , * args , ** kwargs ):
290
+ """Used by dispatch tests"""
291
+ return 'blah'
292
+
293
+ def test_pre_hook (self ):
294
+ foo = {}
295
+
296
+ @pre_dispatch (module_func )
297
+ def test (** kwargs ):
298
+ foo .update (kwargs )
299
+
300
+ self .assertTrue (hasattr (module_func , '__wrapped__' ))
301
+ self .assertEqual (len (callbacks ['before' ]), 1 )
302
+
303
+ module_func ('hi' , foo = 'bar' )
304
+
305
+ self .assertTrue ('sender' in foo , foo )
306
+ # best we can do
307
+ self .assertEqual (foo ['sender' ].__name__ , 'module_func' )
308
+ self .assertTrue ('start' in foo , foo )
309
+ self .assertTrue (foo ['start' ] > 0 )
310
+ self .assertTrue ('stop' not in foo , foo )
311
+ self .assertTrue ('args' in foo , foo )
312
+ self .assertTrue (len (foo ['args' ]), 1 )
313
+ self .assertEqual (foo ['args' ][0 ], 'hi' )
314
+ self .assertTrue ('kwargs' in foo , foo )
315
+ self .assertTrue (len (foo ['kwargs' ]), 1 )
316
+ self .assertTrue ('foo' in foo ['kwargs' ])
317
+ self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
318
+
319
+ callbacks ['before' ] = {}
320
+
321
+ @pre_dispatch (TrackingTestCase .class_func )
322
+ def test (** kwargs ):
323
+ foo .update (kwargs )
324
+
325
+ self .assertTrue (hasattr (TrackingTestCase .class_func , '__wrapped__' ))
326
+ self .assertEqual (len (callbacks ['before' ]), 1 )
327
+
328
+ self .class_func ('hello' , foo = 'bar' )
329
+
330
+ self .assertTrue ('sender' in foo , foo )
331
+ # best we can do
332
+ self .assertEqual (foo ['sender' ].__name__ , 'class_func' )
333
+ self .assertTrue ('start' in foo , foo )
334
+ self .assertTrue (foo ['start' ] > 0 )
335
+ self .assertTrue ('stop' not in foo , foo )
336
+ self .assertTrue ('args' in foo , foo )
337
+ self .assertTrue (len (foo ['args' ]), 2 )
338
+ self .assertEqual (foo ['args' ][1 ], 'hello' )
339
+ self .assertTrue ('kwargs' in foo , foo )
340
+ self .assertTrue (len (foo ['kwargs' ]), 1 )
341
+ self .assertTrue ('foo' in foo ['kwargs' ])
342
+ self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
343
+
344
+ callbacks ['before' ] = {}
345
+
346
+ @pre_dispatch (TrackingTestCase .class_method )
347
+ def test (** kwargs ):
348
+ foo .update (kwargs )
349
+
350
+ self .assertTrue (hasattr (TrackingTestCase .class_method , '__wrapped__' ))
351
+ self .assertEqual (len (callbacks ['before' ]), 1 )
352
+
353
+ TrackingTestCase .class_method ()
354
+
355
+ self .assertTrue ('sender' in foo , foo )
356
+ # best we can do
357
+ self .assertEqual (foo ['sender' ].__name__ , 'class_method' )
358
+ self .assertTrue ('start' in foo , foo )
359
+ self .assertTrue ('stop' not in foo , foo )
360
+ self .assertTrue ('args' in foo , foo )
361
+
362
+ def test_post_hook (self ):
363
+ foo = {}
364
+
365
+ @post_dispatch (module_func )
366
+ def test (** kwargs ):
367
+ foo .update (kwargs )
368
+
369
+ self .assertTrue (hasattr (module_func , '__wrapped__' ))
370
+ self .assertEqual (len (callbacks ['after' ]), 1 )
371
+
372
+ module_func ('hi' , foo = 'bar' )
373
+
374
+ self .assertTrue ('sender' in foo , foo )
375
+ # best we can do
376
+ self .assertEqual (foo ['sender' ].__name__ , 'module_func' )
377
+ self .assertTrue ('start' in foo , foo )
378
+ self .assertTrue (foo ['start' ] > 0 )
379
+ self .assertTrue ('stop' in foo , foo )
380
+ self .assertTrue (foo ['stop' ] > foo ['start' ])
381
+ self .assertTrue ('args' in foo , foo )
382
+ self .assertTrue (len (foo ['args' ]), 1 )
383
+ self .assertEqual (foo ['args' ][0 ], 'hi' )
384
+ self .assertTrue ('kwargs' in foo , foo )
385
+ self .assertTrue (len (foo ['kwargs' ]), 1 )
386
+ self .assertTrue ('foo' in foo ['kwargs' ])
387
+ self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
388
+
389
+ callbacks ['after' ] = {}
390
+
391
+ @post_dispatch (TrackingTestCase .class_func )
392
+ def test (** kwargs ):
393
+ foo .update (kwargs )
394
+
395
+ self .assertTrue (hasattr (TrackingTestCase .class_func , '__wrapped__' ))
396
+ self .assertEqual (len (callbacks ['after' ]), 1 )
397
+
398
+ self .class_func ('hello' , foo = 'bar' )
399
+
400
+ self .assertTrue ('sender' in foo , foo )
401
+ # best we can do
402
+ self .assertEqual (foo ['sender' ].__name__ , 'class_func' )
403
+ self .assertTrue ('start' in foo , foo )
404
+ self .assertTrue (foo ['start' ] > 0 )
405
+ self .assertTrue ('stop' in foo , foo )
406
+ self .assertTrue (foo ['stop' ] > foo ['start' ])
407
+ self .assertTrue ('args' in foo , foo )
408
+ self .assertTrue (len (foo ['args' ]), 2 )
409
+ self .assertEqual (foo ['args' ][1 ], 'hello' )
410
+ self .assertTrue ('kwargs' in foo , foo )
411
+ self .assertTrue (len (foo ['kwargs' ]), 1 )
412
+ self .assertTrue ('foo' in foo ['kwargs' ])
413
+ self .assertEqual (foo ['kwargs' ]['foo' ], 'bar' )
0 commit comments