Xuanwo commented on code in PR #3397: URL: https://github.com/apache/incubator-opendal/pull/3397#discussion_r1376320554
########## bindings/python/tests/test_write.py: ########## @@ -0,0 +1,132 @@ +# 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. + +import os +from uuid import uuid4 +from random import randint + +import pytest + + [email protected]_capability("write", "delete", "stat") +def test_sync_write(service_name, operator, async_operator): + size = randint(1, 1024) + filename = f"test_file_{str(uuid4())}.txt" + content = os.urandom(size) + size = len(content) + operator.write(filename, content) + metadata = operator.stat(filename) + assert metadata is not None + assert metadata.mode.is_file() + assert metadata.content_length == size + + operator.delete(filename) + + [email protected] [email protected]_capability("write", "delete", "stat") +async def test_async_write(service_name, operator, async_operator): + size = randint(1, 1024) + filename = f"test_file_{str(uuid4())}.txt" + content = os.urandom(size) + size = len(content) + await async_operator.write(filename, content) + metadata = await async_operator.stat(filename) + assert metadata is not None + assert metadata.mode.is_file() + assert metadata.content_length == size + + await async_operator.delete(filename) + + [email protected]_capability("write", "delete", "stat") +def test_sync_write_with_non_ascii_name(service_name, operator, async_operator): + size = randint(1, 1024) + filename = f"βπ±δΈζ_{str(uuid4())}.test" Review Comment: Please don't add test case like this. We are still working on solution about this. ########## .github/actions/behavior_test_binding_python/action.yaml: ########## @@ -0,0 +1,62 @@ +# 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. + +name: Test Binding Python +description: 'Test Core with given setup and service' +inputs: + setup: + description: "The setup action for test" + service: + description: "The service to test" + feature: + description: "The feature to test" + +runs: + using: "composite" + steps: + - name: Setup + shell: bash + run: | + mkdir -p ./dynamic_test_binding_python && + cat <<EOF >./dynamic_test_binding_python/action.yml + runs: + using: composite + steps: + - name: Setup Test + uses: ./.github/services/${{ inputs.service }}/${{ inputs.setup }} + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Build with maturin + shell: bash + working-directory: "bindings/python" + run: | + python -m venv venv + source venv/bin/activate + pip install maturin[patchelf] + maturin develop -E test -F ${{ inputs.feature }} Review Comment: It's better to move those part to `Behavior Test Binding Python` instead for better readability and maintaince. Keep those trick part as small as possible. ########## bindings/python/tests/conftest.py: ########## @@ -15,9 +15,66 @@ # specific language governing permissions and limitations # under the License. +import os + from dotenv import load_dotenv import pytest +import opendal load_dotenv() pytest_plugins = ("pytest_asyncio",) + + +def pytest_configure(config): + # register an additional marker + config.addinivalue_line( + "markers", + "need_capability(*capability): mark test to run only on named capability", + ) + + [email protected]() +def service_name(): Review Comment: What will happen if `OPENDAL_TEST` is empty or none? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
