From 488272ee590364128741af3e5f84eebc0db4b19b Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Mon, 5 Jan 2015 11:23:56 +0000 Subject: 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 --- tests/unit/test_shell.py | 23 +++++++++++------------ 1 file 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): -- cgit v1.2.1