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

Commit1c73113

Browse files
Merge pull request#160 from dmitry-lipetsk/D20241207_001--remote_op-expect_error
RemoteOperations::exec_command must not raise an exception when 'expect_error' is True (#159)
2 parents364d358 +cb87d0a commit1c73113

File tree

6 files changed

+98
-18
lines changed

6 files changed

+98
-18
lines changed

‎testgres/operations/remote_ops.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,26 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
8383

8484
exit_status=process.returncode
8585

86-
ifencoding:
87-
result=result.decode(encoding)
88-
error=error.decode(encoding)
89-
90-
ifexpect_error:
91-
raiseException(result,error)
86+
asserttype(result)==bytes# noqa: E721
87+
asserttype(error)==bytes# noqa: E721
9288

9389
ifnoterror:
94-
error_found=0
90+
error_found=False
9591
else:
96-
error=normalize_error(error)
9792
error_found=exit_status!=0orany(
98-
markerinerrorformarkerin ['error','Permission denied','fatal','No such file or directory']
93+
markerinerrorformarkerin [b'error',b'Permission denied',b'fatal',b'No such file or directory']
9994
)
10095

101-
ifnotignore_errorsanderror_found:
102-
ifisinstance(error,bytes):
103-
message=b"Utility exited with non-zero code. Error: "+error
104-
else:
105-
message=f"Utility exited with non-zero code. Error:{error}"
96+
asserttype(error_found)==bool# noqa: E721
97+
98+
ifencoding:
99+
result=result.decode(encoding)
100+
error=error.decode(encoding)
101+
102+
ifnotignore_errorsanderror_foundandnotexpect_error:
103+
error=normalize_error(error)
104+
asserttype(error)==str# noqa: E721
105+
message="Utility exited with non-zero code. Error: "+error
106106
raiseExecUtilException(message=message,command=cmd,exit_code=exit_status,out=result)
107107

108108
ifverbose:

‎tests/__init__.py

Whitespace-only changes.

‎tests/helpers/__init__.py

Whitespace-only changes.

‎tests/helpers/run_conditions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importpytest
2+
importplatform
3+
4+
5+
classRunConditions:
6+
# It is not a test kit!
7+
__test__=False
8+
9+
defskip_if_windows():
10+
ifplatform.system().lower()=="windows":
11+
pytest.skip("This test does not support Windows.")

‎tests/test_local.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
importpytest
2+
3+
fromtestgresimportExecUtilException
4+
fromtestgresimportLocalOperations
5+
6+
from .helpers.run_conditionsimportRunConditions
7+
8+
9+
classTestLocalOperations:
10+
11+
@pytest.fixture(scope="function",autouse=True)
12+
defsetup(self):
13+
self.operations=LocalOperations()
14+
15+
deftest_exec_command_success(self):
16+
"""
17+
Test exec_command for successful command execution.
18+
"""
19+
RunConditions.skip_if_windows()
20+
21+
cmd="python3 --version"
22+
response=self.operations.exec_command(cmd,wait_exit=True,shell=True)
23+
24+
assertb'Python 3.'inresponse
25+
26+
deftest_exec_command_failure(self):
27+
"""
28+
Test exec_command for command execution failure.
29+
"""
30+
RunConditions.skip_if_windows()
31+
32+
cmd="nonexistent_command"
33+
whileTrue:
34+
try:
35+
self.operations.exec_command(cmd,wait_exit=True,shell=True)
36+
exceptExecUtilExceptionase:
37+
error=e.message
38+
break
39+
raiseException("We wait an exception!")
40+
asserterror=="Utility exited with non-zero code. Error `b'/bin/sh: 1: nonexistent_command: not found\\n'`"
41+
42+
deftest_exec_command_failure__expect_error(self):
43+
"""
44+
Test exec_command for command execution failure.
45+
"""
46+
RunConditions.skip_if_windows()
47+
48+
cmd="nonexistent_command"
49+
50+
exit_status,result,error=self.operations.exec_command(cmd,verbose=True,wait_exit=True,shell=True,expect_error=True)
51+
52+
asserterror==b'/bin/sh: 1: nonexistent_command: not found\n'
53+
assertexit_status==127
54+
assertresult==b''

‎tests/test_remote.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,27 @@ def test_exec_command_failure(self):
3030
Test exec_command for command execution failure.
3131
"""
3232
cmd="nonexistent_command"
33-
try:
34-
exit_status,result,error=self.operations.exec_command(cmd,verbose=True,wait_exit=True)
35-
exceptExecUtilExceptionase:
36-
error=e.message
33+
whileTrue:
34+
try:
35+
self.operations.exec_command(cmd,verbose=True,wait_exit=True)
36+
exceptExecUtilExceptionase:
37+
error=e.message
38+
break
39+
raiseException("We wait an exception!")
3740
asserterror==b'Utility exited with non-zero code. Error: bash: line 1: nonexistent_command: command not found\n'
3841

42+
deftest_exec_command_failure__expect_error(self):
43+
"""
44+
Test exec_command for command execution failure.
45+
"""
46+
cmd="nonexistent_command"
47+
48+
exit_status,result,error=self.operations.exec_command(cmd,verbose=True,wait_exit=True,shell=True,expect_error=True)
49+
50+
asserterror==b'bash: line 1: nonexistent_command: command not found\n'
51+
assertexit_status==127
52+
assertresult==b''
53+
3954
deftest_is_executable_true(self):
4055
"""
4156
Test is_executable for an existing executable.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp