Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def test_function_scrub():
    """
    Tests scrubbing cb's from function arguments
    """

    lut = Lut()
    scrubber = Scrubber(lut)

    #a named function
    def sqrt(x):
        return x**0.5

    #a *args, yo
    scrubbed = scrubber.scrub([1, 5, lambda x: x+1, sqrt])

    nt.assert_equal( scrubbed,
                     {'callbacks': {0: [2], 'sqrt': [3]},
                      'arguments': [1, 5, '[function]', '[function]']
                     })

    # sqrt and the lambda are registered to the lut.
    # is this the behavior I want?
    nt.assert_equal(lut.lookup('sqrt')(4), 2)