Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e4a1e3

Browse files
Refactoring of tests (#232)
* TestLocalOperations is refactored* TestRemoteOperations is refactored
1 parent5a19e0b commit1e4a1e3

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_descrsimportOsOpsDescrs
3+
from .helpers.os_ops_descrsimportOsOperations
4+
25
importos
36

47
importpytest
58
importre
69

7-
from ..testgresimportLocalOperations
8-
910

1011
classTestLocalOperations:
12+
@pytest.fixture
13+
defos_ops(self):
14+
returnOsOpsDescrs.sm_local_os_ops
1115

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

2121
withpytest.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-
deftest_read_binary__spec__unk_file(self):
24+
deftest_read_binary__spec__unk_file(self,os_ops:OsOperations):
2525
"""
2626
Test LocalOperations::read_binary with unknown file.
2727
"""
2828

2929
withpytest.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-
deftest_get_file_size__unk_file(self):
34+
deftest_get_file_size__unk_file(self,os_ops:OsOperations):
3535
"""
3636
Test LocalOperations::get_file_size.
3737
"""
38+
assertisinstance(os_ops,OsOperations)
3839

3940
withpytest.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-
deftest_cwd(self):
43+
deftest_cwd(self,os_ops:OsOperations):
4344
"""
4445
Test cwd.
4546
"""
46-
v=self.operations.cwd()
47+
assertisinstance(os_ops,OsOperations)
48+
49+
v=os_ops.cwd()
4750

4851
assertvisnotNone
4952
asserttype(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-
importos
32

4-
importpytest
3+
from .helpers.os_ops_descrsimportOsOpsDescrs
4+
from .helpers.os_ops_descrsimportOsOperations
55

66
from ..testgresimportExecUtilException
7-
from ..testgresimportRemoteOperations
8-
from ..testgresimportConnectionParams
7+
8+
importos
9+
importpytest
910

1011

1112
classTestRemoteOperations:
13+
@pytest.fixture
14+
defos_ops(self):
15+
returnOsOpsDescrs.sm_remote_os_ops
1216

13-
@pytest.fixture(scope="function",autouse=True)
14-
defsetup(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+
deftest_rmdirs__try_to_delete_nonexist_path(self,os_ops:OsOperations):
18+
assertisinstance(os_ops,OsOperations)
1919

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

23-
assertself.operations.rmdirs(path,ignore_errors=False)isTrue
22+
assertos_ops.rmdirs(path,ignore_errors=False)isTrue
23+
24+
deftest_rmdirs__try_to_delete_file(self,os_ops:OsOperations):
25+
assertisinstance(os_ops,OsOperations)
2426

25-
deftest_rmdirs__try_to_delete_file(self):
26-
path=self.operations.mkstemp()
27+
path=os_ops.mkstemp()
28+
asserttype(path)==str# noqa: E721
2729
assertos.path.exists(path)
2830

2931
withpytest.raises(ExecUtilException)asx:
30-
self.operations.rmdirs(path,ignore_errors=False)
32+
os_ops.rmdirs(path,ignore_errors=False)
3133

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

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

4548
withpytest.raises(ExecUtilException)asx:
46-
self.operations.read("/dummy")
49+
os_ops.read("/dummy")
4750

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

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

5761
withpytest.raises(ExecUtilException)asx:
58-
self.operations.read_binary("/dummy",0)
62+
os_ops.read_binary("/dummy",0)
5963

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

64-
deftest_get_file_size__unk_file(self):
68+
deftest_get_file_size__unk_file(self,os_ops:OsOperations):
6569
"""
6670
Test RemoteOperations::get_file_size.
6771
"""
72+
assertisinstance(os_ops,OsOperations)
6873

6974
withpytest.raises(ExecUtilException)asx:
70-
self.operations.get_file_size("/dummy")
75+
os_ops.get_file_size("/dummy")
7176

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp