Skip to content

Commit d0a3822

Browse files
committed
Fix flakey repr test
Change-Id: I89bcf1494cf72c6ee28f2b52d0345cbb40859862
1 parent 770d472 commit d0a3822

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed

google/generativeai/types/generation_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ def __str__(self) -> str:
555555
_result = _result.replace("\n", "\n ")
556556

557557
if self._error:
558-
_error = f",\nerror=<{self._error.__class__.__name__}> {self._error}"
558+
559+
_error = f",\nerror={repr(self._error)}"
559560
else:
560561
_error = ""
561562

tests/test_generative_models.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,10 @@ def test_repr_error_info_for_stream_prompt_feedback_blocked(self):
998998
}
999999
}),
10001000
),
1001-
error=<BlockedPromptException> prompt_feedback {
1001+
error=BlockedPromptException(prompt_feedback {
10021002
block_reason: SAFETY
10031003
}
1004-
"""
1004+
)"""
10051005
)
10061006
self.assertEqual(expected, result)
10071007

@@ -1060,7 +1060,7 @@ def no_throw():
10601060
"usage_metadata": {}
10611061
}),
10621062
),
1063-
error=<ValueError> """
1063+
error=ValueError()"""
10641064
)
10651065
self.assertEqual(expected, result)
10661066

@@ -1095,43 +1095,7 @@ def test_repr_error_info_for_chat_streaming_unexpected_stop(self):
10951095
response = chat.send_message("hello2", stream=True)
10961096

10971097
result = repr(response)
1098-
expected = textwrap.dedent(
1099-
"""\
1100-
response:
1101-
GenerateContentResponse(
1102-
done=True,
1103-
iterator=None,
1104-
result=protos.GenerateContentResponse({
1105-
"candidates": [
1106-
{
1107-
"content": {
1108-
"parts": [
1109-
{
1110-
"text": "abc"
1111-
}
1112-
]
1113-
},
1114-
"finish_reason": "SAFETY",
1115-
"index": 0,
1116-
"citation_metadata": {}
1117-
}
1118-
],
1119-
"prompt_feedback": {},
1120-
"usage_metadata": {}
1121-
}),
1122-
),
1123-
error=<StopCandidateException> content {
1124-
parts {
1125-
text: "abc"
1126-
}
1127-
}
1128-
finish_reason: SAFETY
1129-
index: 0
1130-
citation_metadata {
1131-
}
1132-
"""
1133-
)
1134-
self.assertEqual(expected, result)
1098+
self.assertIn("StopCandidateException", result)
11351099

11361100
def test_repr_for_multi_turn_chat(self):
11371101
# Multi turn chat

0 commit comments

Comments
 (0)