Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e43a384

Browse files
TestOsOpsCommon is updated
New tests: - test_exec_command_success - test_exec_command_failure - test_exec_command_failure__expect_error
1 parent 6e45c15 commit e43a384

File tree

3 files changed

+61
-101
lines changed

3 files changed

+61
-101
lines changed

tests/test_local.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
import re
66
import logging
77

8-
from ..testgres import ExecUtilException
98
from ..testgres import LocalOperations
109

11-
from .helpers.run_conditions import RunConditions
12-
1310

1411
class TestLocalOperations:
1512

@@ -33,58 +30,6 @@ def test_mkdtemp__custom(self):
3330
os.rmdir(path)
3431
assert not os.path.exists(path)
3532

36-
def test_exec_command_success(self):
37-
"""
38-
Test exec_command for successful command execution.
39-
"""
40-
RunConditions.skip_if_windows()
41-
42-
cmd = "python3 --version"
43-
response = self.operations.exec_command(cmd, wait_exit=True, shell=True)
44-
45-
assert b'Python 3.' in response
46-
47-
def test_exec_command_failure(self):
48-
"""
49-
Test exec_command for command execution failure.
50-
"""
51-
RunConditions.skip_if_windows()
52-
53-
cmd = "nonexistent_command"
54-
while True:
55-
try:
56-
self.operations.exec_command(cmd, wait_exit=True, shell=True)
57-
except ExecUtilException as e:
58-
assert type(e.exit_code) == int # noqa: E721
59-
assert e.exit_code == 127
60-
61-
assert type(e.message) == str # noqa: E721
62-
assert type(e.error) == bytes # noqa: E721
63-
64-
assert e.message.startswith("Utility exited with non-zero code (127). Error:")
65-
assert "nonexistent_command" in e.message
66-
assert "not found" in e.message
67-
assert b"nonexistent_command" in e.error
68-
assert b"not found" in e.error
69-
break
70-
raise Exception("We wait an exception!")
71-
72-
def test_exec_command_failure__expect_error(self):
73-
"""
74-
Test exec_command for command execution failure.
75-
"""
76-
RunConditions.skip_if_windows()
77-
78-
cmd = "nonexistent_command"
79-
80-
exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)
81-
82-
assert exit_status == 127
83-
assert result == b''
84-
assert type(error) == bytes # noqa: E721
85-
assert b"nonexistent_command" in error
86-
assert b"not found" in error
87-
8833
def test_read__unknown_file(self):
8934
"""
9035
Test LocalOperations::read with unknown file.

tests/test_os_ops_common.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import tempfile
1212

1313
from ..testgres import InvalidOperationException
14+
from ..testgres import ExecUtilException
1415

1516

1617
class TestOsOpsCommon:
@@ -28,6 +29,66 @@ def os_ops(self, request: pytest.FixtureRequest) -> OsOperations:
2829
assert isinstance(request.param, OsOperations)
2930
return request.param
3031

32+
def test_exec_command_success(self, os_ops: OsOperations):
33+
"""
34+
Test exec_command for successful command execution.
35+
"""
36+
assert isinstance(os_ops, OsOperations)
37+
38+
RunConditions.skip_if_windows()
39+
40+
cmd = ["sh", "-c", "python3 --version"]
41+
42+
response = os_ops.exec_command(cmd)
43+
44+
assert b'Python 3.' in response
45+
46+
def test_exec_command_failure(self, os_ops: OsOperations):
47+
"""
48+
Test exec_command for command execution failure.
49+
"""
50+
assert isinstance(os_ops, OsOperations)
51+
52+
RunConditions.skip_if_windows()
53+
54+
cmd = ["sh", "-c", "nonexistent_command"]
55+
56+
while True:
57+
try:
58+
os_ops.exec_command(cmd)
59+
except ExecUtilException as e:
60+
assert type(e.exit_code) == int # noqa: E721
61+
assert e.exit_code == 127
62+
63+
assert type(e.message) == str # noqa: E721
64+
assert type(e.error) == bytes # noqa: E721
65+
66+
assert e.message.startswith("Utility exited with non-zero code (127). Error:")
67+
assert "nonexistent_command" in e.message
68+
assert "not found" in e.message
69+
assert b"nonexistent_command" in e.error
70+
assert b"not found" in e.error
71+
break
72+
raise Exception("We wait an exception!")
73+
74+
def test_exec_command_failure__expect_error(self, os_ops: OsOperations):
75+
"""
76+
Test exec_command for command execution failure.
77+
"""
78+
assert isinstance(os_ops, OsOperations)
79+
80+
RunConditions.skip_if_windows()
81+
82+
cmd = ["sh", "-c", "nonexistent_command"]
83+
84+
exit_status, result, error = os_ops.exec_command(cmd, verbose=True, expect_error=True)
85+
86+
assert exit_status == 127
87+
assert result == b''
88+
assert type(error) == bytes # noqa: E721
89+
assert b"nonexistent_command" in error
90+
assert b"not found" in error
91+
3192
def test_listdir(self, os_ops: OsOperations):
3293
"""
3394
Test listdir for listing directory contents.

tests/test_remote.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,6 @@ def setup(self):
2020
ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY'))
2121
self.operations = RemoteOperations(conn_params)
2222

23-
def test_exec_command_success(self):
24-
"""
25-
Test exec_command for successful command execution.
26-
"""
27-
cmd = "python3 --version"
28-
response = self.operations.exec_command(cmd, wait_exit=True)
29-
30-
assert b'Python 3.' in response
31-
32-
def test_exec_command_failure(self):
33-
"""
34-
Test exec_command for command execution failure.
35-
"""
36-
cmd = "nonexistent_command"
37-
while True:
38-
try:
39-
self.operations.exec_command(cmd, verbose=True, wait_exit=True)
40-
except ExecUtilException as e:
41-
assert type(e.exit_code) == int # noqa: E721
42-
assert e.exit_code == 127
43-
44-
assert type(e.message) == str # noqa: E721
45-
assert type(e.error) == bytes # noqa: E721
46-
47-
assert e.message.startswith("Utility exited with non-zero code (127). Error:")
48-
assert "nonexistent_command" in e.message
49-
assert "not found" in e.message
50-
assert b"nonexistent_command" in e.error
51-
assert b"not found" in e.error
52-
break
53-
raise Exception("We wait an exception!")
54-
55-
def test_exec_command_failure__expect_error(self):
56-
"""
57-
Test exec_command for command execution failure.
58-
"""
59-
cmd = "nonexistent_command"
60-
61-
exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)
62-
63-
assert exit_status == 127
64-
assert result == b''
65-
assert type(error) == bytes # noqa: E721
66-
assert b"nonexistent_command" in error
67-
assert b"not found" in error
68-
6923
def test_is_executable_true(self):
7024
"""
7125
Test is_executable for an existing executable.

0 commit comments

Comments
 (0)