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


Python mock.assert_called_with函数代码示例

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


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

示例1: test_side_effect

    def test_side_effect(self):
        mock = Mock()

        def effect(*args, **kwargs):
            raise SystemError('kablooie')

        mock.side_effect = effect
        self.assertRaises(SystemError, mock, 1, 2, fish=3)
        mock.assert_called_with(1, 2, fish=3)

        results = [1, 2, 3]
        def effect():
            return results.pop()
        mock.side_effect = effect

        self.assertEqual([mock(), mock(), mock()], [3, 2, 1],
                          "side effect not used correctly")

        mock = Mock(side_effect=sentinel.SideEffect)
        self.assertEqual(mock.side_effect, sentinel.SideEffect,
                          "side effect in constructor not used")

        def side_effect():
            return DEFAULT
        mock = Mock(side_effect=side_effect, return_value=sentinel.RETURN)
        self.assertEqual(mock(), sentinel.RETURN)
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:26,代码来源:testmock.py

示例2: test_get_release

    def test_get_release(self, mock):
        # The get_release method fecthes a release tarball and
        # extracts it. We have setup a mock so that it won't actually
        # download the release. Let's call the code.
        class FakeFile(object):
            def read(self):
                return 'Django tarball'
            def close(self):
                self.closed = True

        tmp = tempfile.mkdtemp()
        filename = os.path.join(tmp, 'django-0.96.2.tar.gz')
        mock.return_value = FakeFile()
        try:
            self.assertEqual(
                self.recipe.get_release('0.96.2', tmp),
                filename)
            # It tried to download the release through our mock
            mock.assert_called_with(
                'http://www.djangoproject.com/download/0.96.2/tarball/')
            # The file should have been filled with the contents from the
            # handle it got.
            self.assertEqual(open(filename).read(), 'Django tarball')
        finally:
            shutil.rmtree(tmp)
开发者ID:marinho,项目名称:raminel-recipe,代码行数:25,代码来源:tests.py

示例3: test_get_one_or_else_multiple_results

    def test_get_one_or_else_multiple_results(self, mock):
        journo_1, _ = db_helper.init_journalist()
        journo_2, _ = db_helper.init_journalist()

        with mock.patch('logger') as mock_logger:
            get_one_or_else(Journalist.query, mock_logger, mock)
        mock_logger.error.assert_called()  # Not specifying very long log line
        mock.assert_called_with(500)
开发者ID:freedomofpress,项目名称:securedrop,代码行数:8,代码来源:test_db.py

示例4: test_get_one_or_else_no_result_found

    def test_get_one_or_else_no_result_found(self, mock):
        query = Journalist.query.filter(Journalist.username == "alice")

        with mock.patch('logger') as mock_logger:
            get_one_or_else(query, mock_logger, mock)
        log_line = ('Found none when one was expected: '
                    'No row was found for one()')
        mock_logger.error.assert_called_with(log_line)
        mock.assert_called_with(404)
开发者ID:freedomofpress,项目名称:securedrop,代码行数:9,代码来源:test_db.py

示例5: test_setting_call

    def test_setting_call(self):
        mock = Mock()
        def __call__(self, a):
            return self._mock_call(a)

        type(mock).__call__ = __call__
        mock('one')
        mock.assert_called_with('one')

        self.assertRaises(TypeError, mock, 'one', 'two')
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:10,代码来源:testmock.py

示例6: test_java_exception_side_effect

    def test_java_exception_side_effect(self):
        import java
        mock = Mock(side_effect=java.lang.RuntimeException("Boom!"))

        # can't use assertRaises with java exceptions
        try:
            mock(1, 2, fish=3)
        except java.lang.RuntimeException:
            pass
        else:
            self.fail('java exception not raised')
        mock.assert_called_with(1,2, fish=3)
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:12,代码来源:testmock.py

示例7: run

 def run(args):
     new_app = {
         'instances': 10,
         'labels': {
             'HAPROXY_DEPLOYMENT_TARGET_INSTANCES': 30
         }
     }
     old_app = {'instances': 8}
     args.initial_instances = 5
     zdd.scale_new_app_instances(args, new_app, old_app)
     mock.assert_called_with(
         args, new_app, 30)
开发者ID:ajays20078,项目名称:marathon-lb,代码行数:12,代码来源:test_zdd.py

示例8: test_canot_parse_items

    def test_canot_parse_items(self, mock):
        from pypi_updates.bot import RSS_URL
        target_obj = self._make_one()
        update_status = target_obj.funcs[0]['options']['callback']

        with logbook.TestHandler() as log_handler:
            update_status(target_obj)

        assert log_handler.formatted_records == [
            '[WARNING] [kuroko user]: Cannot parse RSS: {}'.format(RSS_URL)
        ]
        mock.assert_called_with(RSS_URL)
开发者ID:tell-k,项目名称:pypi-updates,代码行数:12,代码来源:test_bot.py

示例9: test_assert_called_with

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

        # Will raise an exception if it fails
        mock.assert_called_with()
        self.assertRaises(AssertionError, mock.assert_called_with, 1)

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

        mock(1, 2, 3, a='fish', b='nothing')
        mock.assert_called_with(1, 2, 3, a='fish', b='nothing')
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:13,代码来源:testmock.py

示例10: 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

示例11: test_scale_new_app_instances_to_target

 def test_scale_new_app_instances_to_target(self, mock):
     """When scaling new instances up, if we have met or surpassed the
        amount of instances deployed for old_app, go right to our
        deployment target amount of instances for new_app
     """
     new_app = {
         'instances': 10,
         'labels': {
             'HAPROXY_DEPLOYMENT_TARGET_INSTANCES': 30
         }
     }
     old_app = {'instances': 8}
     args = Arguments()
     args.initial_instances = 5
     zdd.scale_new_app_instances(args, new_app, old_app)
     mock.assert_called_with(
         args, new_app, 30)
开发者ID:alberts,项目名称:marathon-lb,代码行数:17,代码来源:test_zdd.py

示例12: test_scale_new_app_instances_up_50_percent

 def test_scale_new_app_instances_up_50_percent(self, mock):
     """When scaling new_app instances, increase instances by 50% of
        existing instances if we have not yet met or surpassed the amount
        of instances deployed by old_app
     """
     new_app = {
         'instances': 10,
         'labels': {
             'HAPROXY_DEPLOYMENT_TARGET_INSTANCES': 30
         }
     }
     old_app = {'instances': 30}
     args = Arguments()
     args.initial_instances = 5
     zdd.scale_new_app_instances(args, new_app, old_app)
     mock.assert_called_with(
         args, new_app, 15)
开发者ID:alberts,项目名称:marathon-lb,代码行数:17,代码来源:test_zdd.py

示例13: test_pre_kill_hook

    def test_pre_kill_hook(self, mock):
        # TODO(BM): This test is naive. An end-to-end test would be nice.
        args = Arguments()
        args.pre_kill_hook = 'myhook'
        old_app = {
            'id': 'oldApp'
        }
        new_app = {
            'id': 'newApp'
        }
        tasks_to_kill = ['task1', 'task2']

        zdd.execute_pre_kill_hook(args,
                                  old_app,
                                  tasks_to_kill,
                                  new_app)

        mock.assert_called_with([args.pre_kill_hook,
                                 '{"id": "oldApp"}',
                                 '["task1", "task2"]',
                                 '{"id": "newApp"}'])
开发者ID:alberts,项目名称:marathon-lb,代码行数:21,代码来源:test_zdd.py

示例14: test_assert_called_with_function_spec

    def test_assert_called_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_with(1, 2, 3)
        mock.assert_called_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_with(e=8)
        if hasattr(cm.exception, '__cause__'):
            self.assertIsInstance(cm.exception.__cause__, TypeError)
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:16,代码来源:testmock.py

示例15: test_class_fullname

    def test_class_fullname(self, mock):

        target = self._makeOne(self._getDummyModel(), 'connection')
        self.assertEqual('dummy', target.class_fullname)
        mock.assert_called_with('TestModel')
开发者ID:tell-k,项目名称:django-modelsdoc,代码行数:5,代码来源:test_wrappers.py


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