当前位置: 首页>>代码示例>>Python>>正文


Python Mock.assert_any_call方法代码示例

本文整理汇总了Python中mock.Mock.assert_any_call方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.assert_any_call方法的具体用法?Python Mock.assert_any_call怎么用?Python Mock.assert_any_call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.Mock的用法示例。


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

示例1: TestBuilder

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
class TestBuilder(object):
    """
    """

    def setup_method(self, method):
        self.injector = Injector([SandboxModuleTest()])
        self.dispatcher = self.injector.get(Dispatcher)
        self.builder = self.injector.get(Builder)
        self._composer = self.injector.get(Composer)

        self._build = Mock()
        self.builder.build = self._build
        self.builder._composer = self._composer

    def test_build_not_sandbox_image(self):
        images = ['external1', 'sandbox/internal1']
        calls = ['internal1:master']

        options = {
            '<flavour>': 'with_external_component',
            '--force': True
        }

        self.dispatcher.build_all(options)
        for call in calls:
            self._build.assert_any_call(call)

        assert mock.call('external1') not in self._build.mock_calls
开发者ID:kalymero,项目名称:midonet-sandbox,代码行数:30,代码来源:test_builder.py

示例2: test_manager_should_call_all

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
 def test_manager_should_call_all(self):
     em = ExtensionManager.make_test_instance([test_extension2,
                                               test_extension])
     func = Mock()
     em.map(func)
     func.assert_any_call(test_extension2)
     func.assert_any_call(test_extension)
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:9,代码来源:test_test_manager.py

示例3: test_rmtree_success

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
    def test_rmtree_success(self):
        dir1_list = ["dir2", "file"]
        empty_list = []
        mock_listdir = Mock()
        mock_listdir.side_effect = [dir1_list, empty_list]

        mock_isdir = Mock()
        mock_isdir.side_effect = [True, False]

        mock_unlink = Mock()
        mock_unlink.return_value = 0

        mock_rmdir = Mock()
        mock_rmdir.return_value = 0

        mock_islink = Mock()
        mock_islink.return_value = False

        with nested(
            patch("glusterfs.gfapi.Volume.listdir", mock_listdir),
            patch("glusterfs.gfapi.Volume.isdir", mock_isdir),
            patch("glusterfs.gfapi.Volume.islink", mock_islink),
            patch("glusterfs.gfapi.Volume.unlink", mock_unlink),
            patch("glusterfs.gfapi.Volume.rmdir", mock_rmdir),
        ):
            self.vol.rmtree("dir1")
            mock_rmdir.assert_any_call("dir1/dir2")
            mock_unlink.assert_called_once_with("dir1/file")
            mock_rmdir.assert_called_with("dir1")
开发者ID:humblec,项目名称:libgfapi-python,代码行数:31,代码来源:test_gfapi.py

示例4: test_simple_handler

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
    def test_simple_handler(self):
        from slamon.agent.executor import Executor
        from slamon.agent.handlers import TaskHandler
        from mock import Mock

        mock_handler = Mock()
        mock_callback = Mock()

        @TaskHandler("test-task", 1)
        def test_handler(input_data):
            mock_handler()
            return input_data

        data = {"data": 1337}

        with Executor() as executor:
            executor.submit_task(
                {
                    "task_id": "123e4567-e89b-12d3-a456-426655440000",
                    "task_type": "test-task",
                    "task_version": 1,
                    "task_data": data,
                },
                mock_callback,
            )

        mock_handler.assert_any_call()
        mock_callback.assert_called_once_with("123e4567-e89b-12d3-a456-426655440000", task_data=data)
开发者ID:Korkkii,项目名称:SLAMon,代码行数:30,代码来源:executor_tests.py

示例5: test__init

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
 def test__init(self):
     mock_load_data = Mock()
     probes = self.get_obj(load_data=mock_load_data)
     mock_load_data.assert_any_call()
     self.assertEqual(probes.probedata,
                      ClientProbeDataSet())
     self.assertEqual(probes.cgroups, dict())
开发者ID:dhutty,项目名称:bcfg2,代码行数:9,代码来源:TestProbes.py

示例6: test_raising_handler

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
    def test_raising_handler(self):
        from slamon.agent.executor import Executor
        from slamon.agent.handlers import TaskHandler
        from mock import Mock, ANY

        mock_handler = Mock(side_effect=Exception)
        mock_callback = Mock()

        @TaskHandler("raising-task", 1)
        def raising_handler(input_data):
            mock_handler()

        with Executor() as executor:
            executor.submit_task(
                {
                    "task_id": "123e4567-e89b-12d3-a456-426655440000",
                    "task_type": "raising-task",
                    "task_version": 1,
                    "task_data": {},
                },
                mock_callback,
            )

        mock_handler.assert_any_call()
        mock_callback.assert_called_once_with("123e4567-e89b-12d3-a456-426655440000", task_error=ANY)
开发者ID:Korkkii,项目名称:SLAMon,代码行数:27,代码来源:executor_tests.py

示例7: test_mock_asserts

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
    def test_mock_asserts(self):
        """The mock object has four useful helpers (assert_called_with, assert_called_once_with, assert_any_call, assert_has_calls)
        that you can use to assert various things about what the mock has been called with since instantiation"""

        m = Mock()
        m(1)

        m.assert_called_with(1)
        self.assertRaises(AssertionError, m.assert_called_with, 2)

        # assert_called_with asserts what the Mock's most recent call was, not that a call occurred, ever.
        # calling m.assert_called_with(1) now will raise error
        m(2)
        m.assert_called_with(2)
        self.assertRaises(AssertionError, m.assert_called_with, 1)

        # assert_called_once_with is the stronger assertion that the mock has been called exactly once in its history, with the
        # specified argument. (this mock has already been called twice, so both of these fail)
        self.assertRaises(AssertionError, m.assert_called_once_with, 1)
        self.assertRaises(AssertionError, m.assert_called_once_with, 2)

        # assert_any_call means it was called with the given args at any point in history
        m.assert_any_call(1)
        m.assert_any_call(2)
        self.assertRaises(AssertionError, m.assert_called_with, 3)

        # use assert_has_calls to assert the whole call history. it takes a set of mock.call objects
        m.assert_has_calls([mock.call(1), mock.call(2)])

        # this fails because order of calls was m(1) then m(2) and by default any_order=False
        self.assertRaises(AssertionError, m.assert_has_calls, [mock.call(2), mock.call(1)])

        # this works because any_order=true
        m.assert_has_calls([mock.call(2), mock.call(1)], any_order=True)
开发者ID:evandekieft,项目名称:python-mock-examples,代码行数:36,代码来源:tests.py

示例8: test_on_preview_port_added

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
    def test_on_preview_port_added(self):
        """Create a Controller object, call add a source method and
        check that the callback fires
        """
        serv = Server(path=PATH, video_port=3000)
        try:
            serv.run()

            controller = Controller()
            controller.establish_connection()

            test_cb = Mock(side_effect=lambda mode, serve, type:
                           self.quit_mainloop_after(2))
            controller.on_preview_port_added(test_cb)

            sources = TestSources(video_port=3000)
            sources.new_test_video()
            sources.new_test_video()

            GLib.timeout_add_seconds(5, self.quit_mainloop)
            self.run_mainloop()

            print(test_cb.call_args_list)
            test_cb.assert_any_call(3003, 1, 7)
            test_cb.assert_any_call(3004, 1, 8)
            assert test_cb.call_count == 2

            serv.terminate(1)
        finally:
            serv.terminate_and_output_status(cov=True)
开发者ID:mithro,项目名称:gst-switch,代码行数:32,代码来源:test_controller.py

示例9: test_rmtree_ignore_unlink_rmdir_exception

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
    def test_rmtree_ignore_unlink_rmdir_exception(self):
        dir1_list = ["dir2", "file"]
        empty_list = []
        mock_listdir = Mock()
        mock_listdir.side_effect = [dir1_list, empty_list]

        mock_isdir = Mock()
        mock_isdir.side_effect = [True, False]

        mock_unlink = Mock()
        mock_unlink.side_effect = [OSError]

        mock_rmdir = Mock()
        mock_rmdir.side_effect = [0, OSError]

        mock_islink = Mock()
        mock_islink.return_value = False

        with nested(patch("gluster.gfapi.Volume.listdir", mock_listdir),
                    patch("gluster.gfapi.Volume.isdir", mock_isdir),
                    patch("gluster.gfapi.Volume.islink", mock_islink),
                    patch("gluster.gfapi.Volume.unlink", mock_unlink),
                    patch("gluster.gfapi.Volume.rmdir", mock_rmdir)):
            self.vol.rmtree("dir1", True)
            mock_rmdir.assert_any_call("dir1/dir2")
            mock_unlink.assert_called_once_with("dir1/file")
            mock_rmdir.assert_called_with("dir1")
开发者ID:Alphadelta14,项目名称:libgfapi-python,代码行数:29,代码来源:test_gfapi.py

示例10: test_can_set_tuple

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
 def test_can_set_tuple(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig("Name", config, {}, save_mock)
     section.set("list", (1, 2))
     self.assertEqual("1,2", config["list"])
     # Automatically saved value
     save_mock.assert_any_call()
开发者ID:abseabse,项目名称:gtg,代码行数:10,代码来源:test_config.py

示例11: test_can_set_list

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
 def test_can_set_list(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig("Name", config, {}, save_mock)
     section.set("list", [1, True, "Hello"])
     self.assertEqual("1,True,Hello", config["list"])
     # Automatically saved value
     save_mock.assert_any_call()
开发者ID:abseabse,项目名称:gtg,代码行数:10,代码来源:test_config.py

示例12: test_can_set_value

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
 def test_can_set_value(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig("Name", config, {}, save_mock)
     section.set("option", 42)
     self.assertEqual("42", config["option"])
     # Automatically saved value
     save_mock.assert_any_call()
开发者ID:abseabse,项目名称:gtg,代码行数:10,代码来源:test_config.py

示例13: test_basestring_hook_called

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
 def test_basestring_hook_called(self):
     basestring_hook = Mock()
     with patch.object(themyutils.json.JSONDecoder, "basestring_hook", basestring_hook):
         themyutils.json.loads('{"data": {"datetime": "2014-02-02T17:32:01", "datetimes": [{"asdict": '+\
                                '"2014-02-02T17:32:02"}, "2014-02-02T17:32:03"]}}')
         basestring_hook.assert_any_call("2014-02-02T17:32:01")
         basestring_hook.assert_any_call("2014-02-02T17:32:02")
         basestring_hook.assert_any_call("2014-02-02T17:32:03")
开发者ID:themylogin,项目名称:themyutils,代码行数:10,代码来源:test_json.py

示例14: test_dispatch_map_should_invoke_filter_for_extensions

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
 def test_dispatch_map_should_invoke_filter_for_extensions(self):
     em = DispatchExtensionManager.make_test_instance([test_extension,
                                                       test_extension2])
     filter_func = Mock(return_value=False)
     args = ('A',)
     kw = {'big': 'Cheese'}
     em.map(filter_func, None, *args, **kw)
     filter_func.assert_any_call(test_extension, *args, **kw)
     filter_func.assert_any_call(test_extension2, *args, **kw)
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:11,代码来源:test_test_manager.py

示例15: test_delete_book

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_any_call [as 别名]
    def test_delete_book(self):
        """YYUUPA! the last one!"""
        with patch('model.DB.find_author') as perm_mock:

         perm_mock = Mock(return_value=None)
         perm_mock('firstBook')
         perm_mock('secondBook')
         perm_mock('thirdBook')
         perm_mock.assert_any_call('secondBook')
开发者ID:Ksenatos,项目名称:Architectures,代码行数:11,代码来源:test.py


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