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

Commit22c649d

Browse files
test_local.py and test_exec_command_failure__expect_error are added
test_local.py contains set of test for LocalOperations - test_exec_command_success - test_exec_command_failure - test_exec_command_failure__expect_errorChanges in TestRemoteOperations: - test_exec_command_failure exptects an exception - new test test_exec_command_failure__expect_error was addedTestRemoteOperations::test_exec_command_failure__expect_error will fail because RemoteOperations::exec_command does not handle the 'expect_error' parameter correctly.
1 parentcf1d227 commit22c649d

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

‎tests/test_local.py

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