How to use the mock.patch.multiple function in mock

To help you get started, we’ve selected a few mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yubico / python-fido2 / test / _pyu2f / test_macos.py View on Github external
  @mock.patch.multiple(macos, iokit=mock.DEFAULT, cf=mock.DEFAULT,
                       GetDeviceIntProperty=mock.DEFAULT)
  def testInitHidDevice(self, thread, iokit, cf, GetDeviceIntProperty):  # pylint: disable=invalid-name
    init_mock_iokit(iokit)
    init_mock_cf(cf)
    init_mock_get_int_property(GetDeviceIntProperty)

    device = macos.MacOsHidDevice('1')

    self.assertEqual(64, device.GetInReportDataLength())
    self.assertEqual(64, device.GetOutReportDataLength())
github testing-cabal / mock / tests / testpatch.py View on Github external
        @patch.multiple(foo_name, f=3, g=4)
        def test():
            self.assertIs(Foo, original_foo)
            self.assertEqual(Foo.f, 3)
            self.assertEqual(Foo.g, 4)
github openstack / openstack-ansible / tests / test_inventory.py View on Github external
def test_group_with_hosts_and_children_fails(self):
        """Integration test making sure the whole script fails."""
        env = self._create_bad_env(self.env)


        config = get_config()

        kwargs = {
            'load_environment': mock.DEFAULT,
            'load_user_configuration': mock.DEFAULT
        }

        with mock.patch.multiple('osa_toolkit.filesystem', **kwargs) as mocks:
            mocks['load_environment'].return_value = env
            mocks['load_user_configuration'].return_value = config

            with self.assertRaises(di.GroupConflict) as context:
                get_inventory()
github requests / requests-kerberos / tests / test_requests_kerberos.py View on Github external
def test_principal_override(self):
        with patch.multiple(kerberos_module_name,
                            authGSSClientInit=clientInit_complete,
                            authGSSClientResponse=clientResponse,
                            authGSSClientStep=clientStep_continue):
            response = requests.Response()
            response.url = "http://www.example.org/"
            response.headers = {'www-authenticate': 'negotiate token'}
            host = urlparse(response.url).hostname
            auth = requests_kerberos.HTTPKerberosAuth(principal="user@REALM")
            auth.generate_request_header(response, host)
            clientInit_complete.assert_called_with(
                "HTTP@www.example.org",
                gssflags=(
                    kerberos.GSS_C_MUTUAL_FLAG |
                    kerberos.GSS_C_SEQUENCE_FLAG),
                principal="user@REALM")
github presslabs / gitfs / tests / test_router.py View on Github external
def test_destroy(self):
        mocked_fetch = MagicMock()
        mocked_sync = MagicMock()

        router, mocks = self.get_new_router()
        router.workers = [mocked_fetch, mocked_sync]

        with patch.multiple(
            "gitfs.router",
            shutil=mocks["shutil"],
            fetch=mocks["fetch"],
            shutting_down=mocks["shutting"],
        ):
            router.destroy("path")

        assert mocked_fetch.join.call_count == 1
        assert mocked_sync.join.call_count == 1
        assert mocks["fetch"].set.call_count == 1
        assert mocks["shutting"].set.call_count == 1
        mocks["shutil"].rmtree.assert_called_once_with(mocks["repo_path"])
github kk7ds / somecomfort / tests / test_client.py View on Github external
def test_relogin(self):
        recorder = betamax.Betamax(self.session)
        with recorder.use_cassette('relogin'):
            with mock.patch.multiple(
                    'somecomfort.SomeComfort',
                    _login=mock.DEFAULT,
                    _discover=mock.DEFAULT,
                    keepalive=mock.DEFAULT) as (l, d, k):
                SomeComfort.keepalive.side_effect = somecomfort.SessionTimedOut
                c = SomeComfort(self.username, self.password)
                c._login.assert_called_once_with()
            with mock.patch.object(c, 'keepalive') as mock_k:
                tries = [1]

                def fake_keepalive():
                    if tries:
                        tries.pop()
                        raise somecomfort.SessionTimedOut()

                mock_k.side_effect = fake_keepalive
github presslabs / gitfs / tests / test_router.py View on Github external
"remote_url": "remote_url",
            "repo_path": "repository_path",
            "mount_path": "mount_path",
            "credentials": mocked_credentials,
            "branch": mocked_branch,
            "user": "user",
            "group": "root",
            "commit_queue": mocked_queue,
            "max_size": 10,
            "max_offset": 10,
            "ignore_file": "",
            "module_file": "",
            "hard_ignore": None,
        }

        with patch.multiple(
            "gitfs.router",
            Repository=mocked_repository,
            log=mocked_log,
            CachedIgnore=mocked_ignore,
            lru_cache=mocked_lru,
            getpwnam=mocked_pwnam,
            getgrnam=mocked_grnam,
            time=mocked_time,
            shutil=mocked_shutil,
            fetch=mocked_fetch,
            shutting_down=mocked_shutting,
        ):
            router = Router(**init_kwargs)

        mocks.update(init_kwargs)
        return router, mocks
github python-provy / provy / tests / unit / core / test_roles.py View on Github external
def test_script_converted(self):
        with patch.multiple("provy.core.roles.Role", execute=DEFAULT,
                            create_remote_temp_file=DEFAULT,
                            put_file=DEFAULT) as values:
            values['create_remote_temp_file'].return_value = "/tmp/scriptfoo.py"
            self.role.execute_python_script("script", False, False)

        self.assertTrue(isinstance(values['put_file'].mock_calls[0][1][0], StringIO))
github jsdir / stretch / tests / stretch / test_config_managers.py View on Github external
    @patch.multiple('stretch.config_managers.ConfigManager', get_key=DEFAULT)
    def test_remove_env(self, get_key):
        get_key.return_value = '/e'
        env = Mock()
        self.cm.delete = Mock()
        self.cm.remove_env(env)
        self.cm.delete.assert_called_with('/e')
github dirkwallenstein / vim-localcomplete / pylibs / localcomplete_tests.py View on Github external
def _helper_isolate_sut(self,
            match_result_order,
            expected_result_lines,
            buffer_content=("0", "1", "2", "3", "4", "5", "6"),
            above_range=range(1, 3),
            current_index=3,
            below_range=range(4, 6)):

        vim_mock = VimMockFactory.get_mock(
                match_result_order=match_result_order,
                buffer_content=buffer_content)
        buffer_range_mock = mock.Mock(
                return_value=(above_range, current_index, below_range))

        with mock.patch.multiple(__name__ + '.localcomplete',
                get_buffer_ranges=buffer_range_mock,
                vim=vim_mock):
            actual_result = list(localcomplete.generate_haystack())
        self.assertEqual(actual_result, expected_result_lines)