mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-07-07 17:10:42 +00:00

* Adding StringJoiner * Release notes * Remove typing * Remove unused import * Try to fix header * Fix one test * Add to docs, move test to behavioral pipeline test * Undo changes * Fix test * Update haystack/components/joiners/string_joiner.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * Update haystack/components/joiners/string_joiner.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * Provide usage example * Apply suggestions from code review Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> --------- Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
from haystack.core.serialization import component_from_dict, component_to_dict
|
|
from haystack.components.joiners.string_joiner import StringJoiner
|
|
|
|
|
|
class TestStringJoiner:
|
|
def test_init(self):
|
|
joiner = StringJoiner()
|
|
assert isinstance(joiner, StringJoiner)
|
|
|
|
def test_to_dict(self):
|
|
joiner = StringJoiner()
|
|
data = component_to_dict(joiner, name="string_joiner")
|
|
assert data == {"type": "haystack.components.joiners.string_joiner.StringJoiner", "init_parameters": {}}
|
|
|
|
def test_from_dict(self):
|
|
data = {"type": "haystack.components.joiners.string_joiner.StringJoiner", "init_parameters": {}}
|
|
string_joiner = component_from_dict(StringJoiner, data=data, name="string_joiner")
|
|
assert isinstance(string_joiner, StringJoiner)
|
|
|
|
def test_empty_list(self):
|
|
joiner = StringJoiner()
|
|
result = joiner.run([])
|
|
assert result == {"strings": []}
|
|
|
|
def test_single_string(self):
|
|
joiner = StringJoiner()
|
|
result = joiner.run("a")
|
|
assert result == {"strings": ["a"]}
|
|
|
|
def test_two_strings(self):
|
|
joiner = StringJoiner()
|
|
result = joiner.run(["a", "b"])
|
|
assert result == {"strings": ["a", "b"]}
|