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 (+LocalOperations::is_executable)
New tests:- test_is_executable_true- test_is_executable_false- test_makedirs_and_rmdirs_success- test_makedirs_failureLocalOperations::is_executable is corrected
  • Loading branch information
@dmitry-lipetsk
dmitry-lipetsk committedApr 2, 2025
commit23cb7616ec23d7050db257913f7f5ee84bbf80cd
3 changes: 2 additions & 1 deletiontestgres/operations/local_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,8 @@ def find_executable(self, executable):

def is_executable(self, file):
# Check if the file is executable
return os.stat(file).st_mode & stat.S_IXUSR
assert stat.S_IXUSR != 0
return (os.stat(file).st_mode & stat.S_IXUSR) == stat.S_IXUSR

def set_env(self, var_name, var_val):
# Check if the directory is already in PATH
Expand Down
60 changes: 60 additions & 0 deletionstests/test_os_ops_common.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,6 +89,66 @@ def test_exec_command_failure__expect_error(self, os_ops: OsOperations):
assert b"nonexistent_command" in error
assert b"not found" in error

def test_is_executable_true(self, os_ops: OsOperations):
"""
Test is_executable for an existing executable.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

response = os_ops.is_executable("/bin/sh")

assert response is True

def test_is_executable_false(self, os_ops: OsOperations):
"""
Test is_executable for a non-executable.
"""
assert isinstance(os_ops, OsOperations)

response = os_ops.is_executable(__file__)

assert response is False

def test_makedirs_and_rmdirs_success(self, os_ops: OsOperations):
"""
Test makedirs and rmdirs for successful directory creation and removal.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

cmd = "pwd"
pwd = os_ops.exec_command(cmd, wait_exit=True, encoding='utf-8').strip()

path = "{}/test_dir".format(pwd)

# Test makedirs
os_ops.makedirs(path)
assert os.path.exists(path)
assert os_ops.path_exists(path)

# Test rmdirs
os_ops.rmdirs(path)
assert not os.path.exists(path)
assert not os_ops.path_exists(path)

def test_makedirs_failure(self, os_ops: OsOperations):
"""
Test makedirs for failure.
"""
# Try to create a directory in a read-only location
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

path = "/root/test_dir"

# Test makedirs
with pytest.raises(Exception):
os_ops.makedirs(path)

def test_listdir(self, os_ops: OsOperations):
"""
Test listdir for listing directory contents.
Expand Down
54 changes: 0 additions & 54 deletionstests/test_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,9 +6,7 @@

from ..testgres import ExecUtilException
from ..testgres import RemoteOperations
from ..testgres import LocalOperations
from ..testgres import ConnectionParams
from ..testgres import utils as testgres_utils


class TestRemoteOperations:
Expand All@@ -20,58 +18,6 @@ def setup(self):
ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY'))
self.operations = RemoteOperations(conn_params)

def test_is_executable_true(self):
"""
Test is_executable for an existing executable.
"""
local_ops = LocalOperations()
cmd = testgres_utils.get_bin_path2(local_ops, "pg_config")
cmd = local_ops.exec_command([cmd, "--bindir"], encoding="utf-8")
cmd = cmd.rstrip()
cmd = os.path.join(cmd, "pg_config")
response = self.operations.is_executable(cmd)

assert response is True

def test_is_executable_false(self):
"""
Test is_executable for a non-executable.
"""
cmd = "python"
response = self.operations.is_executable(cmd)

assert response is False

def test_makedirs_and_rmdirs_success(self):
"""
Test makedirs and rmdirs for successful directory creation and removal.
"""
cmd = "pwd"
pwd = self.operations.exec_command(cmd, wait_exit=True, encoding='utf-8').strip()

path = "{}/test_dir".format(pwd)

# Test makedirs
self.operations.makedirs(path)
assert os.path.exists(path)
assert self.operations.path_exists(path)

# Test rmdirs
self.operations.rmdirs(path)
assert not os.path.exists(path)
assert not self.operations.path_exists(path)

def test_makedirs_failure(self):
"""
Test makedirs for failure.
"""
# Try to create a directory in a read-only location
path = "/root/test_dir"

# Test makedirs
with pytest.raises(Exception):
self.operations.makedirs(path)

def test_mkdtemp__default(self):
path = self.operations.mkdtemp()
logging.info("Path is [{0}].".format(path))
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp