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

Commit23cb761

Browse files
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
1 parente43a384 commit23cb761

File tree

3 files changed

+62
-55
lines changed

3 files changed

+62
-55
lines changed

‎testgres/operations/local_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def find_executable(self, executable):
156156

157157
defis_executable(self,file):
158158
# Check if the file is executable
159-
returnos.stat(file).st_mode&stat.S_IXUSR
159+
assertstat.S_IXUSR!=0
160+
return (os.stat(file).st_mode&stat.S_IXUSR)==stat.S_IXUSR
160161

161162
defset_env(self,var_name,var_val):
162163
# Check if the directory is already in PATH

‎tests/test_os_ops_common.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,66 @@ def test_exec_command_failure__expect_error(self, os_ops: OsOperations):
8989
assertb"nonexistent_command"inerror
9090
assertb"not found"inerror
9191

92+
deftest_is_executable_true(self,os_ops:OsOperations):
93+
"""
94+
Test is_executable for an existing executable.
95+
"""
96+
assertisinstance(os_ops,OsOperations)
97+
98+
RunConditions.skip_if_windows()
99+
100+
response=os_ops.is_executable("/bin/sh")
101+
102+
assertresponseisTrue
103+
104+
deftest_is_executable_false(self,os_ops:OsOperations):
105+
"""
106+
Test is_executable for a non-executable.
107+
"""
108+
assertisinstance(os_ops,OsOperations)
109+
110+
response=os_ops.is_executable(__file__)
111+
112+
assertresponseisFalse
113+
114+
deftest_makedirs_and_rmdirs_success(self,os_ops:OsOperations):
115+
"""
116+
Test makedirs and rmdirs for successful directory creation and removal.
117+
"""
118+
assertisinstance(os_ops,OsOperations)
119+
120+
RunConditions.skip_if_windows()
121+
122+
cmd="pwd"
123+
pwd=os_ops.exec_command(cmd,wait_exit=True,encoding='utf-8').strip()
124+
125+
path="{}/test_dir".format(pwd)
126+
127+
# Test makedirs
128+
os_ops.makedirs(path)
129+
assertos.path.exists(path)
130+
assertos_ops.path_exists(path)
131+
132+
# Test rmdirs
133+
os_ops.rmdirs(path)
134+
assertnotos.path.exists(path)
135+
assertnotos_ops.path_exists(path)
136+
137+
deftest_makedirs_failure(self,os_ops:OsOperations):
138+
"""
139+
Test makedirs for failure.
140+
"""
141+
# Try to create a directory in a read-only location
142+
assertisinstance(os_ops,OsOperations)
143+
144+
RunConditions.skip_if_windows()
145+
146+
path="/root/test_dir"
147+
148+
# Test makedirs
149+
withpytest.raises(Exception):
150+
os_ops.makedirs(path)
151+
92152
deftest_listdir(self,os_ops:OsOperations):
93153
"""
94154
Test listdir for listing directory contents.

‎tests/test_remote.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
from ..testgresimportExecUtilException
88
from ..testgresimportRemoteOperations
9-
from ..testgresimportLocalOperations
109
from ..testgresimportConnectionParams
11-
from ..testgresimportutilsastestgres_utils
1210

1311

1412
classTestRemoteOperations:
@@ -20,58 +18,6 @@ def setup(self):
2018
ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY'))
2119
self.operations=RemoteOperations(conn_params)
2220

23-
deftest_is_executable_true(self):
24-
"""
25-
Test is_executable for an existing executable.
26-
"""
27-
local_ops=LocalOperations()
28-
cmd=testgres_utils.get_bin_path2(local_ops,"pg_config")
29-
cmd=local_ops.exec_command([cmd,"--bindir"],encoding="utf-8")
30-
cmd=cmd.rstrip()
31-
cmd=os.path.join(cmd,"pg_config")
32-
response=self.operations.is_executable(cmd)
33-
34-
assertresponseisTrue
35-
36-
deftest_is_executable_false(self):
37-
"""
38-
Test is_executable for a non-executable.
39-
"""
40-
cmd="python"
41-
response=self.operations.is_executable(cmd)
42-
43-
assertresponseisFalse
44-
45-
deftest_makedirs_and_rmdirs_success(self):
46-
"""
47-
Test makedirs and rmdirs for successful directory creation and removal.
48-
"""
49-
cmd="pwd"
50-
pwd=self.operations.exec_command(cmd,wait_exit=True,encoding='utf-8').strip()
51-
52-
path="{}/test_dir".format(pwd)
53-
54-
# Test makedirs
55-
self.operations.makedirs(path)
56-
assertos.path.exists(path)
57-
assertself.operations.path_exists(path)
58-
59-
# Test rmdirs
60-
self.operations.rmdirs(path)
61-
assertnotos.path.exists(path)
62-
assertnotself.operations.path_exists(path)
63-
64-
deftest_makedirs_failure(self):
65-
"""
66-
Test makedirs for failure.
67-
"""
68-
# Try to create a directory in a read-only location
69-
path="/root/test_dir"
70-
71-
# Test makedirs
72-
withpytest.raises(Exception):
73-
self.operations.makedirs(path)
74-
7521
deftest_mkdtemp__default(self):
7622
path=self.operations.mkdtemp()
7723
logging.info("Path is [{0}].".format(path))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp