Skip to content

Commit

Permalink
fix(bindings/python): Fix the semantic of size argument for python …
Browse files Browse the repository at this point in the history
…`File::read`
  • Loading branch information
reswqa committed Mar 14, 2024
1 parent 7533627 commit dbac7a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions bindings/python/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ impl File {

let buffer = match size {
Some(size) => {
let bs = reader
.read_exact(size)
let bs = reader.read(size)
.map_err(|err| PyIOError::new_err(err.to_string()))?;
bs.to_vec()
}
Expand Down Expand Up @@ -241,7 +240,7 @@ impl AsyncFile {
let buffer = match size {
Some(size) => {
let buffer = reader
.read_exact(size)
.read(size)
.await
.map_err(|err| PyIOError::new_err(err.to_string()))?;
buffer.to_vec()
Expand Down
10 changes: 10 additions & 0 deletions bindings/python/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def test_sync_reader(service_name, operator, async_operator):
assert read_content is not None
assert read_content == content

with operator.open(filename, "rb") as reader:
read_content = reader.read(size + 1)
assert read_content is not None
assert read_content == content

operator.delete(filename)


Expand Down Expand Up @@ -80,6 +85,11 @@ async def test_async_reader(service_name, operator, async_operator):
assert read_content is not None
assert read_content == content

async with await async_operator.open(filename, "rb") as reader:
read_content = await reader.read(size + 1)
assert read_content is not None
assert read_content == content

await async_operator.delete(filename)


Expand Down

0 comments on commit dbac7a8

Please sign in to comment.