Beispiel #1
0
def test_apply():
    # applying arguments to f object returns partial applied functions.
    # when apply one by one, it's called currying.
    assert add.apply(1).apply(2)() == 3
    assert sub.apply(1).apply(2)() == -1

    # apply can accept more than one arguments at a time
    add_1_4 = add.apply(1, 4)
    assert add_1_4 == 5

    # supports keyword arguments as well, notice named argument 'base' is
    # supposed to be the second argument of int
    from_hex = f(int).apply(base=16)
    assert from_hex('0a') == 10
    assert from_hex('0b') == 11
    assert from_hex('0c') == 12
    assert from_hex('0d') == 13
    assert from_hex('0e') == 14
    assert from_hex('0f') == 15
    assert from_hex('10') == 16
Beispiel #2
0
def test_value():
    # a read-only property 'value' on f object, will invoke the function as
    # well
    assert add.apply(3, 8).value == 11