23
24
from quickstart import manage
26
@mock.patch('quickstart.manage.sys.exit')
27
@mock.patch('quickstart.manage.IOLoop')
28
class TestExit(unittest.TestCase):
30
def test_io_loop_stopped(self, mock_io_loop, mock_exit):
31
# The Tornado IO loop is stopped.
33
io_loop = mock_io_loop.instance
34
io_loop.assert_called_once_with()
35
io_loop().stop.assert_called_once_with()
37
def test_exit_without_errors(self, mock_io_loop, mock_exit):
38
# The application correctly exits without errors.
40
mock_exit.assert_called_once_with(None)
42
def test_exit_with_errors(self, mock_io_loop, mock_exit):
43
# It is possible to pass an error when quitting the application.
44
manage.exit('bad wolf')
45
mock_exit.assert_called_once_with('bad wolf')
27
class TestDescriptionAction(unittest.TestCase):
30
self.parser = argparse.ArgumentParser()
31
self.parser.add_argument(
32
'--test', action=manage._DescriptionAction, nargs=0)
34
@mock.patch('sys.exit')
35
@mock.patch('__builtin__.print')
36
def test_action(self, mock_print, mock_exit):
37
# The action just prints the description and exits.
38
args = self.parser.parse_args(['--test'])
39
self.assertIsNone(args.test)
40
mock_print.assert_called_once_with(manage.description)
41
mock_exit.assert_called_once_with(0)