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,3 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
@@ -0,0 +1,61 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import pytest
|
||||
|
||||
from haystack.marshal.yaml import YamlMarshaller
|
||||
|
||||
|
||||
class InvalidClass:
|
||||
def __init__(self) -> None:
|
||||
self.a = 1
|
||||
self.b = None
|
||||
self.c = "string"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def yaml_data():
|
||||
return {"key": "value", 1: 0.221, "list": [1, 2, 3], "tuple": (1, None, True), "dict": {"set": {False}}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def invalid_yaml_data():
|
||||
return {"key": "value", 1: 0.221, "list": [1, 2, 3], "tuple": (1, InvalidClass(), True), "dict": {"set": {False}}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def serialized_yaml_str():
|
||||
return """key: value
|
||||
1: 0.221
|
||||
list:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
tuple: !!python/tuple
|
||||
- 1
|
||||
- null
|
||||
- true
|
||||
dict:
|
||||
set: !!set
|
||||
false: null
|
||||
"""
|
||||
|
||||
|
||||
def test_yaml_marshal(yaml_data, serialized_yaml_str):
|
||||
marshaller = YamlMarshaller()
|
||||
marshalled = marshaller.marshal(yaml_data)
|
||||
assert isinstance(marshalled, str)
|
||||
assert marshalled.strip().replace("\n", "") == serialized_yaml_str.strip().replace("\n", "")
|
||||
|
||||
|
||||
def test_yaml_marshal_invalid_type(invalid_yaml_data):
|
||||
with pytest.raises(TypeError, match="basic Python types"):
|
||||
marshaller = YamlMarshaller()
|
||||
_ = marshaller.marshal(invalid_yaml_data)
|
||||
|
||||
|
||||
def test_yaml_unmarshal(yaml_data, serialized_yaml_str):
|
||||
marshaller = YamlMarshaller()
|
||||
unmarshalled = marshaller.unmarshal(serialized_yaml_str)
|
||||
assert unmarshalled == yaml_data
|
||||
Reference in New Issue
Block a user