def test_lut_lambda(): # make a lookup table, register a random-ass function, get it back and # make sure it works. lut = Lut() key = lut.register(lambda x: x+1) fxn = lut.lookup(key) nt.assert_equal(fxn(1), 2) nt.assert_equal(fxn(2), 3)
def test_lut_method(): # make a lut, register a method and make sure you can get it *by name*. class Test(object): def ping(self, cb): cb('pong!') test = Test() lut = Lut() key = lut.register(Test.ping) nt.assert_equal(key, 'ping') fxn = lut.lookup(key)