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

RemoteOperations::exec_command must not raise an exception when 'expect_error' is True (#159)#160

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
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
NextNext commit
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.
  • Loading branch information
@dmitry-lipetsk
dmitry-lipetsk committedDec 7, 2024
commit22c649dcaa8129bc240d49b24f2e363832e70d9a
46 changes: 46 additions & 0 deletionstests/test_local.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
import pytest

from testgres import ExecUtilException
from testgres import LocalOperations


class TestLocalOperations:

@pytest.fixture(scope="function", autouse=True)
def setup(self):
self.operations = LocalOperations()

def test_exec_command_success(self):
"""
Test exec_command for successful command execution.
"""
cmd = "python3 --version"
response = self.operations.exec_command(cmd, wait_exit=True, shell=True)

assert b'Python 3.' in response

def test_exec_command_failure(self):
"""
Test exec_command for command execution failure.
"""
cmd = "nonexistent_command"
while True:
try:
self.operations.exec_command(cmd, wait_exit=True, shell=True)
except ExecUtilException as e:
error = e.message
break
raise Exception("We wait an exception!")
assert error == "Utility exited with non-zero code. Error `b'/bin/sh: 1: nonexistent_command: not found\\n'`"

def test_exec_command_failure__expect_error(self):
"""
Test exec_command for command execution failure.
"""
cmd = "nonexistent_command"

exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)

assert error == b'/bin/sh: 1: nonexistent_command: not found\n'
assert exit_status == 127
assert result == b''
23 changes: 19 additions & 4 deletionstests/test_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,12 +30,27 @@ def test_exec_command_failure(self):
Test exec_command for command execution failure.
"""
cmd = "nonexistent_command"
try:
exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True)
except ExecUtilException as e:
error = e.message
while True:
try:
self.operations.exec_command(cmd, verbose=True, wait_exit=True)
except ExecUtilException as e:
error = e.message
break
raise Exception("We wait an exception!")
assert error == b'Utility exited with non-zero code. Error: bash: line 1: nonexistent_command: command not found\n'

def test_exec_command_failure__expect_error(self):
"""
Test exec_command for command execution failure.
"""
cmd = "nonexistent_command"

exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)

assert error == b'bash: line 1: nonexistent_command: command not found\n'
assert exit_status == 127
assert result == b''

def test_is_executable_true(self):
"""
Test is_executable for an existing executable.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp