From 3f153b485ab7a6814358f01cec40db070b8b6a17 Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Wed, 17 Feb 2016 10:47:15 +0000 Subject: [PATCH] Update docstring in test/tools.py Update of docstring in test/tools.py to better align it and remove pep8 warning. This patch is a result of comment in change I8d03528f8f45f5f50fa467b39245a513a37c5d89 where it was suggested to move the docstring update to its own patch. Change-Id: Ib85bbea02fff87ce10e00483b53200dc3b89202a --- neutron/tests/tools.py | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py index 44b53f14e74..c5bc4bc5497 100644 --- a/neutron/tests/tools.py +++ b/neutron/tests/tools.py @@ -109,10 +109,15 @@ class SafeCleanupFixture(fixtures.Fixture): self.addCleanup(cleanUp) -"""setup_mock_calls and verify_mock_calls are convenient methods -to setup a sequence of mock calls. +import unittest -expected_calls_and_values is a list of (expected_call, return_value): +from neutron.common import utils + + +def setup_mock_calls(mocked_call, expected_calls_and_values): + """A convenient method to setup a sequence of mock calls. + + expected_calls_and_values is a list of (expected_call, return_value): expected_calls_and_values = [ (mock.call(["ovs-vsctl", self.TO, '--', "--may-exist", "add-port", @@ -124,23 +129,34 @@ expected_calls_and_values is a list of (expected_call, return_value): .... ] -* expected_call should be mock.call(expected_arg, ....) -* return_value is passed to side_effect of a mocked call. - A return value or an exception can be specified. -""" - -import unittest - -from neutron.common import utils - - -def setup_mock_calls(mocked_call, expected_calls_and_values): + * expected_call should be mock.call(expected_arg, ....) + * return_value is passed to side_effect of a mocked call. + A return value or an exception can be specified. + """ return_values = [call[1] for call in expected_calls_and_values] mocked_call.side_effect = return_values def verify_mock_calls(mocked_call, expected_calls_and_values, any_order=False): + """A convenient method to setup a sequence of mock calls. + + expected_calls_and_values is a list of (expected_call, return_value): + + expected_calls_and_values = [ + (mock.call(["ovs-vsctl", self.TO, '--', "--may-exist", "add-port", + self.BR_NAME, pname]), + None), + (mock.call(["ovs-vsctl", self.TO, "set", "Interface", + pname, "type=gre"]), + None), + .... + ] + + * expected_call should be mock.call(expected_arg, ....) + * return_value is passed to side_effect of a mocked call. + A return value or an exception can be specified. + """ expected_calls = [call[0] for call in expected_calls_and_values] mocked_call.assert_has_calls(expected_calls, any_order=any_order)