diff options
author | Daniel Edgy Edgecombe <edgy.edgemond@gmail.com> | 2022-07-15 10:50:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-15 11:50:20 +0200 |
commit | d9de4fcf3ab74f981c92c7391f4f6887971b9707 (patch) | |
tree | 4a5254b6328da54cc674fabad15715408f870af2 | |
parent | df4b72060b1fc4edaae0a93dbf36bf247410fcf3 (diff) |
* pass start at time to stop invoke
* add test for start at, with running frame
* no need for multiple times, tested in other start test
* update cli comment
* update docs
* assert first frame closed, and current frame tracked
PR: https://github.com/TailorDev/Watson/pull/480
-rw-r--r-- | docs/user-guide/commands.md | 3 | ||||
-rw-r--r-- | tests/test_cli.py | 26 | ||||
-rw-r--r-- | watson/cli.py | 5 |
3 files changed, 31 insertions, 3 deletions
diff --git a/docs/user-guide/commands.md b/docs/user-guide/commands.md index bf8474d..387639f 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: diff --git a/tests/test_cli.py b/tests/test_cli.py index 2a1b3a5..5c28317 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -196,6 +196,32 @@ def test_start_valid_time(runner, watson, mocker, at_dt): assert result.exit_code == 0 +# watson start new task in past, with existing task + +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) + 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 + + frame_id = OutputParser.get_frame_id(result.output) + assert watson.frames[frame_id].project == "a-project" + assert watson.current["project"] == "b-project" + + # watson restart @pytest.mark.parametrize('at_dt', VALID_TIMES_DATA) diff --git a/watson/cli.py b/watson/cli.py index bd3bd52..377b76b 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: @@ -273,7 +274,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_) |