Merge in RR/pyinfra from 2.0.0-documentation to 2.0.0
Squashed commit of the following:
commit 7a794bdcc987631cdc4d89b5620359464e2e018e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jul 4 13:05:26 2022 +0200
removed obsolete imports
commit 3fc6a7ef5d0172dbce1c4292d245eced2f378b5a
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jul 4 11:47:12 2022 +0200
enable docker-compose fixture
commit 36d8d3bc851b06d94cf12a73048a00a67ef79c42
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jul 4 11:46:53 2022 +0200
renaming
commit 3bf00d11cd041dff325b66f13fcd00d3ce96b8b5
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Thu Jun 30 12:47:57 2022 +0200
refactoring: added cached pipeline factory
commit 90e735852af2f86e35be845fabf28494de952edb
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Jun 29 13:47:08 2022 +0200
renaming
commit 93b3d4b202b41183ed8cabe193a4bfa03f520787
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Jun 29 13:25:03 2022 +0200
further refactored server setup code: moving and decomplecting
commit 8b2ed83c7ade5bd811cb045d56fbfb0353fa385e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Jun 29 12:53:09 2022 +0200
refactored server setup code: factored out and decoupled operation registry and prometheus summary registry
commit da2dce762bdd6889165fbb320dc9ee8a0bd089b2
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Tue Jun 28 19:40:04 2022 +0200
adjusted test target
commit 70df7911b9b92f4b72afd7d4b33ca2bbf136295e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Tue Jun 28 19:32:38 2022 +0200
minor refactoring
commit 0937b63dc000346559bde353381304b273244109
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 13:59:59 2022 +0200
support for empty operation suffix
commit 5e56917970962a2e69bbd66a324bdb4618c040bd
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 12:52:36 2022 +0200
minor refactoring
commit 40665a7815ae5927b3877bda14fb77deef37d667
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 10:57:04 2022 +0200
optimization: prefix filtering via storage API for get_all_object_names
commit af0892a899d09023eb0e61eecb63e03dc2fd3b60
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Jun 27 10:55:47 2022 +0200
topological sorting of definitions by caller hierarchy
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
import pytest
|
|
from funcy import repeatedly, takewhile, notnone, lmap, lmapcat, lflatten
|
|
|
|
from pyinfra.server.buffering.stream import FlatStreamBuffer, StreamBuffer
|
|
from pyinfra.server.dispatcher.dispatcher import Nothing
|
|
from pyinfra.server.stream.queued_stream_function import QueuedStreamFunction
|
|
from pyinfra.utils.func import lift, foreach, starlift
|
|
|
|
|
|
@pytest.fixture
|
|
def func(one_to_many):
|
|
def fn(x):
|
|
y = x**2
|
|
return y if not one_to_many else (y, y)
|
|
|
|
return fn
|
|
|
|
|
|
def test_stream_buffer(func, inputs, outputs, buffer_size):
|
|
stream_buffer = StreamBuffer(lift(func), buffer_size=buffer_size)
|
|
|
|
assert lmapcat(stream_buffer, (*inputs, Nothing)) == outputs
|
|
assert lmapcat(stream_buffer, [Nothing]) == []
|
|
|
|
|
|
@pytest.mark.parametrize("n_items", [1])
|
|
def test_stream_buffer_catches_type_error(func, inputs, outputs):
|
|
|
|
stream_buffer = StreamBuffer(func)
|
|
|
|
with pytest.raises(TypeError):
|
|
lmapcat(stream_buffer, inputs)
|
|
|
|
|
|
def test_flat_stream_buffer(func, inputs, outputs, buffer_size):
|
|
flat_stream_buffer = FlatStreamBuffer(lift(func), buffer_size=buffer_size)
|
|
|
|
assert list(flat_stream_buffer(inputs)) == outputs
|
|
assert list(flat_stream_buffer([])) == []
|
|
|
|
|
|
@pytest.mark.xfail(reason="input wrong format, TODO: redesign input fixture hierarchy")
|
|
def test_flat_stream_buffer_on_different_data(
|
|
core_operation, input_data_items, metadata, target_data_items, buffer_size, item_type, one_to_many
|
|
):
|
|
|
|
if core_operation is Nothing:
|
|
pytest.skip(f"No operation defined for parameter combination: {item_type=}, {one_to_many=}")
|
|
|
|
flat_stream_buffer = FlatStreamBuffer(starlift(core_operation), buffer_size=buffer_size)
|
|
|
|
assert list(flat_stream_buffer(zip(input_data_items, metadata))) == target_data_items
|
|
assert list(flat_stream_buffer([])) == []
|
|
|
|
|
|
def test_queued_stream_function(func, inputs, outputs):
|
|
queued_stream_function = QueuedStreamFunction(lift(func))
|
|
|
|
foreach(queued_stream_function.push, inputs)
|
|
|
|
assert list(takewhile(notnone, repeatedly(queued_stream_function.pop))) == outputs
|
|
|
|
|
|
@pytest.fixture
|
|
def inputs(n_items):
|
|
return range(n_items)
|
|
|
|
|
|
@pytest.fixture
|
|
def outputs(inputs, func):
|
|
return lmap(func, inputs)
|
|
|
|
|
|
@pytest.fixture(params=[1, 3, 10, 12])
|
|
def buffer_size(request):
|
|
return request.param
|