~frankban/juju-gui/quickstart-initial

« back to all changes in this revision

Viewing changes to quickstart/tests/test_manage.py

  • Committer: Francesco Banconi
  • Date: 2013-10-14 15:24:29 UTC
  • Revision ID: francesco.banconi@canonical.com-20131014152429-9v1tkogs189u1jc7
Remove tornado.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the Juju Quickstart management infrastructure."""
18
18
 
 
19
import argparse
19
20
import unittest
20
21
 
21
22
import mock
23
24
from quickstart import manage
24
25
 
25
26
 
26
 
@mock.patch('quickstart.manage.sys.exit')
27
 
@mock.patch('quickstart.manage.IOLoop')
28
 
class TestExit(unittest.TestCase):
29
 
 
30
 
    def test_io_loop_stopped(self, mock_io_loop, mock_exit):
31
 
        # The Tornado IO loop is stopped.
32
 
        manage.exit()
33
 
        io_loop = mock_io_loop.instance
34
 
        io_loop.assert_called_once_with()
35
 
        io_loop().stop.assert_called_once_with()
36
 
 
37
 
    def test_exit_without_errors(self, mock_io_loop, mock_exit):
38
 
        # The application correctly exits without errors.
39
 
        manage.exit()
40
 
        mock_exit.assert_called_once_with(None)
41
 
 
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):
 
28
 
 
29
    def setUp(self):
 
30
        self.parser = argparse.ArgumentParser()
 
31
        self.parser.add_argument(
 
32
            '--test', action=manage._DescriptionAction, nargs=0)
 
33
 
 
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)