Skip to content

Commit 88bfb4e

Browse files
committed
fix: black
1 parent c9548a7 commit 88bfb4e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

posthog/test/ai/langchain/test_callbacks.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,13 @@ async def sleep(x): # -> Any:
10331033

10341034
def test_error(mock_client):
10351035
prompt = ChatPromptTemplate.from_messages([("user", "Foo")])
1036-
# Configure the model to raise an exception by passing an error message
1037-
model = FakeMessagesListChatModel(responses=[AIMessage(content="Bar")], error="Test error")
1036+
model = FakeMessagesListChatModel(responses=[AIMessage(content="Bar")])
10381037
chain = prompt | model
10391038
callbacks = CallbackHandler(mock_client)
1040-
with pytest.raises(Exception):
1041-
chain.invoke({}, config={"callbacks": [callbacks]})
1039+
1040+
with patch.object(FakeMessagesListChatModel, 'invoke', side_effect=Exception("Test error")):
1041+
with pytest.raises(Exception):
1042+
chain.invoke({}, config={"callbacks": [callbacks]})
10421043

10431044
assert mock_client.capture.call_count == 1
10441045
call_args = mock_client.capture.call_args[1]
@@ -1052,8 +1053,9 @@ def test_http_error(mock_client):
10521053
model = FakeMessagesListChatModel(responses=[AIMessage(content="Bar")], http_status=400)
10531054
chain = prompt | model
10541055
callbacks = CallbackHandler(mock_client)
1055-
with pytest.raises(Exception):
1056-
chain.invoke({}, config={"callbacks": [callbacks]})
1056+
with patch.object(FakeMessagesListChatModel, 'invoke', side_effect=Exception(status_code=400)):
1057+
with pytest.raises(Exception):
1058+
chain.invoke({}, config={"callbacks": [callbacks]})
10571059

10581060
assert mock_client.capture.call_count == 1
10591061
call_args = mock_client.capture.call_args[1]

0 commit comments

Comments
 (0)