You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by su...@apache.org on 2024/02/01 13:05:34 UTC
(opendal) 01/01: fix(bindings/python): sync writer exit close raise error
This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch py-sync-writer-exit-close
in repository https://gitbox.apache.org/repos/asf/opendal.git
commit 568aa5468567f2b03c7af64e1f301e02818c9cc2
Author: suyanhanx <su...@gmail.com>
AuthorDate: Thu Feb 1 21:05:20 2024 +0800
fix(bindings/python): sync writer exit close raise error
Signed-off-by: suyanhanx <su...@gmail.com>
---
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)
+
+@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)