Skip to content

Commit

Permalink
Fix "start --at" fail when stopping a current project (#480)
Browse files Browse the repository at this point in the history
* 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: #480
  • Loading branch information
EdgyEdgemond authored Jul 15, 2022
1 parent df4b720 commit d9de4fc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/user-guide/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
26 changes: 26 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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_)

Expand Down

0 comments on commit d9de4fc

Please sign in to comment.