From 030fb0aba3bf8ac90650003a4e86cc8951f2f08e Mon Sep 17 00:00:00 2001 From: Tal Einat <532281+taleinat@users.noreply.github.com> Date: Thu, 12 May 2022 22:20:56 +0300 Subject: [PATCH] [watchmedo] Fix broken parsing of --kill-after argument for the auto-restart command (#886) This appears to be the originally intended behavior. --- changelog.rst | 4 ++-- src/watchdog/watchmedo.py | 1 + tests/test_0_watchmedo.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/changelog.rst b/changelog.rst index ffc8fb02..900a55df 100644 --- a/changelog.rst +++ b/changelog.rst @@ -8,8 +8,8 @@ Changelog 2022-xx-xx • `full history `__ -- -- Thanks to our beloved contributors: @ +- [watchmedo] Fix broken parsing of ``--kill-after`` argument for the ``auto-restart`` command. (`#870 `_) +- Thanks to our beloved contributors: @taleinat 2.1.7 ~~~~~ diff --git a/src/watchdog/watchmedo.py b/src/watchdog/watchmedo.py index 0841c9a0..a3d1fd8a 100755 --- a/src/watchdog/watchmedo.py +++ b/src/watchdog/watchmedo.py @@ -579,6 +579,7 @@ def shell_command(args): argument('--kill-after', dest='kill_after', default=10.0, + type=float, help='When stopping, kill the subprocess after the specified timeout ' 'in seconds (default 10.0).')]) def auto_restart(args): diff --git a/tests/test_0_watchmedo.py b/tests/test_0_watchmedo.py index 312ba5a1..5da43146 100644 --- a/tests/test_0_watchmedo.py +++ b/tests/test_0_watchmedo.py @@ -74,6 +74,21 @@ def test_kill_auto_restart(tmpdir, capfd): # assert 'KeyboardInterrupt' in cap.err +def test_auto_restart_arg_parsing_basic(): + args = watchmedo.cli.parse_args(["auto-restart", "-d", ".", "cmd"]) + assert args.func is watchmedo.auto_restart + assert args.command == "cmd" + assert args.directories == ["."] + + +def test_auto_restart_arg_parsing_kill_after(): + args = watchmedo.cli.parse_args(["auto-restart", "-d", ".", "--kill-after", "12.5", "cmd"]) + assert args.func is watchmedo.auto_restart + assert args.command == "cmd" + assert args.directories == ["."] + assert args.kill_after == pytest.approx(12.5) + + @pytest.mark.parametrize("command", ["tricks-from", "tricks"]) def test_tricks_from_file(command, tmp_path): tricks_file = tmp_path / "tricks.yaml"