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

TestOsOpsCommon is added [generic os_ops tests]#231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
TestOsOpsCommon is updated
New tests:- test_exec_command_success- test_exec_command_failure- test_exec_command_failure__expect_error
  • Loading branch information
@dmitry-lipetsk
dmitry-lipetsk committedApr 2, 2025
commite43a38484ee4a82c0dff69f21fab7d8d6839d6da
55 changes: 0 additions & 55 deletionstests/test_local.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,11 +5,8 @@
import re
import logging

from ..testgres import ExecUtilException
from ..testgres import LocalOperations

from .helpers.run_conditions import RunConditions


class TestLocalOperations:

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

def test_exec_command_success(self):
"""
Test exec_command for successful command execution.
"""
RunConditions.skip_if_windows()

cmd = "python3 --version"
response = self.operations.exec_command(cmd, wait_exit=True, shell=True)

assert b'Python 3.' in response

def test_exec_command_failure(self):
"""
Test exec_command for command execution failure.
"""
RunConditions.skip_if_windows()

cmd = "nonexistent_command"
while True:
try:
self.operations.exec_command(cmd, wait_exit=True, shell=True)
except ExecUtilException as e:
assert type(e.exit_code) == int # noqa: E721
assert e.exit_code == 127

assert type(e.message) == str # noqa: E721
assert type(e.error) == bytes # noqa: E721

assert e.message.startswith("Utility exited with non-zero code (127). Error:")
assert "nonexistent_command" in e.message
assert "not found" in e.message
assert b"nonexistent_command" in e.error
assert b"not found" in e.error
break
raise Exception("We wait an exception!")

def test_exec_command_failure__expect_error(self):
"""
Test exec_command for command execution failure.
"""
RunConditions.skip_if_windows()

cmd = "nonexistent_command"

exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)

assert exit_status == 127
assert result == b''
assert type(error) == bytes # noqa: E721
assert b"nonexistent_command" in error
assert b"not found" in error

def test_read__unknown_file(self):
"""
Test LocalOperations::read with unknown file.
Expand Down
61 changes: 61 additions & 0 deletionstests/test_os_ops_common.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@
import tempfile

from ..testgres import InvalidOperationException
from ..testgres import ExecUtilException


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

def test_exec_command_success(self, os_ops: OsOperations):
"""
Test exec_command for successful command execution.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

cmd = ["sh", "-c", "python3 --version"]

response = os_ops.exec_command(cmd)

assert b'Python 3.' in response

def test_exec_command_failure(self, os_ops: OsOperations):
"""
Test exec_command for command execution failure.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

cmd = ["sh", "-c", "nonexistent_command"]

while True:
try:
os_ops.exec_command(cmd)
except ExecUtilException as e:
assert type(e.exit_code) == int # noqa: E721
assert e.exit_code == 127

assert type(e.message) == str # noqa: E721
assert type(e.error) == bytes # noqa: E721

assert e.message.startswith("Utility exited with non-zero code (127). Error:")
assert "nonexistent_command" in e.message
assert "not found" in e.message
assert b"nonexistent_command" in e.error
assert b"not found" in e.error
break
raise Exception("We wait an exception!")

def test_exec_command_failure__expect_error(self, os_ops: OsOperations):
"""
Test exec_command for command execution failure.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

cmd = ["sh", "-c", "nonexistent_command"]

exit_status, result, error = os_ops.exec_command(cmd, verbose=True, expect_error=True)

assert exit_status == 127
assert result == b''
assert type(error) == bytes # noqa: E721
assert b"nonexistent_command" in error
assert b"not found" in error

def test_listdir(self, os_ops: OsOperations):
"""
Test listdir for listing directory contents.
Expand Down
46 changes: 0 additions & 46 deletionstests/test_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,52 +20,6 @@ def setup(self):
ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY'))
self.operations = RemoteOperations(conn_params)

def test_exec_command_success(self):
"""
Test exec_command for successful command execution.
"""
cmd = "python3 --version"
response = self.operations.exec_command(cmd, wait_exit=True)

assert b'Python 3.' in response

def test_exec_command_failure(self):
"""
Test exec_command for command execution failure.
"""
cmd = "nonexistent_command"
while True:
try:
self.operations.exec_command(cmd, verbose=True, wait_exit=True)
except ExecUtilException as e:
assert type(e.exit_code) == int # noqa: E721
assert e.exit_code == 127

assert type(e.message) == str # noqa: E721
assert type(e.error) == bytes # noqa: E721

assert e.message.startswith("Utility exited with non-zero code (127). Error:")
assert "nonexistent_command" in e.message
assert "not found" in e.message
assert b"nonexistent_command" in e.error
assert b"not found" in e.error
break
raise Exception("We wait an exception!")

def test_exec_command_failure__expect_error(self):
"""
Test exec_command for command execution failure.
"""
cmd = "nonexistent_command"

exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)

assert exit_status == 127
assert result == b''
assert type(error) == bytes # noqa: E721
assert b"nonexistent_command" in error
assert b"not found" in error

def test_is_executable_true(self):
"""
Test is_executable for an existing executable.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp