本文整理汇总了Python中mock.PropertyMock.side_effect方法的典型用法代码示例。如果您正苦于以下问题:Python PropertyMock.side_effect方法的具体用法?Python PropertyMock.side_effect怎么用?Python PropertyMock.side_effect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.PropertyMock
的用法示例。
在下文中一共展示了PropertyMock.side_effect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_are_creds_valid_with_invalid_creds
# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import side_effect [as 别名]
def test_are_creds_valid_with_invalid_creds(self):
with patch.object(github.Github, 'get_user') as patched_get_user:
mocked_login = PropertyMock()
mocked_login.side_effect = github.BadCredentialsException(401, 'dummy data')
type(patched_get_user.return_value).login = mocked_login
self.assertFalse(self.backend.are_creds_valid())
示例2: test_get_will_retry
# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import side_effect [as 别名]
def test_get_will_retry():
global sequential_values, retry_policy
retry_policy = MagicMock()
retry_policy.should_retry.return_value = True
retry_policy.seconds_to_sleep.return_value = 0.01
with patch('requests.get') as patched_get:
# When we call assert_equals in this unit test, the side_effect is executed.
# So, the last status_code should be repeated.
sequential_values = [500, 200, 200]
pm = PropertyMock()
pm.side_effect = return_sequential
type(patched_get.return_value).status_code = pm
client = ReliableHttpClient(endpoint, {}, retry_policy)
result = client.get("r", [200])
assert_equals(200, result.status_code)
retry_policy.should_retry.assert_called_once_with(500, False, 0)
retry_policy.seconds_to_sleep.assert_called_once_with(0)
示例3: test_delete_will_retry
# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import side_effect [as 别名]
def test_delete_will_retry():
global sequential_values, retry_policy
retry_policy = MagicMock()
retry_policy.should_retry.return_value = True
retry_policy.seconds_to_sleep.return_value = 0.01
with patch('requests.delete') as patched_delete:
# When we call assert_equals in this unit test, the side_effect is executed.
# So, the last status_code should be repeated.
sequential_values = [500, 200, 200]
pm = PropertyMock()
pm.side_effect = return_sequential
type(patched_delete.return_value).status_code = pm
client = ReliableHttpClient("http://url.com", {}, "username", "password", retry_policy)
result = client.delete("r", [200])
assert_equals(200, result.status_code)
retry_policy.should_retry.assert_called_once_with(500, 0)
retry_policy.seconds_to_sleep.assert_called_once_with(0)
示例4: test_deserialize_not_empty_but_error
# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import side_effect [as 别名]
def test_deserialize_not_empty_but_error():
session = MagicMock()
status_property = PropertyMock()
status_property.side_effect = ValueError()
type(session).status = status_property
reader_writer = MagicMock()
reader_writer.read_lines.return_value = """{
"clients": [
{
"name": "py",
"id": "1",
"sqlcontext": true,
"kind": "pyspark",
"connectionstring": "url=https://mysite.com/livy;username=user;password=pass",
"version": "0.0.0"
},
{
"name": "sc",
"id": "2",
"sqlcontext": false,
"kind": "spark",
"connectionstring": "url=https://mysite.com/livy;username=user;password=pass",
"version": "0.0.0"
}
]
}
"""
serializer = ClientManagerStateSerializer(reader_writer)
serializer._create_livy_session = MagicMock(return_value=session)
serializer._create_livy_client = MagicMock()
deserialized = serializer.deserialize_state()
assert len(deserialized) == 0
serializer._create_livy_session.assert_no_called()
serializer._create_livy_session.assert_no_called()
示例5: test_deserialize_not_emtpy_but_error
# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import side_effect [as 别名]
def test_deserialize_not_emtpy_but_error():
client_factory = MagicMock()
session = MagicMock()
status_property = PropertyMock()
status_property.side_effect = ValueError()
type(session).status = status_property
client_factory.create_session.return_value = session
reader_writer = MagicMock()
reader_writer.read_lines.return_value = """{
"clients": [
{
"name": "py",
"id": "1",
"sqlcontext": true,
"language": "python",
"connectionstring": "url=https://mysite.com/livy;username=user;password=pass",
"version": "0.0.0"
},
{
"name": "sc",
"id": "2",
"sqlcontext": false,
"language": "scala",
"connectionstring": "url=https://mysite.com/livy;username=user;password=pass",
"version": "0.0.0"
}
]
}
"""
serializer = ClientManagerStateSerializer(client_factory, reader_writer)
deserialized = serializer.deserialize_state()
assert len(deserialized) == 0
client_factory.create_session.assert_no_called()
client_factory.build_client.assert_no_called()