Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bindings/python): sync writer exit close raise error #4127

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions bindings/python/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

// Remove this allow after <https://github.com/rust-lang/rust-clippy/issues/12039> fixed.
// Remove this `allow` after <https://github.com/rust-lang/rust-clippy/issues/12039> fixed.
#![allow(clippy::unnecessary_fallible_conversions)]

use std::io::Read;
Expand Down Expand Up @@ -118,7 +118,7 @@ impl File {
}

/// Change the stream position to the given byte offset.
/// offset is interpreted relative to the position indicated by `whence`.
/// Offset is interpreted relative to the position indicated by `whence`.
/// The default value for whence is `SEEK_SET`. Values for `whence` are:
///
/// * `SEEK_SET` or `0` – start of the stream (the default); offset should be zero or positive
Expand Down Expand Up @@ -188,8 +188,13 @@ impl File {
slf
}

pub fn __exit__(&mut self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) {
let _ = self.close();
pub fn __exit__(
&mut self,
_exc_type: PyObject,
_exc_value: PyObject,
_traceback: PyObject,
) -> PyResult<()> {
self.close()
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setup_config(service_name):
True if os.environ.get("OPENDAL_DISABLE_RANDOM_ROOT") == "true" else False
)
if not disable_random_root:
config["root"] = f"{config.get('root', '/')}{str(uuid4())}/"
config["root"] = f"{config.get('root', '/')}/{str(uuid4())}/"
return config


Expand Down
27 changes: 26 additions & 1 deletion bindings/python/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,29 @@ async def test_async_delete(service_name, operator, async_operator):
await async_operator.write(filename, content)
await async_operator.delete(filename)
with pytest.raises(NotFound):
await operator.stat(filename)
await async_operator.stat(filename)

@pytest.mark.asyncio
@pytest.mark.need_capability("write", "delete")
async def test_async_writer(service_name, operator, async_operator):
size = randint(1, 1024)
filename = f"test_file_{str(uuid4())}.txt"
content = os.urandom(size)
f = await async_operator.open(filename, "wb")
await f.write(content)
await f.close()
await async_operator.delete(filename)
with pytest.raises(NotFound):
await async_operator.stat(filename)

@pytest.mark.need_capability("write", "delete")
def test_sync_writer(service_name, operator, async_operator):
size = randint(1, 1024)
filename = f"test_file_{str(uuid4())}.txt"
content = os.urandom(size)
f = operator.open(filename, "wb")
f.write(content)
f.close()
operator.delete(filename)
with pytest.raises(NotFound):
operator.stat(filename)
Loading