chore: import upstream snapshot with attribution
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Docker image release / Build base image (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Has been cancelled
Tests / Check if changed (push) Has been cancelled
Tests / format (push) Has been cancelled
Tests / check-imports (push) Has been cancelled
Tests / Unit / macos-latest (push) Has been cancelled
Tests / Unit / ubuntu-latest (push) Has been cancelled
Tests / Unit / windows-latest (push) Has been cancelled
Tests / mypy (push) Has been cancelled
Tests / Integration / ubuntu-latest (push) Has been cancelled
Tests / Integration / macos-latest (push) Has been cancelled
Tests / Integration / windows-latest (push) Has been cancelled
Tests / notify-slack-on-failure (push) Has been cancelled
Tests / Mark tests as completed (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Docker image release / Build base image (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Has been cancelled
Tests / Check if changed (push) Has been cancelled
Tests / format (push) Has been cancelled
Tests / check-imports (push) Has been cancelled
Tests / Unit / macos-latest (push) Has been cancelled
Tests / Unit / ubuntu-latest (push) Has been cancelled
Tests / Unit / windows-latest (push) Has been cancelled
Tests / mypy (push) Has been cancelled
Tests / Integration / ubuntu-latest (push) Has been cancelled
Tests / Integration / macos-latest (push) Has been cancelled
Tests / Integration / windows-latest (push) Has been cancelled
Tests / notify-slack-on-failure (push) Has been cancelled
Tests / Mark tests as completed (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from haystack.components.generators.chat.openai import OpenAIChatGenerator
|
||||
from haystack.core.errors import DeserializationError
|
||||
from haystack.utils.deserialization import deserialize_component_inplace
|
||||
|
||||
|
||||
class ChatGeneratorWithoutFromDict:
|
||||
def to_dict(self):
|
||||
return {"type": "test_deserialization.ChatGeneratorWithoutFromDict"}
|
||||
|
||||
|
||||
class TestDeserializeComponentInplace:
|
||||
def test_deserialize_component_inplace(self, monkeypatch):
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
|
||||
chat_generator = OpenAIChatGenerator()
|
||||
data = {"chat_generator": chat_generator.to_dict()}
|
||||
deserialize_component_inplace(data)
|
||||
assert isinstance(data["chat_generator"], OpenAIChatGenerator)
|
||||
assert data["chat_generator"].to_dict() == chat_generator.to_dict()
|
||||
|
||||
def test_missing_key(self):
|
||||
data = {"some_key": "some_value"}
|
||||
with pytest.raises(DeserializationError):
|
||||
deserialize_component_inplace(data)
|
||||
|
||||
def test_component_is_not_a_dict(self):
|
||||
data = {"chat_generator": "not_a_dict"}
|
||||
with pytest.raises(DeserializationError):
|
||||
deserialize_component_inplace(data)
|
||||
|
||||
def test_type_key_missing(self):
|
||||
data = {"chat_generator": {"some_key": "some_value"}}
|
||||
with pytest.raises(DeserializationError):
|
||||
deserialize_component_inplace(data)
|
||||
|
||||
def test_class_not_correctly_imported(self):
|
||||
data = {"chat_generator": {"type": "invalid.module.InvalidClass"}}
|
||||
with pytest.raises(DeserializationError):
|
||||
deserialize_component_inplace(data)
|
||||
|
||||
def test_component_no_from_dict_method(self):
|
||||
chat_generator = ChatGeneratorWithoutFromDict()
|
||||
data = {"chat_generator": chat_generator.to_dict()}
|
||||
deserialize_component_inplace(data)
|
||||
assert isinstance(data["chat_generator"], ChatGeneratorWithoutFromDict)
|
||||
Reference in New Issue
Block a user