This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new f4a302727a fix(bindings/python): sync writer exit close raise error
(#4127)
f4a302727a is described below
commit f4a302727ac76de11cd299d5afc2f153c30eff52
Author: Suyan <[email protected]>
AuthorDate: Thu Feb 1 21:36:45 2024 +0800
fix(bindings/python): sync writer exit close raise error (#4127)
---
bindings/python/src/file.rs | 13 +++++++++----
bindings/python/tests/conftest.py | 2 +-
bindings/python/tests/test_write.py | 27 ++++++++++++++++++++++++++-
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs
index b7db1997d5..692bb4896d 100644
--- a/bindings/python/src/file.rs
+++ b/bindings/python/src/file.rs
@@ -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;
@@ -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
@@ -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()
}
}
diff --git a/bindings/python/tests/conftest.py
b/bindings/python/tests/conftest.py
index 5e0f4ccfb4..86fa77f8a9 100644
--- a/bindings/python/tests/conftest.py
+++ b/bindings/python/tests/conftest.py
@@ -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
diff --git a/bindings/python/tests/test_write.py
b/bindings/python/tests/test_write.py
index e98c6e959b..7d01910eaf 100644
--- a/bindings/python/tests/test_write.py
+++ b/bindings/python/tests/test_write.py
@@ -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)
+
[email protected]
[email protected]_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)
+
[email protected]_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)