• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mock.assert_called_once_with函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mock.assert_called_once_with函数的典型用法代码示例。如果您正苦于以下问题:Python assert_called_once_with函数的具体用法?Python assert_called_once_with怎么用?Python assert_called_once_with使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_called_once_with函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_search_several_param

 def test_search_several_param(self, mock):
     keywords = ['one', 'two']
     mock.return_value = (200, MOCK_CONFIGURATION_SEARCH_JSON, MOCK_CONFIGURATION_SEARCH_JSON_RAW)
     status_code, json_response = maccli.dao.api_configuration.search_public_configuration(keywords)
     mock.assert_called_once_with("GET", "/configuration/search?keyword=one&keyword=two")
     self.assertEqual(json_response, MOCK_CONFIGURATION_SEARCH_JSON)
     self.assertEqual(status_code, 200)
开发者ID:TomA-R,项目名称:manageacloud-cli,代码行数:7,代码来源:test_dao_api_configuration.py


示例2: test_instance_destroy_error_not_found

 def test_instance_destroy_error_not_found(self, mock):
     mock.return_value = (404, None, "Error Response")
     json_response = maccli.dao.api_instance.destroy(DEFAULT_SERVERNAME)
     mock.assert_called_once_with("DELETE", "/instance/%s" % DEFAULT_SERVERNAME)
     error = self.buf.getvalue()
     self.assertEqual(' '.join(MOCK_RESPONSE_INSTANCE_DESTROY_NOT_FOUND.split()), ' '.join(error.split()))
     self.assertEqual(json_response, None)
开发者ID:TomA-R,项目名称:manageacloud-cli,代码行数:7,代码来源:test_dao_api_instance.py


示例3: _test_assert_called_once_with

    def _test_assert_called_once_with(self, mock, resource,
                                      chk_interval, time_out, **kwargs):
        """Method to replace repeatative asserts on resources

        :param mock: The mock to call assert with
        :param resource: The resource used in mock
        :param chk_interval: The interval used for polling the action
        :param time_out: Time out value for action
        :param kwargs: currently used for validating the is_ready attribute,
        can be extended as required
        """

        isready = self.res_is.mock()
        if kwargs:
            if kwargs["is_ready"]:
                mock.assert_called_once_with(
                    resource,
                    update_resource=self.gfm(),
                    is_ready=isready,
                    check_interval=chk_interval,
                    timeout=time_out)
            else:
                mock.assert_called_once_with(
                    resource,
                    update_resource=self.gfm(),
                    check_interval=chk_interval,
                    timeout=time_out)
开发者ID:zhengzhenyu,项目名称:rally,代码行数:27,代码来源:test_utils.py


示例4: test_ip_ns_route

 def test_ip_ns_route(self, mock):
     ns_list = commands.ip_ns_list()
     for ns in ns_list:
         expected = ['/usr/bin/sudo', '-n', 'ip', 'netns', 'exec', ns,
                     'ip', 'r']
         commands.ip_ns_route(ns)
         mock.assert_called_once_with(expected, **self.subprocess_args)
开发者ID:Mirantis,项目名称:tempest,代码行数:7,代码来源:test_commands.py


示例5: test_hardwares_ok

 def test_hardwares_ok(self, mock):
     mock.return_value = (200, MOCK_HARDWARE_LIST_JSON, MOCK_HARDWARE_LIST_JSON_RAW)
     status_code, json_response = maccli.dao.api_provider.get_hardwares(DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_CONFIGURATION, DEFAULT_RELEASE)
     mock.assert_called_once_with("GET", "/provider/hardware?provider=%s&location=%s&release=%s&cookbook_tag=%s" % (
     DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_RELEASE, DEFAULT_CONFIGURATION))
     self.assertEqual(json_response, MOCK_HARDWARE_LIST_JSON)
     self.assertEqual(status_code, 200)
开发者ID:moriano,项目名称:manageacloud-cli,代码行数:7,代码来源:test_dao_api_provider.py


示例6: test_locations

 def test_locations(self, mock):
     mock.return_value = (200, MOCK_LOCATION_LIST_JSON, MOCK_LOCATION_LIST_JSON_RAW)
     status_code, json_response = maccli.dao.api_provider.get_locations(DEFAULT_CONFIGURATION, DEFAULT_PROVIDER)
     mock.assert_called_once_with("GET", "/provider/locations?cookbook_tag=%s&provider=%s" % (
     DEFAULT_CONFIGURATION, DEFAULT_PROVIDER))
     self.assertEqual(json_response, MOCK_LOCATION_LIST_JSON)
     self.assertEqual(status_code, 200)
开发者ID:moriano,项目名称:manageacloud-cli,代码行数:7,代码来源:test_dao_api_provider.py


示例7: test_iptables_raw

 def test_iptables_raw(self, mock):
     table = 'filter'
     expected = ['/usr/bin/sudo', '-n', 'iptables', '--line-numbers',
                 '-L', '-nv', '-t',
                 '%s' % table]
     commands.iptables_raw(table)
     mock.assert_called_once_with(expected, **self.subprocess_args)
开发者ID:Mirantis,项目名称:tempest,代码行数:7,代码来源:test_commands.py


示例8: test_instance_destroy_error

 def test_instance_destroy_error(self, mock):
     mock.return_value = (400, None, "Error Response")
     json_response = maccli.dao.api_instance.destroy(DEFAULT_SERVER_ID)
     mock.assert_called_once_with("DELETE", "/instance/%s" % DEFAULT_SERVER_ID)
     error = self.buf.getvalue()
     self.assertEqual(" ".join(MOCK_RESPONSE_INSTANCE_DESTROY_ERROR.split()), " ".join(error.split()))
     self.assertEqual(json_response, None)
开发者ID:moriano,项目名称:manageacloud-cli,代码行数:7,代码来源:test_dao_api_instance.py


示例9: test_is_tracing_returns_what_tracing_percent_method_returns_for_rest

def test_is_tracing_returns_what_tracing_percent_method_returns_for_rest(
    mock, dummy_request
):
    dummy_request.zipkin_trace_id = '42'
    assert mock.return_value == request_helper.is_tracing(dummy_request)
    mock.assert_called_once_with(
        request_helper.DEFAULT_REQUEST_TRACING_PERCENT, '42'
    )
开发者ID:kaisen,项目名称:pyramid_zipkin,代码行数:8,代码来源:request_helper_test.py


示例10: test_iptables_ns

 def test_iptables_ns(self, mock):
     table = 'filter'
     ns_list = commands.ip_ns_list()
     for ns in ns_list:
         expected = ['/usr/bin/sudo', '-n', 'ip', 'netns', 'exec', ns,
                     'iptables', '-v', '-S', '-t', table]
         commands.iptables_ns(ns, table)
         mock.assert_called_once_with(expected, **self.subprocess_args)
开发者ID:Mirantis,项目名称:tempest,代码行数:8,代码来源:test_commands.py


示例11: test_hardwares_error

 def test_hardwares_error(self, mock):
     mock.return_value = (400, None, "No credentials available")
     status_code, json_response = maccli.dao.api_provider.get_hardwares(DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_CONFIGURATION, DEFAULT_RELEASE)
     mock.assert_called_once_with("GET", "/provider/hardware?provider=%s&location=%s&release=%s&cookbook_tag=%s" % (
     DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_RELEASE, DEFAULT_CONFIGURATION))
     self.assertEqual(json_response, None)
     self.assertEqual(status_code, 400)
     out = self.buf.getvalue()
     self.assertEqual(' '.join(OUTPUT_HARDWARES_NO_CREDENTIALS.split()), ' '.join(out.split()))
开发者ID:moriano,项目名称:manageacloud-cli,代码行数:9,代码来源:test_dao_api_provider.py


示例12: test_output_is_sourceable

def test_output_is_sourceable(mock, releases_dictionary):
    bash_script = '/foo/bar.sh'
    assert (write_releases_dictionary_to_bash(releases_dictionary,
                                              bash_script))
    mock.assert_called_once_with(bash_script, 'w')
    handle = mock()
    args, _ = handle.write.call_args
    written_content = args[0]
    # TODO(Llorente): check environment variables
    assert (0 == os.system(written_content))
开发者ID:openstack-infra,项目名称:tripleo-ci,代码行数:10,代码来源:test_write_bash_script.py


示例13: test_instance_create_error

 def test_instance_create_error(self, mock):
     mock.return_value = (400, None, "Error Response")
     json_response = maccli.dao.api_instance.create(DEFAULT_CONFIGURATION, DEFAULT_BOOTSTRAP, DEFAULT_DEPLOYMENT, DEFAULT_LOCATION,
                                                    DEFAULT_SERVERNAME,
                                                    DEFAULT_PROVIDER, DEFAULT_RELEASE, DEFAULT_RELEASE_VERSION, DEFAULT_BRANCH,
                                                    DEFAULT_HARDWARE, DEFAULT_LIFESPAN, DEFAULT_ENVIRONMENT,
                                                    DEFAULT_HD, DEFAULT_PORT, DEFAULT_NET, DEFAULT_METADATA, DEFAULT_APPLYCHANGES)
     mock.assert_called_once_with("POST", "/instance", data=MOCK_INSTANCE_CREATE_PARAMETERS_JSON_RAW)
     error = self.buf.getvalue()
     self.assertEqual(' '.join(MOCK_RESPONSE_INSTANCE_CREATE_ERROR.split()), ' '.join(error.split()))
     self.assertEqual(json_response, None)
开发者ID:TomA-R,项目名称:manageacloud-cli,代码行数:11,代码来源:test_dao_api_instance.py


示例14: test_all_running_options

    def test_all_running_options(self, mock):
        jid = "[email protected]"
        room = "[email protected]"
        password = "password"
        nick = "nick"

        args = ["test", "-j", jid, "-p", password, "-r", room, "-n", nick]

        self.assertIsNone(nonobot.main.main(args))

        mock.assert_called_once_with(jid=jid, room=room, password=password, nick=nick, plugins={"help": []})
开发者ID:EmilienM,项目名称:python-nonobot,代码行数:11,代码来源:test_main.py


示例15: test_list_with_pagination

    def test_list_with_pagination(self, mock):

        self.call(execution_cmd.List)
        mock.assert_called_once_with(limit=None, marker='',
                                     sort_dirs='asc',
                                     sort_keys='created_at')

        self.call(execution_cmd.List, app_args=['--limit', '5',
                                                '--sort_dirs', 'id, Workflow',
                                                '--sort_keys', 'desc',
                                                '--marker', 'abc'])

        mock.assert_called_with(limit=5, marker='abc',
                                sort_dirs='id, Workflow',
                                sort_keys='desc')
开发者ID:aneeshkp,项目名称:python-mistralclient,代码行数:15,代码来源:test_cli_executions.py


示例16: test_assert_called_once_with

    def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock("foo", "bar", baz=2)
        mock.assert_called_once_with("foo", "bar", baz=2)

        mock.reset_mock()
        mock("foo", "bar", baz=2)
        self.assertRaises(AssertionError, lambda: mock.assert_called_once_with("bob", "bar", baz=2))
开发者ID:hiisi13,项目名称:python-mock,代码行数:19,代码来源:testmock.py


示例17: test_all_running_options

    def test_all_running_options(self, mock):
        jid = '[email protected]'
        room = '[email protected]'
        password = 'password'
        nick = 'nick'

        args = ['test',
                '-j', jid,
                '-p', password,
                '-r', room,
                '-n', nick]

        self.assertIsNone(nonobot.main.main(args, plugins={}))

        mock.assert_called_once_with(
            jid=jid,
            room=room,
            password=password,
            nick=nick,
            plugins={}
        )
开发者ID:Anhmike,项目名称:python-nonobot,代码行数:21,代码来源:test_main.py


示例18: test_assert_called_once_with_function_spec

    def test_assert_called_once_with_function_spec(self):
        def f(a, b, c, d=None):
            pass

        mock = Mock(spec=f)

        mock(1, b=2, c=3)
        mock.assert_called_once_with(1, 2, 3)
        mock.assert_called_once_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_once_with(e=8)
        if hasattr(cm.exception, '__cause__'):
            self.assertIsInstance(cm.exception.__cause__, TypeError)
        # Mock called more than once => always fails
        mock(4, 5, 6)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, 2, 3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          4, 5, 6)
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:22,代码来源:testmock.py


示例19: test_testfunc_calls_execute

 def test_testfunc_calls_execute(self, mock):
     obj = self.FakeNegativeJSONTest("test_fake_negative")
     self.assertIn("test_fake_negative", dir(obj))
     obj.test_fake_negative()
     mock.assert_called_once_with(self.FakeNegativeJSONTest._schema)
开发者ID:HybridF5,项目名称:tempest,代码行数:5,代码来源:test_decorators.py


示例20: test_search_no_params

 def test_search_no_params(self, mock):
     mock.return_value = (200, MOCK_CONFIGURATION_SEARCH_JSON, MOCK_CONFIGURATION_SEARCH_JSON_RAW)
     status_code, json_response = maccli.dao.api_configuration.search_public_configuration(None)
     mock.assert_called_once_with("GET", "/configuration/search")
     self.assertEqual(json_response, MOCK_CONFIGURATION_SEARCH_JSON)
     self.assertEqual(status_code, 200)
开发者ID:TomA-R,项目名称:manageacloud-cli,代码行数:6,代码来源:test_dao_api_configuration.py



注:本文中的mock.assert_called_once_with函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mock.assert_called_with函数代码示例发布时间:2022-05-27
下一篇:
Python mochitest_options.MochitestOptions类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap