Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tstadel committed Dec 28, 2024
1 parent d12340c commit 765525c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion haystack/dataclasses/byte_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ def __str__(self) -> str:
"""
Returns a string representation of the ByteStream, truncating the data to 1KB.
"""
truncated = self.data[:1021] + b"..." if len(self.data) > 1024 else self.data
truncated = self.data[:1024] + b"..." if len(self.data) > 1024 else self.data
return f"ByteStream(data={truncated!r}, mime_type={self.mime_type!r}, meta={self.meta!r})"
7 changes: 7 additions & 0 deletions test/dataclasses/test_byte_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ def test_to_file(tmp_path, request):
ByteStream(test_str.encode()).to_file(test_path)
with open(test_path, "rb") as fd:
assert fd.read().decode() == test_str


def test_str_truncation():
test_str = "1234567890" * 1000
b = ByteStream.from_string(test_str, mime_type="text/plain", meta={"foo": "bar"})
string_repr = str(b)
assert len(string_repr) < 1200

0 comments on commit 765525c

Please sign in to comment.