Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as Python by Dhananjay Nene ( 16 years ago )
# Python unit testing of decorators
import unittest

def collect(collector):
    def wrapper(func):
        def inner(*args,**kwargs):
            ret = func(*args,**kwargs)
            collector.append((func.__name__,args,kwargs,ret))
            return ret
        return inner
    return wrapper

collector = []

def add(x,y):
    return x + y

def mult(x,y):
    return x * y

class TestCollector(unittest.TestCase):
    def testCollection(self):
        collector = []
        collect(collector)(add)(3,5)
        collect(collector)(mult)(4,6)
        self.assertEquals(collector,[('add', (3, 5), {}, 8), ('mult', (4, 6), {}, 24)])

 

Revise this Paste

Your Name: Code Language: