Skip to content

Commit

Permalink
binding(python): Format python code in binding (#1885)
Browse files Browse the repository at this point in the history
Signed-off-by: Manjusaka <[email protected]>
  • Loading branch information
Zheaoli authored Apr 8, 2023
1 parent f1b1526 commit c23e1c5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
15 changes: 13 additions & 2 deletions bindings/python/benchmark/async_opendal_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Config(BaseSettings):
aws_region: str
aws_s3_bucket: str


SETTINGS = Config()

TEST_CASE = [
Expand All @@ -40,7 +41,12 @@ class Config(BaseSettings):


async def opendal_write():
op = opendal.AsyncOperator("s3", bucket=SETTINGS.aws_s3_bucket, region=SETTINGS.aws_region, endpoint=SETTINGS.aws_endpoint)
op = opendal.AsyncOperator(
"s3",
bucket=SETTINGS.aws_s3_bucket,
region=SETTINGS.aws_region,
endpoint=SETTINGS.aws_endpoint,
)
tasks = []
for case in TEST_CASE:
tasks.append(
Expand All @@ -53,7 +59,12 @@ async def opendal_write():


async def opendal_read():
op = opendal.AsyncOperator("s3", bucket=SETTINGS.aws_s3_bucket, region=SETTINGS.aws_region, endpoint=SETTINGS.aws_endpoint)
op = opendal.AsyncOperator(
"s3",
bucket=SETTINGS.aws_s3_bucket,
region=SETTINGS.aws_region,
endpoint=SETTINGS.aws_endpoint,
)
tasks = []
for case in TEST_CASE:
tasks.append(op.read(f"/benchmark/opendal_write/{case['name']}"))
Expand Down
1 change: 0 additions & 1 deletion bindings/python/python/opendal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@

__doc__ = _opendal.__doc__
__all__ = _opendal.__all__

1 change: 0 additions & 1 deletion bindings/python/python/opendal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.


from typing import AsyncIterable, Iterable, Optional

class Error(Exception): ...
Expand Down
16 changes: 14 additions & 2 deletions bindings/python/tests/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,70 @@
from behave.api.async_step import async_run_until_complete
import opendal

@given('A new OpenDAL Blocking Operator')

@given("A new OpenDAL Blocking Operator")
def step_impl(context):
context.op = opendal.Operator("memory")


@when('Blocking write path "{filename}" with content "{content}"')
def step_impl(context, filename, content):
context.op.write(filename, content.encode())


@then('The blocking file "{filename}" should exist')
def step_impl(context, filename):
context.op.stat(filename)


@then('The blocking file "{filename}" entry mode must be file')
def step_impl(context, filename):
assert context.op.stat(filename).mode.is_file()


@then('The blocking file "{filename}" content length must be {size:d}')
def step_impl(context, filename, size):
assert context.op.stat(filename).content_length == size


@then('The blocking file "{filename}" must have content "{content}"')
def step_impl(context, filename, content):
bs = context.op.read(filename)
assert bs == content.encode()

@given('A new OpenDAL Async Operator')

@given("A new OpenDAL Async Operator")
@async_run_until_complete
async def step_impl(context):
context.op = opendal.AsyncOperator("memory")


@when('Async write path "{filename}" with content "{content}"')
@async_run_until_complete
async def step_impl(context, filename, content):
await context.op.write(filename, content.encode())


@then('The async file "{filename}" should exist')
@async_run_until_complete
async def step_impl(context, filename):
await context.op.stat(filename)


@then('The async file "{filename}" entry mode must be file')
@async_run_until_complete
async def step_impl(context, filename):
meta = await context.op.stat(filename)
assert meta.mode.is_file()


@then('The async file "{filename}" content length must be {size:d}')
@async_run_until_complete
async def step_impl(context, filename, size):
meta = await context.op.stat(filename)
assert meta.content_length == size


@then('The async file "{filename}" must have content "{content}"')
@async_run_until_complete
async def step_impl(context, filename, content):
Expand Down

0 comments on commit c23e1c5

Please sign in to comment.