本文整理汇总了Python中mock.NonCallableMock方法的典型用法代码示例。如果您正苦于以下问题:Python mock.NonCallableMock方法的具体用法?Python mock.NonCallableMock怎么用?Python mock.NonCallableMock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock
的用法示例。
在下文中一共展示了mock.NonCallableMock方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vim
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def vim():
"""A wide-open mock vim object.
We'll just have to be careful since we can't import a real vim object to
use autospec and guarantee that we're calling real APIs.
"""
def vimeval(expr):
# Default Editor.isneovim to False.
# TODO: easy way to override this; neovim mock fixture?
if expr == "has('nvim')":
return False
else:
return mock.DEFAULT
attrs = {'eval.side_effect': vimeval}
return mock.NonCallableMock(name='mockvim', **attrs)
示例2: test_get_real_user_not_callable
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def test_get_real_user_not_callable(self):
"""
Test user_email, user_username, and user_language not available
"""
self.xblock.runtime.get_real_user = NonCallableMock()
real_user_data = self.xblock.extract_real_user_data()
self.assertIsNone(real_user_data['user_email'])
self.assertIsNone(real_user_data['user_username'])
self.assertIsNone(real_user_data['user_language'])
示例3: test_rejects_questionnaire_from_returns_none
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def test_rejects_questionnaire_from_returns_none(self, recruiter):
dummy = mock.NonCallableMock()
assert recruiter.rejects_questionnaire_from(participant=dummy) is None
示例4: test_close
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def test_close():
mock_transport = mock.NonCallableMock()
client = subscriber.Client(transport=mock_transport)
client.close()
mock_transport.channel.close.assert_called()
示例5: test_closes_channel_as_context_manager
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def test_closes_channel_as_context_manager():
mock_transport = mock.NonCallableMock()
client = subscriber.Client(transport=mock_transport)
with client:
pass
mock_transport.channel.close.assert_called()
示例6: test_streaming_pull_gapic_monkeypatch
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def test_streaming_pull_gapic_monkeypatch():
transport = mock.NonCallableMock(spec=["streaming_pull"])
transport.streaming_pull = mock.Mock(spec=[])
client = subscriber.Client(transport=transport)
client.streaming_pull(requests=iter([]))
assert client.api.transport is transport
assert hasattr(transport.streaming_pull, "_prefetch_first_result_")
assert not transport.streaming_pull._prefetch_first_result_
示例7: test_labels_setter_with_removal
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def test_labels_setter_with_removal(self):
# Make sure the bucket labels look correct and follow the expected
# public structure.
bucket = self._make_one(name="name")
self.assertEqual(bucket.labels, {})
bucket.labels = {"color": "red", "flavor": "cherry"}
self.assertEqual(bucket.labels, {"color": "red", "flavor": "cherry"})
bucket.labels = {"color": "red"}
self.assertEqual(bucket.labels, {"color": "red"})
# Make sure that a patch call correctly removes the flavor label.
client = mock.NonCallableMock(spec=("_connection",))
client._connection = mock.NonCallableMock(spec=("api_request",))
bucket.patch(client=client)
client._connection.api_request.assert_called()
_, _, kwargs = client._connection.api_request.mock_calls[0]
self.assertEqual(len(kwargs["data"]["labels"]), 2)
self.assertEqual(kwargs["data"]["labels"]["color"], "red")
self.assertIsNone(kwargs["data"]["labels"]["flavor"])
self.assertEqual(kwargs["timeout"], self._get_default_timeout())
# A second patch call should be a no-op for labels.
client._connection.api_request.reset_mock()
bucket.patch(client=client, timeout=42)
client._connection.api_request.assert_called()
_, _, kwargs = client._connection.api_request.mock_calls[0]
self.assertNotIn("labels", kwargs["data"])
self.assertEqual(kwargs["timeout"], 42)
示例8: mock_sql
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def mock_sql():
mock_sql_query = Mock(spec_set=['_execute_sql', 'query', 'as_sql'])
mock_sql_query._execute_sql = Mock()
mock_sql_query.query = NonCallableMock(spec_set=['model'])
mock_sql_query.query.model = Mock()
query_string = 'SELECT * from table_name'
mock_sql_query.as_sql = Mock(return_value=(query_string, ()))
return mock_sql_query, query_string
示例9: _mock_response
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def _mock_response(self):
response = NonCallableMock()
response._headers = {}
response.status_code = 200
response.queries = []
response.get = response._headers.get
response.content = ''
return response
示例10: mock_cloneable
# 需要导入模块: import mock [as 别名]
# 或者: from mock import NonCallableMock [as 别名]
def mock_cloneable(cloneable_subclass_with_api_call_method):
# pylint:disable=abstract-method
class MockCloneable(cloneable_subclass_with_api_call_method, NonCallableMock):
pass
return MockCloneable(spec_set=cloneable_subclass_with_api_call_method, name='Cloneable')