Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
26 changes: 14 additions & 12 deletions bindings/python/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ impl Operator {
.set_source(err)
})
.map_err(format_pyerr)?;
let map = map
.map(|v| {
v.extract::<HashMap<String, String>>()
.expect("must be valid hashmap")
})
.unwrap_or_default();
let map = if let Some(v) = map {
v.iter()
.map(|(k, v)| Ok((k.extract::<String>()?, v.str()?.to_string())))
.collect::<PyResult<HashMap<String, String>>>()?
} else {
HashMap::default()
};

Ok(Operator {
core: build_blocking_operator(scheme, map.clone())?,
Expand Down Expand Up @@ -336,12 +337,13 @@ impl AsyncOperator {
.set_source(err)
})
.map_err(format_pyerr)?;
let map = map
.map(|v| {
v.extract::<HashMap<String, String>>()
.expect("must be valid hashmap")
})
.unwrap_or_default();
let map = if let Some(v) = map {
v.iter()
.map(|(k, v)| Ok((k.extract::<String>()?, v.str()?.to_string())))
.collect::<PyResult<HashMap<String, String>>>()?
} else {
HashMap::default()
};

Ok(AsyncOperator {
core: build_operator(scheme, map.clone())?,
Expand Down
33 changes: 33 additions & 0 deletions bindings/python/tests/test_operator_construction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from pathlib import Path
import opendal
import pytest


def test_operator_new_with_path():
op = opendal.Operator("memory", root=Path("/tmp"))
assert op is not None
assert op.capability().read


@pytest.mark.asyncio
def test_async_operator_new_with_path():
op = opendal.AsyncOperator("memory", root=Path("/tmp"))
assert op is not None
assert op.capability().read
Loading