本文整理汇总了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')
示例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
)
示例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')
示例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)
示例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')
示例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")
示例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")
示例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)
示例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)
示例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()
示例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'])
示例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')
示例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")
示例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)
示例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_)