Permalink
Browse files

Fix #52: Add quit command and unit test

  • Loading branch information...
1 parent e9a1425 commit aa7a03cd32e02bd142a388c0b7cf876f3208eae6 @donnemartin committed May 23, 2016
Showing with 17 additions and 1 deletion.
  1. +10 −1 haxor_news/haxor.py
  2. +7 −0 tests/test_haxor.py
View
@@ -185,6 +185,15 @@ def _add_comment_pagination(self, document_text):
document_text += self.PAGINATE_CMD
return document_text
+ def handle_exit(self, document):
+ """Exits if the user typed exit or quit
+
+ :type document: :class:`prompt_toolkit.document.Document`
+ :param document: An instance of `prompt_toolkit.document.Document`.
+ """
+ if document.text in ('exit', 'quit'):
+ sys.exit()
+
def run_command(self, document):
"""Run the given command.
@@ -204,5 +213,5 @@ def run_cli(self):
click.echo('Syntax: hn <command> [params] [options]')
while True:
document = self.cli.run()
- if (document.text == 'exit'): sys.exit()
+ self.handle_exit(document)
self.run_command(document)
View
@@ -54,3 +54,10 @@ def test_run_command(self, mock_subprocess_call):
self.haxor.run_command(document)
mock_subprocess_call.assert_called_with('hn view 1',
shell=True)
+
+ @mock.patch('haxor_news.haxor.sys.exit')
+ def test_exit_command(self, mock_sys_exit):
+ document = mock.Mock()
+ document.text = 'exit'
+ self.haxor.handle_exit(document)
+ mock_sys_exit.assert_called_with()

0 comments on commit aa7a03c

Please sign in to comment.