haystack/test/preview/components/builders/test_prompt_builder.py
Julian Risch 9f3b6512be
refactor: Remove reimplementations of default from_dict/to_dict and corresponding tests in 2.0 (#6108)
* whisper transcriber

* remove from/to_dict from builders

* remove from/to_dict from embedders

* remove from/to_dict from fetcher, file_converters

* remove from/to_dict from generators, preprocessors

* remove from/to_dict from ranker, reader

* remove from/to_dict from router, sampler, websearch

* pylint

* reno

* refactor import

* remove unused import
2023-10-19 11:17:02 +02:00

38 lines
1.1 KiB
Python

import pytest
from haystack.preview.components.builders.prompt_builder import PromptBuilder
@pytest.mark.unit
def test_init():
builder = PromptBuilder(template="This is a {{ variable }}")
assert builder._template_string == "This is a {{ variable }}"
@pytest.mark.unit
def test_to_dict():
builder = PromptBuilder(template="This is a {{ variable }}")
res = builder.to_dict()
assert res == {"type": "PromptBuilder", "init_parameters": {"template": "This is a {{ variable }}"}}
@pytest.mark.unit
def test_run():
builder = PromptBuilder(template="This is a {{ variable }}")
res = builder.run(variable="test")
assert res == {"prompt": "This is a test"}
@pytest.mark.unit
def test_run_without_input():
builder = PromptBuilder(template="This is a template without input")
res = builder.run()
assert res == {"prompt": "This is a template without input"}
@pytest.mark.unit
def test_run_with_missing_input():
builder = PromptBuilder(template="This is a {{ variable }}")
res = builder.run()
assert res == {"prompt": "This is a "}