Пример #1
0
def test_checkpoints__rewrites():
    """
    Test that only parts that were changed are executed if a pipeline is
    changed.
    """
    _checkpoints = {}
    calls = {}

    transform = chained(
        _count(calls, 'step 1', lambda x: x * 2),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 2', lambda x: x - 3),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 3', lambda x: x),
    )

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 1, 'step 3': 1}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 1, 'step 3': 2}

    transform = chained(
        _count(calls, 'step 1', lambda x: x * 2),
        checkpoint(target=_checkpoints),
        _count(calls, 'alt-step 2', lambda x: x),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 3', lambda x: x),
    )

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 10
    assert calls == {'step 1': 1, 'step 2': 1, 'alt-step 2': 1, 'step 3': 3}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 10
    assert calls == {'step 1': 1, 'step 2': 1, 'alt-step 2': 1, 'step 3': 4}
Пример #2
0
def test_checkpoints__rewrites():
    """
    Test that only parts that were changed are executed if a pipeline is
    changed.
    """
    _checkpoints = {}
    calls = {}

    transform = chained(
        _count(calls, 'step 1', lambda x: x * 2),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 2', lambda x: x - 3),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 3', lambda x: x),
    )

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 1, 'step 3': 1}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 1, 'step 3': 2}

    transform = chained(
        _count(calls, 'step 1', lambda x: x * 2),
        checkpoint(target=_checkpoints),
        _count(calls, 'alt-step 2', lambda x: x),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 3', lambda x: x),
    )

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 10
    assert calls == {'step 1': 1, 'step 2': 1, 'alt-step 2': 1, 'step 3': 3}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 10
    assert calls == {'step 1': 1, 'step 2': 1, 'alt-step 2': 1, 'step 3': 4}
Пример #3
0
def test_checkpoints__single_no_rewrite():
    _checkpoints = {}
    calls = {}

    transform = chained(_count(calls, 'step 1', lambda x: x * 2),
                        checkpoint(target=_checkpoints),
                        _count(calls, 'step 2', lambda x: x - 3))

    assert apply(transform, 5) == 7
    assert calls == {'step 1': 1, 'step 2': 1}

    assert apply(transform, 5) == 7
    assert calls == {'step 1': 2, 'step 2': 2}
Пример #4
0
def test_checkpoints__single_no_rewrite():
    _checkpoints = {}
    calls = {}

    transform = chained(
        _count(calls, 'step 1', lambda x: x * 2),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 2', lambda x: x - 3)
    )

    assert apply(transform, 5) == 7
    assert calls == {'step 1': 1, 'step 2': 1}

    assert apply(transform, 5) == 7
    assert calls == {'step 1': 2, 'step 2': 2}
Пример #5
0
def test_checkpoints__single():
    _checkpoints = {}
    calls = {}

    transform = chained(_count(calls, 'step 1', lambda x: x * 2),
                        checkpoint(target=_checkpoints),
                        _count(calls, 'step 2', lambda x: x - 3))

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 1}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 2}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 3}

    _checkpoints.clear()

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 2, 'step 2': 4}
Пример #6
0
def test_checkpoints__single():
    _checkpoints = {}
    calls = {}

    transform = chained(
        _count(calls, 'step 1', lambda x: x * 2),
        checkpoint(target=_checkpoints),
        _count(calls, 'step 2', lambda x: x - 3)
    )

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 1}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 2}

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 1, 'step 2': 3}

    _checkpoints.clear()

    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
    assert calls == {'step 1': 2, 'step 2': 4}
Пример #7
0
def test_checkpoints__no_checkpoints():
    transform = chained(lambda x: x * 2, lambda x: x - 3)
    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
Пример #8
0
def test_checkpoints__empty():
    transform = chained()
    assert apply(transform, 5, rewrites=[add_checkpoints]) == 5
Пример #9
0
def test_checkpoints__no_checkpoints():
    transform = chained(lambda x: x * 2, lambda x: x - 3)
    assert apply(transform, 5, rewrites=[add_checkpoints]) == 7
Пример #10
0
def test_checkpoints__empty():
    transform = chained()
    assert apply(transform, 5, rewrites=[add_checkpoints]) == 5