Skip to content

Commit

Permalink
wait_for_ouput() repr includes actual text (#408)
Browse files Browse the repository at this point in the history
* wait_for_ouput() repr includes actual text

This makes `wait_for_output()` return an object that still evaluates as
a bool, but when `repr()`'d it includes the actual text. This will help
debug a few test failures on the build farm caused by expected output
not being seeing.

Signed-off-by: Shane Loretz<sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Flake8 CNL100

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz authored Apr 27, 2020
1 parent 0a49508 commit a768339
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions launch_testing/launch_testing/tools/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,31 @@ def wait_for_output(self, condition=None, timeout=None):
raise TypeError(
"Expected 'condition' to be callable but got '{!r}'".format(condition)
)

actual_output = None

def remember_output():
nonlocal actual_output
actual_output = self.output
return actual_output

class BoolWithText:

def __init__(self, result, output):
self._result = result
self._output = output

def __bool__(self):
return self._result

def __repr__(self):
return f'<BoolWithText({self._result}): {repr(self._output)}>'

with self._proc_output.io_event:
return self._proc_output.io_event.wait_for(
lambda: self.running and condition(self.output), timeout=timeout
bool_result = self._proc_output.io_event.wait_for(
lambda: self.running and condition(remember_output()), timeout=timeout
)
return BoolWithText(bool_result, actual_output)

@property
def target_process_action(self):
Expand Down

0 comments on commit a768339

Please sign in to comment.