Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions labgrid/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ class ProcessWrapper:
loglevel = logging.INFO

@step(args=['command'], result=True, tag='process')
def check_output(self, command, *, print_on_silent_log=False, input=None, stdin=None, timeout=None): # pylint: disable=redefined-builtin
def check_output(
self, command, *, print_on_silent_log=False, input=None, stdin=None, stderr=subprocess.STDOUT, timeout=None
): # pylint: disable=redefined-builtin
"""Run a command and supply the output to callback functions"""

if stderr not in (None, subprocess.STDOUT, subprocess.DEVNULL):
raise NotImplementedError(f"{stderr=} not supported")

logger = logging.getLogger("Process")
res = []
mfd, sfd = pty.openpty()
Expand All @@ -59,8 +65,7 @@ def check_output(self, command, *, print_on_silent_log=False, input=None, stdin=
elif stdin is not None:
kwargs['stdin'] = stdin

process = subprocess.Popen(command, stderr=sfd,
stdout=sfd, bufsize=0, **kwargs)
process = subprocess.Popen(command, stderr=stderr, stdout=sfd, bufsize=0, **kwargs)

logger.log(ProcessWrapper.loglevel, "[%d] command: %s", process.pid, " ".join(command))

Expand Down
13 changes: 6 additions & 7 deletions tests/test_powerdriver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
from urllib.parse import urlparse

import pytest
Expand Down Expand Up @@ -81,7 +82,7 @@ def test_on(self, target, mocker):
d.on()

popen.assert_called_once_with(['set', '-1', 'foo-board'], bufsize=0,
stderr=2, stdout=2)
stderr=subprocess.STDOUT, stdout=2)

def test_off(self, target, mocker):
pty = mocker.patch('pty.openpty')
Expand All @@ -107,7 +108,7 @@ def test_off(self, target, mocker):
d.off()

popen.assert_called_once_with(['set', '-0', 'foo-board'], bufsize=0,
stderr=2, stdout=2)
stderr=subprocess.STDOUT, stdout=2)

def test_cycle(self, target, mocker):
pty = mocker.patch('pty.openpty')
Expand Down Expand Up @@ -135,10 +136,8 @@ def test_cycle(self, target, mocker):
d.cycle()

assert popen.call_args_list == [
mocker.call(['set', '-0', 'foo-board'], bufsize=0, stderr=2,
stdout=2),
mocker.call(['set', '-1', 'foo-board'], bufsize=0, stderr=2,
stdout=2),
mocker.call(['set', '-0', 'foo-board'], bufsize=0, stderr=subprocess.STDOUT, stdout=2),
mocker.call(['set', '-1', 'foo-board'], bufsize=0, stderr=subprocess.STDOUT, stdout=2),
]
m_sleep.assert_called_once_with(2.0)

Expand Down Expand Up @@ -171,7 +170,7 @@ def test_cycle_explicit(self, target, mocker):
d.cycle()

popen.assert_called_once_with(['set', '-c', 'foo-board'], bufsize=0,
stderr=2, stdout=2)
stderr=subprocess.STDOUT, stdout=2)
m_sleep.assert_not_called()

class TestNetworkPowerDriver:
Expand Down
Loading