haystack/test/tracing/test_utils.py
Tobias Wochinger 41b93108c0
feat: allow content tracing (#7066)
* feat: implement content tracing capability

* feat: trace component input/output

* chore: extend type serialization to classes with `to_dict`

* docs: add option for content tracing

* style: remove unused import

* chore: add more tags

* style: ignore typing

* fix: fix tagging of types
2024-02-23 11:52:54 +01:00

44 lines
1.4 KiB
Python

from typing import Any, Union
import pytest
from haystack import Document
from haystack.tracing import utils
class NonSerializableClass:
def __str__(self) -> str:
return "NonSerializableClass"
class TestTypeCoercion:
@pytest.mark.parametrize(
"raw_value,expected_tag_value",
[
(1, 1),
(1.0, 1.0),
(True, True),
(None, ""),
("string", "string"),
([1, 2, 3], "[1, 2, 3]"),
({"key": "value"}, '{"key": "value"}'),
(NonSerializableClass(), "NonSerializableClass"),
(
Document(id="1", content="text"),
'{"id": "1", "content": "text", "dataframe": null, "blob": null, "score": null, "embedding": null}',
),
(
[Document(id="1", content="text")],
'[{"id": "1", "content": "text", "dataframe": null, "blob": null, "score": null, "embedding": null}]',
),
(
{"key": Document(id="1", content="text")},
'{"key": {"id": "1", "content": "text", "dataframe": null, "blob": null, "score": null, "embedding": null}}',
),
],
)
def test_type_coercion(self, raw_value: Any, expected_tag_value: Union[bool, str, int, float]) -> None:
coerced_value = utils.coerce_tag_value(raw_value)
assert coerced_value == expected_tag_value