forked from Archives/langchain
fix: Blob.from_data mimetype is lost (#5395)
# Fix lost mimetype when using Blob.from_data method The mimetype is lost due to a typo in the class attribue name Fixes # - (no issue opened but I can open one if needed) ## Changes * Fixed typo in name * Added unit-tests to validate the output Blob ## Review @eyurtsev
This commit is contained in:
parent
f77f27163d
commit
8b7721ebbb
@ -137,7 +137,7 @@ class Blob(BaseModel):
|
|||||||
Returns:
|
Returns:
|
||||||
Blob instance
|
Blob instance
|
||||||
"""
|
"""
|
||||||
return cls(data=data, mime_type=mime_type, encoding=encoding, path=path)
|
return cls(data=data, mimetype=mime_type, encoding=encoding, path=path)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Define the blob representation."""
|
"""Define the blob representation."""
|
||||||
|
@ -70,6 +70,29 @@ def test_blob_from_str_path() -> None:
|
|||||||
assert bytes_io.read() == content
|
assert bytes_io.read() == content
|
||||||
|
|
||||||
|
|
||||||
|
def test_blob_from_str_data() -> None:
|
||||||
|
"""Test reading blob from a file path."""
|
||||||
|
content = b"Hello, World!"
|
||||||
|
blob = Blob.from_data(content)
|
||||||
|
assert blob.encoding == "utf-8" # Default encoding
|
||||||
|
assert blob.path is None
|
||||||
|
assert blob.mimetype is None
|
||||||
|
assert blob.source is None
|
||||||
|
assert blob.data == b"Hello, World!"
|
||||||
|
assert blob.as_bytes() == content
|
||||||
|
assert blob.as_string() == "Hello, World!"
|
||||||
|
with blob.as_bytes_io() as bytes_io:
|
||||||
|
assert bytes_io.read() == content
|
||||||
|
|
||||||
|
|
||||||
|
def test_blob_mimetype_from_str_data() -> None:
|
||||||
|
"""Test reading blob from a file path."""
|
||||||
|
content = b"Hello, World!"
|
||||||
|
mimetype = "text/html"
|
||||||
|
blob = Blob.from_data(content, mime_type=mimetype)
|
||||||
|
assert blob.mimetype == mimetype
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path, mime_type, guess_type, expected_mime_type",
|
"path, mime_type, guess_type, expected_mime_type",
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user