Ejemplo n.º 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}
Ejemplo n.º 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}
Ejemplo n.º 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}
Ejemplo n.º 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}
Ejemplo n.º 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}
Ejemplo n.º 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}
Ejemplo n.º 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
Ejemplo n.º 8
0
def test_checkpoints__empty():
    transform = chained()
    assert apply(transform, 5, rewrites=[add_checkpoints]) == 5
Ejemplo n.º 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
Ejemplo n.º 10
0
def test_checkpoints__empty():
    transform = chained()
    assert apply(transform, 5, rewrites=[add_checkpoints]) == 5