Skip to content

Commit 78665d9

Browse files
authored
Merge pull request lightspeed-core#976 from tisnik/lcore-1051-optional-types-in-tests
LCORE-1051: optional types in tests
2 parents 4ad2e52 + ac291b8 commit 78665d9

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

tests/e2e/features/steps/feedback.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Implementation of common test steps for the feedback API."""
22

3+
from typing import Optional
4+
35
from behave import given, when, step # pyright: ignore[reportAttributeAccessIssue]
46
from behave.runner import Context
57
import requests
@@ -71,7 +73,7 @@ def submit_feedback_without_conversation(context: Context) -> None:
7173

7274

7375
def access_feedback_post_endpoint(
74-
context: Context, conversation_id: str | None
76+
context: Context, conversation_id: Optional[str]
7577
) -> None:
7678
"""Send POST HTTP request with JSON payload to tested service."""
7779
endpoint = "feedback"

tests/unit/cache/test_noop_cache.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Unit tests for NoopCache class."""
22

3+
from typing import Optional
4+
35
import pytest
46

57
from models.cache_entry import CacheEntry
@@ -198,21 +200,21 @@ def test_ready(cache_fixture: NoopCache) -> None:
198200

199201

200202
@pytest.mark.parametrize("uuid", improper_user_uuids)
201-
def test_list_improper_user_id(cache_fixture: NoopCache, uuid: str | None) -> None:
203+
def test_list_improper_user_id(cache_fixture: NoopCache, uuid: Optional[str]) -> None:
202204
"""Test list with invalid user ID."""
203205
with pytest.raises(ValueError, match=f"Invalid user ID {uuid}"):
204206
cache_fixture.list(uuid)
205207

206208

207209
@pytest.mark.parametrize("uuid", improper_user_uuids)
208-
def test_delete_improper_user_id(cache_fixture: NoopCache, uuid: str | None) -> None:
210+
def test_delete_improper_user_id(cache_fixture: NoopCache, uuid: Optional[str]) -> None:
209211
"""Test delete with invalid user ID."""
210212
with pytest.raises(ValueError, match=f"Invalid user ID {uuid}"):
211213
cache_fixture.delete(uuid, CONVERSATION_ID)
212214

213215

214216
@pytest.mark.parametrize("uuid", improper_user_uuids)
215-
def test_get_improper_user_id(cache_fixture: NoopCache, uuid: str | None) -> None:
217+
def test_get_improper_user_id(cache_fixture: NoopCache, uuid: Optional[str]) -> None:
216218
"""Test how improper user ID is handled."""
217219
with pytest.raises(ValueError, match=f"Invalid user ID {uuid}"):
218220
cache_fixture.get(uuid, CONVERSATION_ID)

tests/unit/models/rlsapi/test_requests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint: disable=no-member
22
"""Unit tests for rlsapi v1 request models."""
33

4-
from typing import Any
4+
from typing import Any, Optional
55

66
import pytest
77
from pydantic import BaseModel, ValidationError
@@ -269,7 +269,9 @@ def test_constructor_full(self, sample_request: RlsapiV1InferRequest) -> None:
269269
),
270270
],
271271
)
272-
def test_question_validation(self, question: str | None, error_match: str) -> None:
272+
def test_question_validation(
273+
self, question: Optional[str], error_match: str
274+
) -> None:
273275
"""Test question field validation for various invalid inputs."""
274276
with pytest.raises(ValidationError, match=error_match):
275277
if question is None:

tests/unit/utils/test_responses.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Unit tests for utils/responses.py functions."""
22

33
from types import SimpleNamespace
4-
from typing import Any
4+
from typing import Any, Optional
55

66
import pytest
77

88
from utils.responses import extract_text_from_response_output_item
99

1010

1111
def make_output_item(
12-
item_type: str | None = None, role: str | None = None, content: Any = None
12+
item_type: Optional[str] = None, role: Optional[str] = None, content: Any = None
1313
) -> SimpleNamespace:
1414
"""Create a mock Responses API output item.
1515
@@ -25,7 +25,7 @@ def make_output_item(
2525

2626

2727
def make_content_part(
28-
text: str | None = None, refusal: str | None = None
28+
text: Optional[str] = None, refusal: Optional[str] = None
2929
) -> SimpleNamespace:
3030
"""Create a mock content part for message content.
3131

0 commit comments

Comments
 (0)