def test_get_handlers_impossible(): int_source = IntSource() float_store = FloatStore() int_float = IntFloatTransformer() elements = [float_store, int_source] transformers = {int_float} # noinspection PyTypeChecker pipeline = DataPipeline(elements, transformers) with pytest.raises(NoConversionError): pipeline._get_handlers(str)
def test_get_handlers(): int_source = IntSource() float_store = FloatStore() int_float = IntFloatTransformer() float_int = FloatIntTransformer() string = StringTransformer() elements = [float_store, int_source] transformers = {int_float, float_int, string} # noinspection PyTypeChecker pipeline = DataPipeline(elements, transformers) handlers = pipeline._get_handlers(str) assert type(handlers) is list assert len(handlers) is 2 assert handlers[0]._source is float_store assert handlers[0]._source_type is float assert handlers[1]._source is int_source assert handlers[1]._source_type is int values = [ random.uniform(-VALUES_MAX, VALUES_MAX) for _ in range(VALUES_COUNT) ] for value in values: assert type(handlers[0]._transform(data=value)) is str values = [ random.randint(-VALUES_MAX, VALUES_MAX) for _ in range(VALUES_COUNT) ] for value in values: assert type(handlers[1]._transform(data=value)) is str assert len(handlers[0]._before_transform) == 0 assert len(handlers[0]._after_transform) == 0 assert len(handlers[1]._before_transform) == 1 assert len(handlers[1]._after_transform) == 1 sink_handler = list(handlers[1]._before_transform)[0] assert sink_handler._sink is float_store assert sink_handler._store_type is float for value in values: assert type(sink_handler._transform(data=value)) is float