From 266108420018d16d35978b8be58f6ff63e30f234 Mon Sep 17 00:00:00 2001 From: EdgyEdgemond Date: Tue, 12 Jul 2022 11:15:00 +0100 Subject: [PATCH 1/6] pass start at time to stop invoke --- watson/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watson/cli.py b/watson/cli.py index bd3bd527..9214eaaa 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -273,7 +273,7 @@ def start(ctx, watson, confirm_new_project, confirm_new_tag, args, at_, if (project and watson.is_started and watson.config.getboolean('options', 'stop_on_start')): - ctx.invoke(stop) + ctx.invoke(stop, at_=at_) _start(watson, project, tags, start_at=at_, gap=gap_) From 9337b49217b835a8b23fea55b8b3b9d70d92b13a Mon Sep 17 00:00:00 2001 From: EdgyEdgemond Date: Tue, 12 Jul 2022 14:43:06 +0100 Subject: [PATCH 2/6] add test for start at, with running frame --- tests/test_cli.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 2a1b3a52..4edaf170 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -196,6 +196,25 @@ def test_start_valid_time(runner, watson, mocker, at_dt): assert result.exit_code == 0 +# watson start new task in past, with existing task + +@pytest.mark.parametrize('at_dt', VALID_TIMES_DATA) +def test_start_existing_frame_stopped(runner, watson, mocker, at_dt): + # Simulate a start date so that 'at_dt' is older than now(). + watson.config.set('options', 'stop_on_start', "true") + mocker.patch('arrow.arrow.dt_datetime', wraps=datetime) + start_dt = datetime(2019, 4, 10, 15, 0, 0, tzinfo=local_tz_info()) + arrow.arrow.dt_datetime.now.return_value = start_dt + runner.invoke(cli.start, ['a-project', '--at', "14:10"], obj=watson) + + result = runner.invoke( + cli.start, + ['b-project', '--at', "14:15"], + obj=watson, + ) + assert result.exit_code == 0, result.stdout + + # watson restart @pytest.mark.parametrize('at_dt', VALID_TIMES_DATA) From 3f642c82448d44dcfe996b2e829ebaf1b1b72155 Mon Sep 17 00:00:00 2001 From: EdgyEdgemond Date: Tue, 12 Jul 2022 14:44:05 +0100 Subject: [PATCH 3/6] no need for multiple times, tested in other start test --- tests/test_cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4edaf170..a19ba59b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -198,8 +198,7 @@ def test_start_valid_time(runner, watson, mocker, at_dt): # watson start new task in past, with existing task -@pytest.mark.parametrize('at_dt', VALID_TIMES_DATA) -def test_start_existing_frame_stopped(runner, watson, mocker, at_dt): +def test_start_existing_frame_stopped(runner, watson, mocker): # Simulate a start date so that 'at_dt' is older than now(). watson.config.set('options', 'stop_on_start', "true") mocker.patch('arrow.arrow.dt_datetime', wraps=datetime) From 341160bc6a60b980f055736db201823a28b6469d Mon Sep 17 00:00:00 2001 From: EdgyEdgemond Date: Tue, 12 Jul 2022 16:14:08 +0100 Subject: [PATCH 4/6] update cli comment --- watson/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/watson/cli.py b/watson/cli.py index 9214eaaa..377b76b5 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -225,7 +225,8 @@ def start(ctx, watson, confirm_new_project, confirm_new_tag, args, at_, If `--at` option is given, the provided starting time is used. The specified time must be after the end of the previous frame and must not be - in the future. + in the future. If there is a current frame running, it will be stopped at + the provided time. Example: From 40141e3af5166d4099999674be074a49f2b619fa Mon Sep 17 00:00:00 2001 From: EdgyEdgemond Date: Tue, 12 Jul 2022 16:15:40 +0100 Subject: [PATCH 5/6] update docs --- docs/user-guide/commands.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/user-guide/commands.md b/docs/user-guide/commands.md index bf8474d8..387639f1 100644 --- a/docs/user-guide/commands.md +++ b/docs/user-guide/commands.md @@ -637,7 +637,8 @@ If there is already a running project and the configuration option If `--at` option is given, the provided starting time is used. The specified time must be after the end of the previous frame and must not be -in the future. +in the future. If there is a current frame running, it will be stopped at +the provided time. Example: From 4e6dadcb3b6b5bf729fb8e2f942a59aa4941d3eb Mon Sep 17 00:00:00 2001 From: EdgyEdgemond Date: Wed, 13 Jul 2022 09:04:20 +0100 Subject: [PATCH 6/6] assert first frame closed, and current frame tracked --- tests/test_cli.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index a19ba59b..5c283171 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -204,7 +204,11 @@ def test_start_existing_frame_stopped(runner, watson, mocker): mocker.patch('arrow.arrow.dt_datetime', wraps=datetime) start_dt = datetime(2019, 4, 10, 15, 0, 0, tzinfo=local_tz_info()) arrow.arrow.dt_datetime.now.return_value = start_dt - runner.invoke(cli.start, ['a-project', '--at', "14:10"], obj=watson) + runner.invoke( + cli.start, + ['a-project', '--at', "14:10"], + obj=watson, + ) result = runner.invoke( cli.start, @@ -213,6 +217,10 @@ def test_start_existing_frame_stopped(runner, watson, mocker): ) assert result.exit_code == 0, result.stdout + frame_id = OutputParser.get_frame_id(result.output) + assert watson.frames[frame_id].project == "a-project" + assert watson.current["project"] == "b-project" + # watson restart