示例#1
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
示例#2
0
def test_with_immutable():
    count = 3
    generator = generate_greenlets(count)
    
    extra_value = object()
    extra_function = CountCalls(pass_parameter)
    immutable_greenlet = Greenlet(extra_function, extra_value)
    immutable_greenlet.immutable = True
    greenlet = group(
        generator.greenlets[0],
        generator.greenlets[1],
        immutable_greenlet,
        generator.greenlets[2],
    )
    greenlet.start()
    assert generator.values[0:2] + [extra_value] + generator.values[2:3] == greenlet.get()
    assert count == generator.calls
    assert 1 == extra_function.calls
示例#3
0
def test_with_immutable():
    count = 3
    generator = generate_greenlets(count)

    extra_value = object()
    extra_function = CountCalls(pass_parameter)
    immutable_greenlet = Greenlet(extra_function, extra_value)
    immutable_greenlet.immutable = True
    greenlet = group(
        generator.greenlets[0],
        generator.greenlets[1],
        immutable_greenlet,
        generator.greenlets[2],
    )
    greenlet.start()
    assert generator.values[0:2] + [
        extra_value
    ] + generator.values[2:3] == greenlet.get()
    assert count == generator.calls
    assert 1 == extra_function.calls