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


Python Mock.assert_called_with方法代码示例

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


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

示例1: test_dispatch_with_kwargs

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_dispatch_with_kwargs(self):
        rules = PatternRules()
        f = Mock()
        rules.add_rule(r'^http://my\.test\.com/(?P<title>[a-zA-Z]+)/([0-9]{4})/$', f)
        rules.dispatch('http://my.test.com/foo/0042/')

        f.assert_called_with('0042', title='foo')
开发者ID:vangroan,项目名称:art-dl,代码行数:9,代码来源:test_rulematch.py

示例2: test_run_checks_EntityCommonStockSharesOutstanding

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_run_checks_EntityCommonStockSharesOutstanding(self):
        msg = messages.get_message('DQC.US.0005', "17")
        mock_context = Mock(endDatetime=1)
        fact = Mock(
            localName='EntityCommonStockSharesOutstanding',
            context=mock_context
        )
        lookup = 'foo'
        eop_results = {lookup: [1, 1]}
        mock_error = Mock()
        mock_modelxbrl = Mock(error=mock_error)
        mock_val = Mock(modelXbrl=mock_modelxbrl)
        dqc_us_0005.run_checks(mock_val, fact, eop_results, lookup)
        self.assertFalse(mock_error.called)

        mock_context = Mock(endDatetime=0)
        fact = Mock(
            localName='EntityCommonStockSharesOutstanding',
            context=mock_context
        )
        dqc_us_0005.run_checks(mock_val, fact, eop_results, lookup)
        mock_error.assert_called_with(
            'DQC.US.0005.17',
            msg,
            modelObject=[fact] + list(eop_results[lookup]),
            ruleVersion=dqc_us_0005._RULE_VERSION
        )
开发者ID:behdadshayegan-wf,项目名称:dqc_us_rules,代码行数:29,代码来源:test_dqc_us_0005.py

示例3: test_debug

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_debug(self):
        """
        If USE_WEBPACK_DEV_SERVER=True, return a hot reload URL
        """
        request = RequestFactory().get('/')
        context = {"request": request}

        # convert to generator
        common_bundle = (chunk for chunk in FAKE_COMMON_BUNDLE)
        get_bundle = Mock(return_value=common_bundle)
        loader = Mock(get_bundle=get_bundle)
        bundle_name = 'bundle_name'
        with patch('ui.templatetags.render_bundle.get_loader', return_value=loader) as get_loader:
            assert render_bundle(context, bundle_name) == (
                '<script type="text/javascript" src="{base}/{js}" ></script>\n'
                '<link type="text/css" href="{base}/{css}" rel="stylesheet" />'.format(
                    base=webpack_dev_server_url(request),
                    js=FAKE_COMMON_BUNDLE[0]['name'],
                    css=FAKE_COMMON_BUNDLE[1]['name'],
                )
            )

        assert public_path(request) == webpack_dev_server_url(request) + "/"

        get_bundle.assert_called_with(bundle_name)
        get_loader.assert_called_with('DEFAULT')
开发者ID:mitodl,项目名称:micromasters,代码行数:28,代码来源:render_bundle_test.py

示例4: test_TS_search_tweets_iterable_callback

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_TS_search_tweets_iterable_callback(self):
        """ Tests TwitterSearch.search_tweets_iterable(callback) by using TwitterSearchOrder class """

        import sys
        if sys.version_info[0] < 3:
            self.assertTrue(True) # Dummy test for py2 doesn't have Mock class
            return

        httpretty.register_uri(httpretty.GET, self.search_url,
                        responses=[
                            httpretty.Response(streaming=True, status=200, content_type='text/json', body=self.apiAnsweringMachine('tests/mock-data/search/0.log')),
                            httpretty.Response(streaming=True, status=200, content_type='text/json', body=self.apiAnsweringMachine('tests/mock-data/search/1.log')),
                            httpretty.Response(streaming=True, status=200, content_type='text/json', body=self.apiAnsweringMachine('tests/mock-data/search/2.log')),
                            httpretty.Response(streaming=True, status=200, content_type='text/json', body=self.apiAnsweringMachine('tests/mock-data/search/3.log'))
                            ]
                        )

        pages = 4
        tso = self.createTSO()
        tso.set_count(4)
        ts = self.createTS()

        from unittest.mock import Mock

        mock = Mock()
        for tweet in ts.search_tweets_iterable(tso, callback=mock):
            mock.assert_called_with(ts)

        times = len(mock.call_args_list)
        self.assertEqual(pages, times, "Callback function was NOT called 4 times but %i times" % times)
开发者ID:abhinonymous,项目名称:TwitterSearch,代码行数:32,代码来源:test_ts.py

示例5: test_when_with_value

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_when_with_value(self):
        mock = Mock()

        promise = q.when('foo')
        promise.then(mock, self.assert_never_called)

        mock.assert_called_with('foo')
开发者ID:xi,项目名称:laneya,代码行数:9,代码来源:test_promise.py

示例6: test_alert_error

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
async def test_alert_error():
    async with unit(1) as unit1:
        async with unit(2) as unit2:

            def err(x):
                raise RuntimeError("dad")

            error_me1 = Mock(side_effect=err)
            await unit1.register(error_me1, "my.error1", call_conv=CC_DATA, multiple=True)
            called = False
            async for d in unit2.poll("my.error1", min_replies=1, max_replies=2, max_delay=TIMEOUT,
                                      result_conv=CC_MSG, debug=True):
                assert not called
                assert d.error.cls == "RuntimeError"
                assert d.error.message == "dad"
                called = True
            error_me1.assert_called_with(None)

            with pytest.raises(RuntimeError):
                async for d in unit2.poll("my.error1", result_conv=CC_DATA, min_replies=1,
                                          max_replies=2, max_delay=TIMEOUT):
                    assert False

            with pytest.raises(RuntimeError):
                await unit2.poll_first("my.error1")
开发者ID:M-o-a-T,项目名称:qbroker,代码行数:27,代码来源:test_unit.py

示例7: test_connectionLost

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
 def test_connectionLost(self):
     m = Mock()
     reason = Mock()
     reason.getErrorMessage.return_value = "Some message"
     self.con._finish_callback = Deferred().addCallback(m)
     self.con.connectionLost(reason)
     m.assert_called_with("Some message")
开发者ID:fiorix,项目名称:cyclone,代码行数:9,代码来源:test_httpserver.py

示例8: test_wraps_calls

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
 def test_wraps_calls(self):
     real = Mock()
     mock = Mock(wraps=real)
     self.assertEqual(mock(), real())
     real.reset_mock()
     mock(1, 2, fish=3)
     real.assert_called_with(1, 2, fish=3)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:9,代码来源:testmock.py

示例9: test

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
 def test(self):
     dependency = Mock()
     method = Mock()
     result = component.depend(dependency)(method)
     self.assertEqual(result, dependency.return_value)
     # Check dependency call
     dependency.assert_called_with(method)
开发者ID:,项目名称:,代码行数:9,代码来源:

示例10: test_process_callback_mode

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_process_callback_mode(self):
        """Test if after_update_callback is called after update of Climate object was changed."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate_mode = ClimateMode(
            xknx,
            'TestClimate',
            group_address_operation_mode='1/2/5')

        after_update_callback = Mock()

        async def async_after_update_callback(device):
            """Async callback."""
            after_update_callback(device)
        climate_mode.register_device_updated_cb(async_after_update_callback)

        self.loop.run_until_complete(asyncio.Task(
            climate_mode.set_operation_mode(HVACOperationMode.COMFORT)))
        after_update_callback.assert_called_with(climate_mode)
        after_update_callback.reset_mock()

        self.loop.run_until_complete(asyncio.Task(
            climate_mode.set_operation_mode(HVACOperationMode.COMFORT)))
        after_update_callback.assert_not_called()
        after_update_callback.reset_mock()

        self.loop.run_until_complete(asyncio.Task(
            climate_mode.set_operation_mode(HVACOperationMode.FROST_PROTECTION)))
        after_update_callback.assert_called_with(climate_mode)
        after_update_callback.reset_mock()
开发者ID:phbaer,项目名称:xknx,代码行数:32,代码来源:climate_test.py

示例11: test_fill_many_pdfs

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_fill_many_pdfs(self):
        pdfparser = PDFParser()
        fake_answer = Mock()
        fake_multiple_answers = [fake_answer]

        fake_path = "some/fake/path.pdf"

        coerce_to_file_path = Mock(return_value=fake_path)
        pdfparser._coerce_to_file_path = coerce_to_file_path

        fake_get_fields = Mock(return_value='field data')
        pdfparser.get_field_data = fake_get_fields

        fake_get_options = Mock(return_value='options')
        pdfparser._get_name_option_lookup = fake_get_options

        fake_fill = Mock()
        pdfparser._fill = fake_fill

        fake_write_tmp_file = Mock(return_value='output path')
        pdfparser._write_tmp_file = fake_write_tmp_file

        fake_join_pdfs = Mock(return_value='filled_pdf')
        pdfparser.join_pdfs = fake_join_pdfs

        #run the method
        result = pdfparser.fill_many_pdfs(fake_path, fake_multiple_answers)

        self.assertEqual(result, 'filled_pdf')
        coerce_to_file_path.assert_called_once_with(fake_path)
        fake_get_fields.assert_called_once_with(fake_path)
        fake_get_options.assert_called_once_with('field data')
        fake_fill.assert_called_once_with(fake_path, 'output path',
            'options', fake_answer)
        fake_join_pdfs.assert_called_with(['output path'])
开发者ID:brennv,项目名称:pdfhook,代码行数:37,代码来源:test_pdfparser.py

示例12: test_reject_with_value

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_reject_with_value(self):
        mock = Mock()

        promise = q.reject('foo')
        promise.then(self.assert_never_called, mock)

        mock.assert_called_with('foo')
开发者ID:xi,项目名称:laneya,代码行数:9,代码来源:test_promise.py

示例13: test_build_create

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
def test_build_create():
    population_class = Mock()
    create_function = common.build_create(population_class)
    assert isfunction(create_function)

    p = create_function("cell class", "cell params", n=999)
    population_class.assert_called_with(999, "cell class", cellparams="cell params")
开发者ID:NeuralEnsemble,项目名称:PyNN,代码行数:9,代码来源:test_lowlevelapi.py

示例14: test_data_route_match

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
    def test_data_route_match(self):
        endpoint = Mock(return_value="cats")

        f = self.app
        f.debug = True

        route = {
            "product": {
                (("year", None), ("location", "department")): {
                    "name": "department_product_year",
                    "action": endpoint
                },
            },
            "year": {
            }
        }

        routing.add_routes(f, route)

        factories.Location(level="department", id=2)
        db.session.commit()

        with f.test_client() as c:
            response = c.get("/product?location=2&year=2007")
            assert response.status_code == 200
            assert response.data == b"cats"
            endpoint.assert_called_with(location=2, year=2007)
开发者ID:Bancoldexprueba,项目名称:atlas-subnational-api,代码行数:29,代码来源:test_data.py

示例15: test_validate_user_headers_call_view_if_authenticated

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_called_with [as 别名]
def test_validate_user_headers_call_view_if_authenticated(context, request_):
    from . import validate_user_headers
    view = Mock()
    request_.headers['X-User-Token'] = 2
    request_.authenticated_userid = object()
    validate_user_headers(view)(context, request_)
    view.assert_called_with(context, request_)
开发者ID:Janaba,项目名称:adhocracy3,代码行数:9,代码来源:test_init.py


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