You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Zheaoli (via GitHub)" <gi...@apache.org> on 2023/10/12 18:26:56 UTC
[PR] refactor: Refactor pytest name [incubator-opendal]
Zheaoli opened a new pull request, #3263:
URL: https://github.com/apache/incubator-opendal/pull/3263
(no comment)
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: Refactor pytest from class based test to function based [incubator-opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #3263:
URL: https://github.com/apache/incubator-opendal/pull/3263#discussion_r1357721011
##########
bindings/python/tests/test_services.py:
##########
@@ -23,191 +23,211 @@
import opendal
import pytest
+RENAME_MAP = {
+ "service_memory": "memory",
+ "service_s3": "s3",
+ "service_fs": "fs",
+}
-class AbstractTestSuite(ABC):
- service_name = ""
-
- def setup_method(self):
- # Read arguments from envs.
- prefix = f"opendal_{self.service_name}_"
- self.config = {}
- for key in os.environ.keys():
- if key.lower().startswith(prefix):
- self.config[key[len(prefix) :].lower()] = os.environ.get(key)
-
- # Check if current test be enabled.
- test_flag = self.config.get("test", "")
- if test_flag != "on" and test_flag != "true":
- raise ValueError(f"Service {self.service_name} test is not enabled.")
-
- self.operator = opendal.Operator(self.service_name, **self.config)
- self.async_operator = opendal.AsyncOperator(self.service_name, **self.config)
-
- def test_sync_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- read_content = self.operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- read_content = await self.async_operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- await self.async_operator.delete(filename)
-
- def test_sync_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- await self.async_operator.delete(filename)
-
- self.operator.delete(filename)
-
- def test_sync_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- self.operator.read(str(uuid4()))
-
- @pytest.mark.asyncio
- async def test_async_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- await self.async_operator.read(str(uuid4()))
-
- def test_sync_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- self.operator.create_dir(path)
- metadata = self.operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- self.operator.delete(path)
-
- @pytest.mark.asyncio
- async def test_async_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- await self.async_operator.create_dir(path)
- metadata = await self.async_operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- await self.async_operator.delete(path)
-
- def test_sync_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- self.operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- self.operator.stat(filename)
-
- @pytest.mark.asyncio
- async def test_async_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- await self.async_operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- await self.operator.stat(filename)
-
-
-class TestS3(AbstractTestSuite):
- service_name = "s3"
-
-
-class TestFS(AbstractTestSuite):
- service_name = "fs"
-
-
-class TestMemory(AbstractTestSuite):
- service_name = "memory"
+
+@pytest.fixture()
Review Comment:
> the function based can do the same thing
I don't understand why we need to completely change our approach just to accomplish the same thing. Are there any other benefits of using function-based tests?
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: Refactor pytest from class based test to function based [incubator-opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #3263:
URL: https://github.com/apache/incubator-opendal/pull/3263#issuecomment-1760739612
I would rather close this PR as there hasn't been much improvement so far.
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: Refactor pytest from class based test to function based [incubator-opendal]
Posted by "Zheaoli (via GitHub)" <gi...@apache.org>.
Zheaoli commented on code in PR #3263:
URL: https://github.com/apache/incubator-opendal/pull/3263#discussion_r1357719235
##########
bindings/python/tests/test_services.py:
##########
@@ -23,191 +23,211 @@
import opendal
import pytest
+RENAME_MAP = {
+ "service_memory": "memory",
+ "service_s3": "s3",
+ "service_fs": "fs",
+}
-class AbstractTestSuite(ABC):
- service_name = ""
-
- def setup_method(self):
- # Read arguments from envs.
- prefix = f"opendal_{self.service_name}_"
- self.config = {}
- for key in os.environ.keys():
- if key.lower().startswith(prefix):
- self.config[key[len(prefix) :].lower()] = os.environ.get(key)
-
- # Check if current test be enabled.
- test_flag = self.config.get("test", "")
- if test_flag != "on" and test_flag != "true":
- raise ValueError(f"Service {self.service_name} test is not enabled.")
-
- self.operator = opendal.Operator(self.service_name, **self.config)
- self.async_operator = opendal.AsyncOperator(self.service_name, **self.config)
-
- def test_sync_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- read_content = self.operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- read_content = await self.async_operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- await self.async_operator.delete(filename)
-
- def test_sync_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- await self.async_operator.delete(filename)
-
- self.operator.delete(filename)
-
- def test_sync_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- self.operator.read(str(uuid4()))
-
- @pytest.mark.asyncio
- async def test_async_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- await self.async_operator.read(str(uuid4()))
-
- def test_sync_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- self.operator.create_dir(path)
- metadata = self.operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- self.operator.delete(path)
-
- @pytest.mark.asyncio
- async def test_async_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- await self.async_operator.create_dir(path)
- metadata = await self.async_operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- await self.async_operator.delete(path)
-
- def test_sync_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- self.operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- self.operator.stat(filename)
-
- @pytest.mark.asyncio
- async def test_async_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- await self.async_operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- await self.operator.stat(filename)
-
-
-class TestS3(AbstractTestSuite):
- service_name = "s3"
-
-
-class TestFS(AbstractTestSuite):
- service_name = "fs"
-
-
-class TestMemory(AbstractTestSuite):
- service_name = "memory"
+
+@pytest.fixture()
Review Comment:
OKKKK,the function based can do the same thing, wait a liite bit
##########
bindings/python/tests/test_services.py:
##########
@@ -23,191 +23,211 @@
import opendal
import pytest
+RENAME_MAP = {
+ "service_memory": "memory",
+ "service_s3": "s3",
+ "service_fs": "fs",
+}
-class AbstractTestSuite(ABC):
- service_name = ""
-
- def setup_method(self):
- # Read arguments from envs.
- prefix = f"opendal_{self.service_name}_"
- self.config = {}
- for key in os.environ.keys():
- if key.lower().startswith(prefix):
- self.config[key[len(prefix) :].lower()] = os.environ.get(key)
-
- # Check if current test be enabled.
- test_flag = self.config.get("test", "")
- if test_flag != "on" and test_flag != "true":
- raise ValueError(f"Service {self.service_name} test is not enabled.")
-
- self.operator = opendal.Operator(self.service_name, **self.config)
- self.async_operator = opendal.AsyncOperator(self.service_name, **self.config)
-
- def test_sync_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- read_content = self.operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- read_content = await self.async_operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- await self.async_operator.delete(filename)
-
- def test_sync_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- await self.async_operator.delete(filename)
-
- self.operator.delete(filename)
-
- def test_sync_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- self.operator.read(str(uuid4()))
-
- @pytest.mark.asyncio
- async def test_async_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- await self.async_operator.read(str(uuid4()))
-
- def test_sync_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- self.operator.create_dir(path)
- metadata = self.operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- self.operator.delete(path)
-
- @pytest.mark.asyncio
- async def test_async_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- await self.async_operator.create_dir(path)
- metadata = await self.async_operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- await self.async_operator.delete(path)
-
- def test_sync_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- self.operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- self.operator.stat(filename)
-
- @pytest.mark.asyncio
- async def test_async_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- await self.async_operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- await self.operator.stat(filename)
-
-
-class TestS3(AbstractTestSuite):
- service_name = "s3"
-
-
-class TestFS(AbstractTestSuite):
- service_name = "fs"
-
-
-class TestMemory(AbstractTestSuite):
- service_name = "memory"
+
+@pytest.fixture()
Review Comment:
OKKKK,the function based can do the same thing, wait a liite bit
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: Refactor pytest from class based test to function based [incubator-opendal]
Posted by "Zheaoli (via GitHub)" <gi...@apache.org>.
Zheaoli commented on code in PR #3263:
URL: https://github.com/apache/incubator-opendal/pull/3263#discussion_r1357729805
##########
bindings/python/tests/test_services.py:
##########
@@ -23,191 +23,211 @@
import opendal
import pytest
+RENAME_MAP = {
+ "service_memory": "memory",
+ "service_s3": "s3",
+ "service_fs": "fs",
+}
-class AbstractTestSuite(ABC):
- service_name = ""
-
- def setup_method(self):
- # Read arguments from envs.
- prefix = f"opendal_{self.service_name}_"
- self.config = {}
- for key in os.environ.keys():
- if key.lower().startswith(prefix):
- self.config[key[len(prefix) :].lower()] = os.environ.get(key)
-
- # Check if current test be enabled.
- test_flag = self.config.get("test", "")
- if test_flag != "on" and test_flag != "true":
- raise ValueError(f"Service {self.service_name} test is not enabled.")
-
- self.operator = opendal.Operator(self.service_name, **self.config)
- self.async_operator = opendal.AsyncOperator(self.service_name, **self.config)
-
- def test_sync_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- read_content = self.operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- read_content = await self.async_operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- await self.async_operator.delete(filename)
-
- def test_sync_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- await self.async_operator.delete(filename)
-
- self.operator.delete(filename)
-
- def test_sync_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- self.operator.read(str(uuid4()))
-
- @pytest.mark.asyncio
- async def test_async_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- await self.async_operator.read(str(uuid4()))
-
- def test_sync_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- self.operator.create_dir(path)
- metadata = self.operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- self.operator.delete(path)
-
- @pytest.mark.asyncio
- async def test_async_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- await self.async_operator.create_dir(path)
- metadata = await self.async_operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- await self.async_operator.delete(path)
-
- def test_sync_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- self.operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- self.operator.stat(filename)
-
- @pytest.mark.asyncio
- async def test_async_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- await self.async_operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- await self.operator.stat(filename)
-
-
-class TestS3(AbstractTestSuite):
- service_name = "s3"
-
-
-class TestFS(AbstractTestSuite):
- service_name = "fs"
-
-
-class TestMemory(AbstractTestSuite):
- service_name = "memory"
+
+@pytest.fixture()
Review Comment:

--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: Refactor pytest from class based test to function based [incubator-opendal]
Posted by "Zheaoli (via GitHub)" <gi...@apache.org>.
Zheaoli closed pull request #3263: refactor: Refactor pytest from class based test to function based
URL: https://github.com/apache/incubator-opendal/pull/3263
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: Refactor pytest from class based test to function based [incubator-opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #3263:
URL: https://github.com/apache/incubator-opendal/pull/3263#discussion_r1357731738
##########
bindings/python/tests/test_services.py:
##########
@@ -23,191 +23,211 @@
import opendal
import pytest
+RENAME_MAP = {
+ "service_memory": "memory",
+ "service_s3": "s3",
+ "service_fs": "fs",
+}
-class AbstractTestSuite(ABC):
- service_name = ""
-
- def setup_method(self):
- # Read arguments from envs.
- prefix = f"opendal_{self.service_name}_"
- self.config = {}
- for key in os.environ.keys():
- if key.lower().startswith(prefix):
- self.config[key[len(prefix) :].lower()] = os.environ.get(key)
-
- # Check if current test be enabled.
- test_flag = self.config.get("test", "")
- if test_flag != "on" and test_flag != "true":
- raise ValueError(f"Service {self.service_name} test is not enabled.")
-
- self.operator = opendal.Operator(self.service_name, **self.config)
- self.async_operator = opendal.AsyncOperator(self.service_name, **self.config)
-
- def test_sync_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- read_content = self.operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- read_content = await self.async_operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- await self.async_operator.delete(filename)
-
- def test_sync_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- await self.async_operator.delete(filename)
-
- self.operator.delete(filename)
-
- def test_sync_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- self.operator.read(str(uuid4()))
-
- @pytest.mark.asyncio
- async def test_async_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- await self.async_operator.read(str(uuid4()))
-
- def test_sync_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- self.operator.create_dir(path)
- metadata = self.operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- self.operator.delete(path)
-
- @pytest.mark.asyncio
- async def test_async_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- await self.async_operator.create_dir(path)
- metadata = await self.async_operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- await self.async_operator.delete(path)
-
- def test_sync_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- self.operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- self.operator.stat(filename)
-
- @pytest.mark.asyncio
- async def test_async_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- await self.async_operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- await self.operator.stat(filename)
-
-
-class TestS3(AbstractTestSuite):
- service_name = "s3"
-
-
-class TestFS(AbstractTestSuite):
- service_name = "fs"
-
-
-class TestMemory(AbstractTestSuite):
- service_name = "memory"
+
+@pytest.fixture()
Review Comment:
But having a class make it more clear about the tests belongings:

--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: Refactor pytest from class based test to function based [incubator-opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #3263:
URL: https://github.com/apache/incubator-opendal/pull/3263#discussion_r1357694336
##########
bindings/python/tests/test_services.py:
##########
@@ -23,191 +23,211 @@
import opendal
import pytest
+RENAME_MAP = {
+ "service_memory": "memory",
+ "service_s3": "s3",
+ "service_fs": "fs",
+}
-class AbstractTestSuite(ABC):
- service_name = ""
-
- def setup_method(self):
- # Read arguments from envs.
- prefix = f"opendal_{self.service_name}_"
- self.config = {}
- for key in os.environ.keys():
- if key.lower().startswith(prefix):
- self.config[key[len(prefix) :].lower()] = os.environ.get(key)
-
- # Check if current test be enabled.
- test_flag = self.config.get("test", "")
- if test_flag != "on" and test_flag != "true":
- raise ValueError(f"Service {self.service_name} test is not enabled.")
-
- self.operator = opendal.Operator(self.service_name, **self.config)
- self.async_operator = opendal.AsyncOperator(self.service_name, **self.config)
-
- def test_sync_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- read_content = self.operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- read_content = await self.async_operator.read(filename)
- assert read_content is not None
- assert read_content == content
-
- await self.async_operator.delete(filename)
-
- def test_sync_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- self.operator.write(filename, content)
-
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_read_stat(self):
- size = randint(1, 1024)
- filename = f"random_file_{str(uuid4())}"
- content = os.urandom(size)
- await self.async_operator.write(filename, content)
-
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.content_length == len(content)
- assert metadata.mode.is_file()
-
- await self.async_operator.delete(filename)
-
- self.operator.delete(filename)
-
- def test_sync_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- self.operator.read(str(uuid4()))
-
- @pytest.mark.asyncio
- async def test_async_read_not_exists(self):
- with pytest.raises(FileNotFoundError):
- await self.async_operator.read(str(uuid4()))
-
- def test_sync_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- metadata = self.operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- self.operator.delete(filename)
-
- @pytest.mark.asyncio
- async def test_async_write_with_non_ascii_name(self):
- size = randint(1, 1024)
- filename = f"❌😱中文_{str(uuid4())}.test"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- metadata = await self.async_operator.stat(filename)
- assert metadata is not None
- assert metadata.mode.is_file()
- assert metadata.content_length == size
-
- await self.async_operator.delete(filename)
-
- def test_sync_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- self.operator.create_dir(path)
- metadata = self.operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- self.operator.delete(path)
-
- @pytest.mark.asyncio
- async def test_async_create_dir(self):
- path = f"test_dir_{str(uuid4())}/"
- await self.async_operator.create_dir(path)
- metadata = await self.async_operator.stat(path)
- assert metadata is not None
- assert metadata.mode.is_dir()
-
- await self.async_operator.delete(path)
-
- def test_sync_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- self.operator.write(filename, content)
- self.operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- self.operator.stat(filename)
-
- @pytest.mark.asyncio
- async def test_async_delete(self):
- size = randint(1, 1024)
- filename = f"test_file_{str(uuid4())}.txt"
- content = os.urandom(size)
- size = len(content)
- await self.async_operator.write(filename, content)
- await self.async_operator.delete(filename)
- with pytest.raises(FileNotFoundError):
- await self.operator.stat(filename)
-
-
-class TestS3(AbstractTestSuite):
- service_name = "s3"
-
-
-class TestFS(AbstractTestSuite):
- service_name = "fs"
-
-
-class TestMemory(AbstractTestSuite):
- service_name = "memory"
+
+@pytest.fixture()
Review Comment:
Thanks for the PR, but the class way is preferred since we want to support `pytest -vk memory,s3,fs` which means we could construct more operators.
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org