From f0d68e204e91484bdaff79fbe5b72c181337c546 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sun, 9 Apr 2023 00:19:53 +0800 Subject: [PATCH] binding(python): Format python code in binding Signed-off-by: Manjusaka --- .../python/benchmark/async_opendal_benchmark.py | 15 +++++++++++++-- bindings/python/python/opendal/__init__.py | 1 - bindings/python/python/opendal/__init__.pyi | 1 - bindings/python/tests/steps/binding.py | 16 ++++++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/bindings/python/benchmark/async_opendal_benchmark.py b/bindings/python/benchmark/async_opendal_benchmark.py index 31c978dacd7..368eaadbc24 100644 --- a/bindings/python/benchmark/async_opendal_benchmark.py +++ b/bindings/python/benchmark/async_opendal_benchmark.py @@ -26,6 +26,7 @@ class Config(BaseSettings): aws_region: str aws_s3_bucket: str + SETTINGS = Config() TEST_CASE = [ @@ -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( @@ -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']}")) diff --git a/bindings/python/python/opendal/__init__.py b/bindings/python/python/opendal/__init__.py index 0ba1f35536c..35bc589a577 100644 --- a/bindings/python/python/opendal/__init__.py +++ b/bindings/python/python/opendal/__init__.py @@ -20,4 +20,3 @@ __doc__ = _opendal.__doc__ __all__ = _opendal.__all__ - diff --git a/bindings/python/python/opendal/__init__.pyi b/bindings/python/python/opendal/__init__.pyi index 7d90dd8bb50..2f82aed6d6f 100644 --- a/bindings/python/python/opendal/__init__.pyi +++ b/bindings/python/python/opendal/__init__.pyi @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. - from typing import AsyncIterable, Iterable, Optional class Error(Exception): ... diff --git a/bindings/python/tests/steps/binding.py b/bindings/python/tests/steps/binding.py index feb36e982fa..4d343eaaffc 100644 --- a/bindings/python/tests/steps/binding.py +++ b/bindings/python/tests/steps/binding.py @@ -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):