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 )
import unittest
def doubler(func):
    #doubles all arguments
    def inner(*args):
        double_args = [2*arg for arg in args]
        return func(*double_args)
    return inner
        
class TestDoubler(unittest.TestCase):
    def testDoubling(self):
        x = 2
        y = 3
        def mock_add(a,b):
            self.assertEquals((a,b),(2 * x, 2 * y))
            return 2 * (a + b)
        #decorate
        mock_adder = doubler(mock_add)
        mock_adder(2,3)

 

Revise this Paste

Children: 12806
Your Name: Code Language: