Skip to content

Commit

Permalink
Add stop command to shell.
Browse files Browse the repository at this point in the history
  • Loading branch information
codito committed Oct 5, 2014
1 parent c15e9dc commit 4bedc9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pomito/plugins/ui/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ def pomito_shell():
def pomito_start(task_id):
"""Starts a pomito session."""
pomodoro_service = _get_pomodoro_service()
tasks = pomodoro_service.get_tasks()
tasks = list(pomodoro_service.get_tasks())
pomodoro_service.start_session(tasks[int(task_id)])

@pomito_shell.command("stop")
def pomito_stop():
"""Stops a pomito session."""
pomodoro_service = _get_pomodoro_service()
pomodoro_service.stop_session()

@pomito_shell.command("list")
@click.argument('task_filter', type=str, required=False)
def pomito_list(task_filter=None):
Expand Down
18 changes: 17 additions & 1 deletion tests/plugins/ui/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def setUp(self):
self.task_list.append(t)
self.pomodoro_service._pomito_instance\
.task_plugin = FakeTaskPlugin()
# Task list should be a generator as per TaskPlugin.get_tasks
self.pomodoro_service._pomito_instance\
.task_plugin.task_list = self.task_list
.task_plugin.task_list = (t for t in self.task_list)
self.dummy_callback = Mock()

def tearDown(self):
Expand Down Expand Up @@ -87,6 +88,21 @@ def test_start_starts_a_pomodoro_session(self):
self.pomodoro_service.signal_session_started\
.disconnect(self.dummy_callback)

def test_stop_stops_a_pomodoro_session(self):
self.pomodoro_service.signal_session_stopped\
.connect(self.dummy_callback, weak=False)

out = self._invoke_command("stop")

expect(out.exit_code).to.be(0)
expect(self.dummy_callback.call_count).to.equal(1)

self.pomodoro_service.signal_session_stopped\
.disconnect(self.dummy_callback)

def test_stop_shows_message_if_no_active_session(self):
pass

def _invoke_command(self, command, args=None):
args_list = [command, args] if args is not None else [command]
out = self.runner.invoke(pomito_shell, args_list,
Expand Down

0 comments on commit 4bedc9a

Please sign in to comment.