haystack/test/core/pipeline/test_self_loop.py
Silvano Cerza d4f6531c52
feat: Refactor Pipeline.run() (#6729)
* First rough implementation of refactored run

* Further improve run logic

* Properly handle variadic input in run

* Further work

* Enhance names and add more documentation

* Fix issue with output distribution

* This works

* Enhance run comments

* Mark Multiplexer as greedy

* Remove MergeLoop in favour of Multiplexer in tests

* Remove FirstIntSelector in favour of Multiplexer

* Handle corner when waiting for input is stuck

* Remove unused import

* Handle mutable input data in run and misbehaving components

* Handle run input validation

* Test validation

* Fix pylint

* Fix mypy

* Call warm_up in run to fix tests
2024-01-18 17:53:47 +01:00

32 lines
1.1 KiB
Python

# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
import logging
from haystack.core.pipeline import Pipeline
from haystack.testing.sample_components import AddFixedValue, SelfLoop
logging.basicConfig(level=logging.DEBUG)
def test_pipeline_one_node():
pipeline = Pipeline(max_loops_allowed=10)
pipeline.add_component("self_loop", SelfLoop())
pipeline.connect("self_loop.current_value", "self_loop.values")
results = pipeline.run({"self_loop": {"values": 5}})
assert results["self_loop"]["final_result"] == 0
def test_pipeline():
pipeline = Pipeline(max_loops_allowed=10)
pipeline.add_component("add_1", AddFixedValue())
pipeline.add_component("self_loop", SelfLoop())
pipeline.add_component("add_2", AddFixedValue())
pipeline.connect("add_1", "self_loop.values")
pipeline.connect("self_loop.current_value", "self_loop.values")
pipeline.connect("self_loop.final_result", "add_2.value")
results = pipeline.run({"add_1": {"value": 5}})
assert results["add_2"]["result"] == 1