Skip to content

Commit 1e4a1e3

Browse files
Refactoring of tests (#232)
* TestLocalOperations is refactored * TestRemoteOperations is refactored
1 parent 5a19e0b commit 1e4a1e3

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

tests/test_local.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
# coding: utf-8
2+
from .helpers.os_ops_descrs import OsOpsDescrs
3+
from .helpers.os_ops_descrs import OsOperations
4+
25
import os
36

47
import pytest
58
import re
69

7-
from ..testgres import LocalOperations
8-
910

1011
class TestLocalOperations:
12+
@pytest.fixture
13+
def os_ops(self):
14+
return OsOpsDescrs.sm_local_os_ops
1115

12-
@pytest.fixture(scope="function", autouse=True)
13-
def setup(self):
14-
self.operations = LocalOperations()
15-
16-
def test_read__unknown_file(self):
16+
def test_read__unknown_file(self, os_ops: OsOperations):
1717
"""
1818
Test LocalOperations::read with unknown file.
1919
"""
2020

2121
with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
22-
self.operations.read("/dummy")
22+
os_ops.read("/dummy")
2323

24-
def test_read_binary__spec__unk_file(self):
24+
def test_read_binary__spec__unk_file(self, os_ops: OsOperations):
2525
"""
2626
Test LocalOperations::read_binary with unknown file.
2727
"""
2828

2929
with pytest.raises(
3030
FileNotFoundError,
3131
match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
32-
self.operations.read_binary("/dummy", 0)
32+
os_ops.read_binary("/dummy", 0)
3333

34-
def test_get_file_size__unk_file(self):
34+
def test_get_file_size__unk_file(self, os_ops: OsOperations):
3535
"""
3636
Test LocalOperations::get_file_size.
3737
"""
38+
assert isinstance(os_ops, OsOperations)
3839

3940
with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
40-
self.operations.get_file_size("/dummy")
41+
os_ops.get_file_size("/dummy")
4142

42-
def test_cwd(self):
43+
def test_cwd(self, os_ops: OsOperations):
4344
"""
4445
Test cwd.
4546
"""
46-
v = self.operations.cwd()
47+
assert isinstance(os_ops, OsOperations)
48+
49+
v = os_ops.cwd()
4750

4851
assert v is not None
4952
assert type(v) == str # noqa: E721

tests/test_remote.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
# coding: utf-8
2-
import os
32

4-
import pytest
3+
from .helpers.os_ops_descrs import OsOpsDescrs
4+
from .helpers.os_ops_descrs import OsOperations
55

66
from ..testgres import ExecUtilException
7-
from ..testgres import RemoteOperations
8-
from ..testgres import ConnectionParams
7+
8+
import os
9+
import pytest
910

1011

1112
class TestRemoteOperations:
13+
@pytest.fixture
14+
def os_ops(self):
15+
return OsOpsDescrs.sm_remote_os_ops
1216

13-
@pytest.fixture(scope="function", autouse=True)
14-
def setup(self):
15-
conn_params = ConnectionParams(host=os.getenv('RDBMS_TESTPOOL1_HOST') or '127.0.0.1',
16-
username=os.getenv('USER'),
17-
ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY'))
18-
self.operations = RemoteOperations(conn_params)
17+
def test_rmdirs__try_to_delete_nonexist_path(self, os_ops: OsOperations):
18+
assert isinstance(os_ops, OsOperations)
1919

20-
def test_rmdirs__try_to_delete_nonexist_path(self):
2120
path = "/root/test_dir"
2221

23-
assert self.operations.rmdirs(path, ignore_errors=False) is True
22+
assert os_ops.rmdirs(path, ignore_errors=False) is True
23+
24+
def test_rmdirs__try_to_delete_file(self, os_ops: OsOperations):
25+
assert isinstance(os_ops, OsOperations)
2426

25-
def test_rmdirs__try_to_delete_file(self):
26-
path = self.operations.mkstemp()
27+
path = os_ops.mkstemp()
28+
assert type(path) == str # noqa: E721
2729
assert os.path.exists(path)
2830

2931
with pytest.raises(ExecUtilException) as x:
30-
self.operations.rmdirs(path, ignore_errors=False)
32+
os_ops.rmdirs(path, ignore_errors=False)
3133

3234
assert os.path.exists(path)
3335
assert type(x.value) == ExecUtilException # noqa: E721
@@ -37,37 +39,40 @@ def test_rmdirs__try_to_delete_file(self):
3739
assert type(x.value.exit_code) == int # noqa: E721
3840
assert x.value.exit_code == 20
3941

40-
def test_read__unknown_file(self):
42+
def test_read__unknown_file(self, os_ops: OsOperations):
4143
"""
4244
Test RemoteOperations::read with unknown file.
4345
"""
46+
assert isinstance(os_ops, OsOperations)
4447

4548
with pytest.raises(ExecUtilException) as x:
46-
self.operations.read("/dummy")
49+
os_ops.read("/dummy")
4750

4851
assert "Utility exited with non-zero code (1)." in str(x.value)
4952
assert "No such file or directory" in str(x.value)
5053
assert "/dummy" in str(x.value)
5154

52-
def test_read_binary__spec__unk_file(self):
55+
def test_read_binary__spec__unk_file(self, os_ops: OsOperations):
5356
"""
5457
Test RemoteOperations::read_binary with unknown file.
5558
"""
59+
assert isinstance(os_ops, OsOperations)
5660

5761
with pytest.raises(ExecUtilException) as x:
58-
self.operations.read_binary("/dummy", 0)
62+
os_ops.read_binary("/dummy", 0)
5963

6064
assert "Utility exited with non-zero code (1)." in str(x.value)
6165
assert "No such file or directory" in str(x.value)
6266
assert "/dummy" in str(x.value)
6367

64-
def test_get_file_size__unk_file(self):
68+
def test_get_file_size__unk_file(self, os_ops: OsOperations):
6569
"""
6670
Test RemoteOperations::get_file_size.
6771
"""
72+
assert isinstance(os_ops, OsOperations)
6873

6974
with pytest.raises(ExecUtilException) as x:
70-
self.operations.get_file_size("/dummy")
75+
os_ops.get_file_size("/dummy")
7176

7277
assert "Utility exited with non-zero code (1)." in str(x.value)
7378
assert "No such file or directory" in str(x.value)

0 commit comments

Comments
 (0)