diff options
author | Alistair Coles <alistair.coles@hp.com> | 2015-01-05 11:23:56 +0000 |
---|---|---|
committer | Alistair Coles <alistair.coles@hp.com> | 2015-01-05 11:23:56 +0000 |
commit | 488272ee590364128741af3e5f84eebc0db4b19b (patch) | |
tree | 030eaff29bf8406a483d926b23d4d95a65e337b7 | |
parent | 5d5701870702a554dcea61213999670ee15f4ea8 (diff) | |
download | python-swiftclient-488272ee590364128741af3e5f84eebc0db4b19b.tar.gz |
Change tests to use CaptureOutput class
Modify two tests to use the CaptureOutput class. These
tests were added after the comprehensive transition to using
CaptureOutput made in change [1], so this is just bringing
them in line with that test pattern.
Also deletes an unused mock.
[1] change id Ib59bbbe88256f215eed0a8ebc8282e02181d4377
Change-Id: Ic524311ffb3b0d6566addec0676633ddb8075e25
-rw-r--r-- | tests/unit/test_shell.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 65530bc..34c1e76 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -225,19 +225,17 @@ class TestShell(unittest.TestCase): ' 0 0 ????-??-?? ??:??:?? container\n' ' 0 0\n') - @mock.patch('swiftclient.shell.OutputManager._print') - @mock.patch('swiftclient.service.Connection') - def test_list_account_totals_error(self, connection, error): + def test_list_account_totals_error(self): # No --lh provided: expect info message about incorrect --totals use argv = ["", "list", "--totals"] - self.assertRaises(SystemExit, swiftclient.shell.main, argv) - self.assertEqual(error.call_args[0][0], - "Listing totals only works with -l or --lh.") + with CaptureOutput() as output: + self.assertRaises(SystemExit, swiftclient.shell.main, argv) + self.assertEqual(output.err, + "Listing totals only works with -l or --lh.\n") - @mock.patch('swiftclient.shell.OutputManager._print') @mock.patch('swiftclient.service.Connection') - def test_list_account_totals(self, connection, mock_print): + def test_list_account_totals(self, connection): # Test account listing, only total count and size connection.return_value.get_account.side_effect = [ @@ -247,10 +245,11 @@ class TestShell(unittest.TestCase): ] argv = ["", "list", "--lh", "--totals"] - swiftclient.shell.main(argv) - calls = [mock.call(marker='', prefix=None)] - connection.return_value.get_account.assert_has_calls(calls) - mock_print.assert_called_once_with(' 6 3') + with CaptureOutput() as output: + swiftclient.shell.main(argv) + calls = [mock.call(marker='', prefix=None)] + connection.return_value.get_account.assert_has_calls(calls) + self.assertEqual(output.out, ' 6 3\n') @mock.patch('swiftclient.service.Connection') def test_list_container(self, connection): |