test_string_joiner.py
1 # SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai> 2 # 3 # SPDX-License-Identifier: Apache-2.0 4 5 from haystack.components.joiners.string_joiner import StringJoiner 6 from haystack.core.serialization import component_from_dict, component_to_dict 7 8 9 class TestStringJoiner: 10 def test_init(self): 11 joiner = StringJoiner() 12 assert isinstance(joiner, StringJoiner) 13 14 def test_to_dict(self): 15 joiner = StringJoiner() 16 data = component_to_dict(joiner, name="string_joiner") 17 assert data == {"type": "haystack.components.joiners.string_joiner.StringJoiner", "init_parameters": {}} 18 19 def test_from_dict(self): 20 data = {"type": "haystack.components.joiners.string_joiner.StringJoiner", "init_parameters": {}} 21 string_joiner = component_from_dict(StringJoiner, data=data, name="string_joiner") 22 assert isinstance(string_joiner, StringJoiner) 23 24 def test_empty_list(self): 25 joiner = StringJoiner() 26 result = joiner.run([]) 27 assert result == {"strings": []} 28 29 def test_single_string(self): 30 joiner = StringJoiner() 31 result = joiner.run("a") 32 assert result == {"strings": ["a"]} 33 34 def test_two_strings(self): 35 joiner = StringJoiner() 36 result = joiner.run(["a", "b"]) 37 assert result == {"strings": ["a", "b"]}