-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[execute_process] emulate_tty configurable and defaul…
…ts to true"" (#277) * Revert "Revert "[execute_process] emulate_tty configurable and defaults to true (#265)" (#276)" This reverts commit 15af530. * add option to strip ansi escape sequences from output in launch_testing Signed-off-by: William Woodall <[email protected]> * move registration of event handlers before including test file Signed-off-by: William Woodall <[email protected]> * replace \r\n with \n too, because you get this in emulated tty mode Signed-off-by: William Woodall <[email protected]> * fix a new test failure due a change in how pytest represents exceptions See: pytest-dev/pytest#5579 Signed-off-by: William Woodall <[email protected]> * refactor to not use YAML in eval of emulate_tty option Signed-off-by: William Woodall <[email protected]> * fix typo Signed-off-by: William Woodall <[email protected]> * refactor emulate_tty tests and test constructor argument Signed-off-by: William Woodall <[email protected]> * change default for emulate_tty to be False and fix warnings Signed-off-by: William Woodall <[email protected]>
- Loading branch information
Showing
9 changed files
with
193 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2019 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
Script that demonstrates disabling tty emulation. | ||
This is most significant for python processes which, without tty | ||
emulation, will be buffered by default and have various other | ||
capabilities disabled." | ||
""" | ||
|
||
import os | ||
import sys | ||
from typing import cast | ||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) # noqa | ||
|
||
import launch | ||
|
||
|
||
def generate_launch_description(): | ||
ld = launch.LaunchDescription() | ||
|
||
# Disable tty emulation (on by default). | ||
ld.add_action(launch.actions.SetLaunchConfiguration('emulate_tty', 'false')) | ||
|
||
# Wire up stdout from processes | ||
def on_output(event: launch.Event) -> None: | ||
for line in event.text.decode().splitlines(): | ||
print('[{}] {}'.format( | ||
cast(launch.events.process.ProcessIO, event).process_name, line)) | ||
|
||
ld.add_action(launch.actions.RegisterEventHandler(launch.event_handlers.OnProcessIO( | ||
on_stdout=on_output, | ||
))) | ||
|
||
# Execute | ||
ld.add_action(launch.actions.ExecuteProcess( | ||
cmd=[sys.executable, './counter.py'] | ||
)) | ||
return ld | ||
|
||
|
||
if __name__ == '__main__': | ||
# ls = LaunchService(argv=argv, debug=True) # Use this instead to get more debug messages. | ||
ls = launch.LaunchService(argv=sys.argv[1:]) | ||
ls.include_launch_description(generate_launch_description()) | ||
sys.exit(ls.run()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2019 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Tests for emulate_tty configuration of ExecuteProcess actions.""" | ||
|
||
import platform | ||
import sys | ||
|
||
import launch | ||
import pytest | ||
|
||
|
||
class OnExit(object): | ||
|
||
def __init__(self): | ||
self.returncode = None | ||
|
||
def handle(self, event, context): | ||
self.returncode = event.returncode | ||
|
||
|
||
def tty_expected_unless_windows(): | ||
return 1 if platform.system() != 'Windows' else 0 | ||
|
||
|
||
@pytest.mark.parametrize('test_input,expected', [ | ||
# use the default defined by ExecuteProcess | ||
(None, not tty_expected_unless_windows()), | ||
# redundantly override the default via LaunchConfiguration | ||
('true', tty_expected_unless_windows()), | ||
# override the default via LaunchConfiguration | ||
('false', 0), | ||
# redundantly override the default via constructor | ||
(True, tty_expected_unless_windows()), | ||
# override the default via constructor | ||
(False, 0), | ||
]) | ||
def test_emulate_tty(test_input, expected): | ||
on_exit = OnExit() | ||
ld = launch.LaunchDescription() | ||
kwargs = {} | ||
if isinstance(test_input, bool): | ||
kwargs['emulate_tty'] = test_input | ||
elif isinstance(test_input, str): | ||
ld.add_action( | ||
launch.actions.SetLaunchConfiguration( | ||
'emulate_tty', | ||
test_input | ||
) | ||
) | ||
ld.add_action( | ||
launch.actions.RegisterEventHandler( | ||
launch.event_handlers.OnProcessExit(on_exit=on_exit.handle) | ||
) | ||
) | ||
ld.add_action(launch.actions.ExecuteProcess( | ||
cmd=[ | ||
sys.executable, | ||
'-c', | ||
'import sys; sys.exit(sys.stdout.isatty())', | ||
], | ||
**kwargs | ||
)) | ||
ls = launch.LaunchService() | ||
ls.include_launch_description(ld) | ||
ls.run() | ||
assert on_exit.returncode == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters