Esempio n. 1
0
def test_nested_chain():
    value = object()
    test_function = CountCalls(pass_parameter)
    greenlet = chain(
        (test_function, value),
        chain(
            test_function,
            test_function,
            test_function,
            test_function),
        test_function,
    )
    greenlet.start()
    assert value is greenlet.get()
    assert 6 == test_function.calls
Esempio n. 2
0
def test_chain_add_args():
    return_second = lambda x, y: y
    value, value2 = object(), object()
    greenlet = chain(
        (pass_parameter, value),
        (return_second, value2),
    )
    greenlet.start()
    assert value2 == greenlet.get()
Esempio n. 3
0
def test_chain_one():
    value = object()
    test_function = CountCalls(pass_parameter)
    greenlet = chain(
        (test_function, value),
    )
    greenlet.start()
    assert value == greenlet.get()
    assert 1 == test_function.calls
Esempio n. 4
0
def test_pass_into_chain():
    value = object()
    test_function = CountCalls(pass_parameter)
    greenlet = chain(
        test_function,
        test_function,
    )
    greenlet.start(value)
    assert value == greenlet.get()
    assert 2 == test_function.calls
Esempio n. 5
0
def test_simple_chain():
    value = object()
    test_function = CountCalls(pass_parameter)
    greenlet = chain(
        Greenlet(test_function, value),
        test_function,
    )
    greenlet.start()
    assert value == greenlet.get()
    assert 2 == test_function.calls
Esempio n. 6
0
def test_chain_with_immutable():
    value, value2 = object(), object()
    test_function = CountCalls(pass_parameter)
    immutable_greenlet = Greenlet(test_function, value2)
    immutable_greenlet.immutable = True
    greenlet = chain(
        (test_function, value),
        test_function,
        immutable_greenlet,
        test_function,
    )
    greenlet.start()
    assert value2 == greenlet.get()
    assert 4 == test_function.calls