tests: make 3.12 compatible (#7265)

This commit is contained in:
Tobias Wochinger 2024-02-29 16:11:14 +01:00 committed by GitHub
parent 232544472f
commit 69d5438d6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,12 +1,12 @@
from test.tracing.utils import SpyingSpan, SpyingTracer
from typing import Optional
from unittest.mock import ANY
import pytest
from _pytest.monkeypatch import MonkeyPatch
from haystack import component, Pipeline
from haystack.tracing.tracer import enable_tracing, tracer
from test.tracing.utils import SpyingSpan, SpyingTracer
from haystack import Pipeline, component
from haystack.tracing.tracer import tracer
@component
@ -52,7 +52,7 @@ class TestTracing:
"haystack.component.name": "hello",
"haystack.component.type": "Hello",
"haystack.component.input_types": {"word": "str"},
"haystack.component.input_spec": {"word": {"type": "typing.Union[str, NoneType]", "senders": []}},
"haystack.component.input_spec": {"word": {"type": ANY, "senders": []}},
"haystack.component.output_spec": {"output": {"type": "str", "senders": ["hello2"]}},
"haystack.component.visits": 1,
},
@ -65,9 +65,7 @@ class TestTracing:
"haystack.component.name": "hello2",
"haystack.component.type": "Hello",
"haystack.component.input_types": {"word": "str"},
"haystack.component.input_spec": {
"word": {"type": "typing.Union[str, NoneType]", "senders": ["hello"]}
},
"haystack.component.input_spec": {"word": {"type": ANY, "senders": ["hello"]}},
"haystack.component.output_spec": {"output": {"type": "str", "senders": []}},
"haystack.component.visits": 1,
},
@ -76,6 +74,13 @@ class TestTracing:
),
]
# We need to check the type of the input_spec because it can be rendered differently
# depending on the Python version 🫠
assert spying_tracer.spans[1].tags["haystack.component.input_spec"]["word"]["type"] in [
"typing.Union[str, NoneType]",
"typing.Optional[str]",
]
def test_with_enabled_content_tracing(
self, spying_tracer: SpyingTracer, monkeypatch: MonkeyPatch, pipeline: Pipeline
) -> None:
@ -102,7 +107,7 @@ class TestTracing:
"haystack.component.name": "hello",
"haystack.component.type": "Hello",
"haystack.component.input_types": {"word": "str"},
"haystack.component.input_spec": {"word": {"type": "typing.Union[str, NoneType]", "senders": []}},
"haystack.component.input_spec": {"word": {"type": ANY, "senders": []}},
"haystack.component.output_spec": {"output": {"type": "str", "senders": ["hello2"]}},
"haystack.component.input": {"word": "world"},
"haystack.component.visits": 1,
@ -117,9 +122,7 @@ class TestTracing:
"haystack.component.name": "hello2",
"haystack.component.type": "Hello",
"haystack.component.input_types": {"word": "str"},
"haystack.component.input_spec": {
"word": {"type": "typing.Union[str, NoneType]", "senders": ["hello"]}
},
"haystack.component.input_spec": {"word": {"type": ANY, "senders": ["hello"]}},
"haystack.component.output_spec": {"output": {"type": "str", "senders": []}},
"haystack.component.input": {"word": "Hello, world!"},
"haystack.component.visits": 1,