Skip to content

Commit 22c649d

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_error Changes in TestRemoteOperations: - test_exec_command_failure exptects an exception - new test test_exec_command_failure__expect_error was added TestRemoteOperations::test_exec_command_failure__expect_error will fail because RemoteOperations::exec_command does not handle the 'expect_error' parameter correctly.
1 parent cf1d227 commit 22c649d

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+
import pytest
2+
3+
from testgres import ExecUtilException
4+
from testgres import LocalOperations
5+
6+
7+
class TestLocalOperations:
8+
9+
@pytest.fixture(scope="function", autouse=True)
10+
def setup(self):
11+
self.operations = LocalOperations()
12+
13+
def test_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+
assert b'Python 3.' in response
21+
22+
def test_exec_command_failure(self):
23+
"""
24+
Test exec_command for command execution failure.
25+
"""
26+
cmd = "nonexistent_command"
27+
while True:
28+
try:
29+
self.operations.exec_command(cmd, wait_exit=True, shell=True)
30+
except ExecUtilException as e:
31+
error = e.message
32+
break
33+
raise Exception("We wait an exception!")
34+
assert error == "Utility exited with non-zero code. Error `b'/bin/sh: 1: nonexistent_command: not found\\n'`"
35+
36+
def test_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+
assert error == b'/bin/sh: 1: nonexistent_command: not found\n'
45+
assert exit_status == 127
46+
assert result == 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-
except ExecUtilException as e:
36-
error = e.message
33+
while True:
34+
try:
35+
self.operations.exec_command(cmd, verbose=True, wait_exit=True)
36+
except ExecUtilException as e:
37+
error = e.message
38+
break
39+
raise Exception("We wait an exception!")
3740
assert error == b'Utility exited with non-zero code. Error: bash: line 1: nonexistent_command: command not found\n'
3841

42+
def test_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+
assert error == b'bash: line 1: nonexistent_command: command not found\n'
51+
assert exit_status == 127
52+
assert result == b''
53+
3954
def test_is_executable_true(self):
4055
"""
4156
Test is_executable for an existing executable.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy