"Fossies" - the Fresh Open Source Software Archive

Member "tacker-2.0.0/tacker/tests/tools.py" (16 Oct 2019, 1738 Bytes) of package /linux/misc/openstack/tacker-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # Copyright (c) 2013 NEC Corporation
    2 # All Rights Reserved.
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 
   16 """setup_mock_calls and verify_mock_calls are convenient methods
   17 to setup a sequence of mock calls.
   18 
   19 expected_calls_and_values is a list of (expected_call, return_value):
   20 
   21         expected_calls_and_values = [
   22             (mock.call(["ovs-vsctl", self.TO, '--', "--may-exist", "add-port",
   23                         self.BR_NAME, pname], root_helper=self.root_helper),
   24              None),
   25             (mock.call(["ovs-vsctl", self.TO, "set", "Interface",
   26                         pname, "type=gre"], root_helper=self.root_helper),
   27              None),
   28             ....
   29         ]
   30 
   31 * expected_call should be mock.call(expected_arg, ....)
   32 * return_value is passed to side_effect of a mocked call.
   33   A return value or an exception can be specified.
   34 """
   35 
   36 
   37 def setup_mock_calls(mocked_call, expected_calls_and_values):
   38     return_values = [call[1] for call in expected_calls_and_values]
   39     mocked_call.side_effect = return_values
   40 
   41 
   42 def verify_mock_calls(mocked_call, expected_calls_and_values):
   43     expected_calls = [call[0] for call in expected_calls_and_values]
   44     mocked_call.assert_has_calls(expected_calls)