chore: improve opendal storage and ensure closing file after reading files in load_stream method (#25874)

This commit is contained in:
Bowen Liang
2025-09-18 14:09:19 +08:00
committed by GitHub
parent 87aa070486
commit b2e4107c17
5 changed files with 40 additions and 28 deletions

View File

@@ -57,12 +57,19 @@ class TestOpenDAL:
def test_load_stream(self):
"""Test loading data as a stream."""
filename = get_example_filename()
data = get_example_data()
chunks = 5
chunk_size = 4096
data = get_example_data(length=chunk_size * chunks)
self.storage.save(filename, data)
generator = self.storage.load_stream(filename)
assert isinstance(generator, Generator)
assert next(generator) == data
for i in range(chunks):
fetched = next(generator)
assert len(fetched) == chunk_size
assert fetched == data[i * chunk_size : (i + 1) * chunk_size]
with pytest.raises(StopIteration):
next(generator)
def test_download(self):
"""Test downloading data to a file."""