From 7005db3f0c893e8f7c7d7a3dce90a9f4a87d11fe Mon Sep 17 00:00:00 2001 From: Daniel Stonier Date: Sat, 29 Jun 2019 11:35:47 -0400 Subject: [PATCH] guard for windows (#1) --- launch/launch/actions/execute_process.py | 7 +++++ .../launch/{ => actions}/test_emulate_tty.py | 27 +++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) rename launch/test/launch/{ => actions}/test_emulate_tty.py (67%) diff --git a/launch/launch/actions/execute_process.py b/launch/launch/actions/execute_process.py index 3c4473225..bd3db6b1a 100644 --- a/launch/launch/actions/execute_process.py +++ b/launch/launch/actions/execute_process.py @@ -529,6 +529,13 @@ async def __execute_process(self, context: LaunchContext) -> None: )) except KeyError: emulate_tty = self.__emulate_tty + # guard against windows - tty emulation is not yet working + # https://github.com/ros2/launch/issues/268 + if emulate_tty and platform.system() == 'Windows': + self.__logger.warning( + "tty emulation not yet supported on windows, disabling" + ) + emulate_tty = False try: transport, self._subprocess_protocol = await async_execute_process( lambda **kwargs: self.__ProcessProtocol( diff --git a/launch/test/launch/test_emulate_tty.py b/launch/test/launch/actions/test_emulate_tty.py similarity index 67% rename from launch/test/launch/test_emulate_tty.py rename to launch/test/launch/actions/test_emulate_tty.py index f531622e9..45b49b64e 100644 --- a/launch/test/launch/test_emulate_tty.py +++ b/launch/test/launch/actions/test_emulate_tty.py @@ -14,6 +14,7 @@ """Tests for emulate_tty configuration of ExecuteProcess actions.""" +import platform import sys import launch @@ -29,19 +30,35 @@ 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', [ - (None, 1), # use the default defined by ExecuteProcess - ('true', 1), # redundantly override the default via LaunchConfiguration - ('false', 0) # override the default via LaunchConfiguration + # use the default defined by ExecuteProcess + (None, tty_expected_unless_windows()), + # redundantly override the default via LaunchConfiguration + ('true', tty_expected_unless_windows()), + # override the default via LaunchConfiguration + ('false', 0) ]) def test_emulate_tty(test_input, expected): on_exit = OnExit() ld = launch.LaunchDescription() ld.add_action(launch.actions.ExecuteProcess( - cmd=[sys.executable, '-c', 'import sys; sys.exit(sys.stdout.isatty())']) + cmd=[sys.executable, + '-c', + 'import sys; sys.exit(sys.stdout.isatty())' + ] + ) ) if test_input is not None: - ld.add_action(launch.actions.SetLaunchConfiguration('emulate_tty', test_input)) + 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)