Skip to content

Commit fdd8932

Browse files
committed
add test for filepart.has_content
1 parent 5e48975 commit fdd8932

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ class FilePart:
10601060

10611061
def has_content(self) -> bool:
10621062
"""Return `True` if the file content is non-empty."""
1063-
return bool(self.content.data) # pragma: no cover
1063+
return bool(self.content.data)
10641064

10651065
__repr__ = _utils.dataclasses_no_defaults_repr
10661066

tests/test_messages.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ def test_pre_usage_refactor_messages_deserializable():
422422
)
423423

424424

425+
def test_file_part_has_content():
426+
filepart = FilePart(content=BinaryContent(data=b'', media_type='application/pdf'))
427+
assert not filepart.has_content()
428+
429+
filepart.content.data = b'not empty'
430+
assert filepart.has_content()
431+
432+
425433
def test_file_part_serialization_roundtrip():
426434
# Verify that a serialized BinaryImage doesn't come back as a BinaryContent.
427435
messages: list[ModelMessage] = [

0 commit comments

Comments
 (0)