From e5be783f430880286f408927bd9aacbd30651069 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Wed, 2 Apr 2025 17:31:50 +0300 Subject: [PATCH 1/2] TestLocalOperations is refactored - [del] setup - [add] fixture: os_ops --- tests/test_local.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/test_local.py b/tests/test_local.py index 7b5e488d..e82df989 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -1,27 +1,27 @@ # coding: utf-8 +from .helpers.os_ops_descrs import OsOpsDescrs +from .helpers.os_ops_descrs import OsOperations + import os import pytest import re -from ..testgres import LocalOperations - class TestLocalOperations: + @pytest.fixture + def os_ops(self): + return OsOpsDescrs.sm_local_os_ops - @pytest.fixture(scope="function", autouse=True) - def setup(self): - self.operations = LocalOperations() - - def test_read__unknown_file(self): + def test_read__unknown_file(self, os_ops: OsOperations): """ Test LocalOperations::read with unknown file. """ with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")): - self.operations.read("/dummy") + os_ops.read("/dummy") - def test_read_binary__spec__unk_file(self): + def test_read_binary__spec__unk_file(self, os_ops: OsOperations): """ Test LocalOperations::read_binary with unknown file. """ @@ -29,21 +29,24 @@ def test_read_binary__spec__unk_file(self): with pytest.raises( FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")): - self.operations.read_binary("/dummy", 0) + os_ops.read_binary("/dummy", 0) - def test_get_file_size__unk_file(self): + def test_get_file_size__unk_file(self, os_ops: OsOperations): """ Test LocalOperations::get_file_size. """ + assert isinstance(os_ops, OsOperations) with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")): - self.operations.get_file_size("/dummy") + os_ops.get_file_size("/dummy") - def test_cwd(self): + def test_cwd(self, os_ops: OsOperations): """ Test cwd. """ - v = self.operations.cwd() + assert isinstance(os_ops, OsOperations) + + v = os_ops.cwd() assert v is not None assert type(v) == str # noqa: E721 From f7e9b303a2882a4b7d3df555436c01577b33d97f Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Wed, 2 Apr 2025 17:32:34 +0300 Subject: [PATCH 2/2] TestRemoteOperations is refactored - [del] setup - [add] fixture: os_ops --- tests/test_remote.py | 47 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/tests/test_remote.py b/tests/test_remote.py index 565b2d20..a37e258e 100755 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -1,33 +1,35 @@ # coding: utf-8 -import os -import pytest +from .helpers.os_ops_descrs import OsOpsDescrs +from .helpers.os_ops_descrs import OsOperations from ..testgres import ExecUtilException -from ..testgres import RemoteOperations -from ..testgres import ConnectionParams + +import os +import pytest class TestRemoteOperations: + @pytest.fixture + def os_ops(self): + return OsOpsDescrs.sm_remote_os_ops - @pytest.fixture(scope="function", autouse=True) - def setup(self): - conn_params = ConnectionParams(host=os.getenv('RDBMS_TESTPOOL1_HOST') or '127.0.0.1', - username=os.getenv('USER'), - ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY')) - self.operations = RemoteOperations(conn_params) + def test_rmdirs__try_to_delete_nonexist_path(self, os_ops: OsOperations): + assert isinstance(os_ops, OsOperations) - def test_rmdirs__try_to_delete_nonexist_path(self): path = "/root/test_dir" - assert self.operations.rmdirs(path, ignore_errors=False) is True + assert os_ops.rmdirs(path, ignore_errors=False) is True + + def test_rmdirs__try_to_delete_file(self, os_ops: OsOperations): + assert isinstance(os_ops, OsOperations) - def test_rmdirs__try_to_delete_file(self): - path = self.operations.mkstemp() + path = os_ops.mkstemp() + assert type(path) == str # noqa: E721 assert os.path.exists(path) with pytest.raises(ExecUtilException) as x: - self.operations.rmdirs(path, ignore_errors=False) + os_ops.rmdirs(path, ignore_errors=False) assert os.path.exists(path) assert type(x.value) == ExecUtilException # noqa: E721 @@ -37,37 +39,40 @@ def test_rmdirs__try_to_delete_file(self): assert type(x.value.exit_code) == int # noqa: E721 assert x.value.exit_code == 20 - def test_read__unknown_file(self): + def test_read__unknown_file(self, os_ops: OsOperations): """ Test RemoteOperations::read with unknown file. """ + assert isinstance(os_ops, OsOperations) with pytest.raises(ExecUtilException) as x: - self.operations.read("/dummy") + os_ops.read("/dummy") assert "Utility exited with non-zero code (1)." in str(x.value) assert "No such file or directory" in str(x.value) assert "/dummy" in str(x.value) - def test_read_binary__spec__unk_file(self): + def test_read_binary__spec__unk_file(self, os_ops: OsOperations): """ Test RemoteOperations::read_binary with unknown file. """ + assert isinstance(os_ops, OsOperations) with pytest.raises(ExecUtilException) as x: - self.operations.read_binary("/dummy", 0) + os_ops.read_binary("/dummy", 0) assert "Utility exited with non-zero code (1)." in str(x.value) assert "No such file or directory" in str(x.value) assert "/dummy" in str(x.value) - def test_get_file_size__unk_file(self): + def test_get_file_size__unk_file(self, os_ops: OsOperations): """ Test RemoteOperations::get_file_size. """ + assert isinstance(os_ops, OsOperations) with pytest.raises(ExecUtilException) as x: - self.operations.get_file_size("/dummy") + os_ops.get_file_size("/dummy") assert "Utility exited with non-zero code (1)." in str(x.value) assert "No such file or directory" in str(x.value) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy