Skip to content

Commit e0c653e

Browse files
committed
Remove type casting in test file
1 parent da6aa51 commit e0c653e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

tests/unit/llm/test_openai_llm.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
from unittest.mock import MagicMock, Mock, patch
16-
from typing import Any, cast
1716

1817
import openai
1918
import pytest
@@ -88,9 +87,9 @@ def test_openai_llm_with_message_history_happy_path(mock_import: Mock) -> None:
8887
assert res.content == "openai chat response"
8988
message_history.append({"role": "user", "content": question})
9089
# Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
91-
cast(Any, llm.client.chat.completions.create).assert_called_once()
90+
llm.client.chat.completions.create.assert_called_once()
9291
# Check call arguments individually
93-
call_args = cast(Any, llm.client.chat.completions.create).call_args[
92+
call_args = llm.client.chat.completions.create.call_args[
9493
1
9594
] # Get the keyword arguments
9695
assert call_args["messages"] == message_history
@@ -124,9 +123,9 @@ def test_openai_llm_with_message_history_and_system_instruction(
124123
messages.extend(message_history)
125124
messages.append({"role": "user", "content": question})
126125
# Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
127-
cast(Any, llm.client.chat.completions.create).assert_called_once()
126+
llm.client.chat.completions.create.assert_called_once()
128127
# Check call arguments individually
129-
call_args = cast(Any, llm.client.chat.completions.create).call_args[
128+
call_args = llm.client.chat.completions.create.call_args[
130129
1
131130
] # Get the keyword arguments
132131
assert call_args["messages"] == messages
@@ -241,9 +240,9 @@ def test_openai_llm_invoke_with_tools_with_message_history(
241240
# Verify the correct messages were passed
242241
message_history.append({"role": "user", "content": question})
243242
# Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
244-
cast(Any, llm.client.chat.completions.create).assert_called_once()
243+
llm.client.chat.completions.create.assert_called_once()
245244
# Check call arguments individually
246-
call_args = cast(Any, llm.client.chat.completions.create).call_args[
245+
call_args = llm.client.chat.completions.create.call_args[
247246
1
248247
] # Get the keyword arguments
249248
assert call_args["messages"] == message_history
@@ -298,9 +297,9 @@ def test_openai_llm_invoke_with_tools_with_system_instruction(
298297
messages = [{"role": "system", "content": system_instruction}]
299298
messages.append({"role": "user", "content": "my text"})
300299
# Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
301-
cast(Any, llm.client.chat.completions.create).assert_called_once()
300+
llm.client.chat.completions.create.assert_called_once()
302301
# Check call arguments individually
303-
call_args = cast(Any, llm.client.chat.completions.create).call_args[
302+
call_args = llm.client.chat.completions.create.call_args[
304303
1
305304
] # Get the keyword arguments
306305
assert call_args["messages"] == messages
@@ -385,9 +384,9 @@ def test_azure_openai_llm_with_message_history_happy_path(mock_import: Mock) ->
385384
assert res.content == "openai chat response"
386385
message_history.append({"role": "user", "content": question})
387386
# Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
388-
cast(Any, llm.client.chat.completions.create).assert_called_once()
387+
llm.client.chat.completions.create.assert_called_once()
389388
# Check call arguments individually
390-
call_args = cast(Any, llm.client.chat.completions.create).call_args[
389+
call_args = llm.client.chat.completions.create.call_args[
391390
1
392391
] # Get the keyword arguments
393392
assert call_args["messages"] == message_history

0 commit comments

Comments
 (0)