-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds bytesIO/bytes input for to.file
This helps when we want to save binary data
- Loading branch information
1 parent
99c3ee1
commit c44bad7
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import io | ||
import pathlib | ||
|
||
import pytest | ||
|
||
from hamilton.io.default_data_loaders import RawFileDataSaverBytes | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data", | ||
[ | ||
b"test", | ||
io.BytesIO(b"test"), | ||
], | ||
) | ||
def test_raw_file_adapter(data, tmp_path: pathlib.Path) -> None: | ||
path = tmp_path / "test" | ||
|
||
writer = RawFileDataSaverBytes(path=path) | ||
writer.save_data(data) | ||
|
||
with open(path, "rb") as f: | ||
data2 = f.read() | ||
|
||
data_processed = data if type(data) is bytes else data.getvalue() | ||
assert data_processed == data2 |