本文整理汇总了Python中mock.patch.multiple方法的典型用法代码示例。如果您正苦于以下问题:Python patch.multiple方法的具体用法?Python patch.multiple怎么用?Python patch.multiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.patch
的用法示例。
在下文中一共展示了patch.multiple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_not_implemented_errors
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_not_implemented_errors(self):
# Construction of the base class should not be possible
self.assertRaises(NotImplementedError, StateMachineDevice)
mandatory_methods = {
'_get_state_handlers': Mock(return_value={'test': MagicMock()}),
'_get_initial_state': Mock(return_value='test'),
'_get_transition_handlers': Mock(
return_value={('test', 'test'): Mock(return_value=True)})
}
# If any of the mandatory methods is missing, a NotImplementedError must be raised
for methods in itertools.combinations(mandatory_methods.items(), 2):
with patch.multiple('lewis.devices.StateMachineDevice', **dict(methods)):
self.assertRaises(NotImplementedError, StateMachineDevice)
# If all are implemented, no exception should be raised
with patch.multiple('lewis.devices.StateMachineDevice', **mandatory_methods):
assertRaisesNothing(self, StateMachineDevice)
示例2: test_check_version_old
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_check_version_old(self):
with patch.multiple(
'awslimitchecker.checker',
logger=DEFAULT,
_get_version_info=DEFAULT,
TrustedAdvisor=DEFAULT,
_get_latest_version=DEFAULT,
autospec=True,
) as mocks:
mocks['_get_version_info'].return_value = self.mock_ver_info
mocks['_get_latest_version'].return_value = '3.4.5'
AwsLimitChecker()
assert mocks['_get_latest_version'].mock_calls == [call()]
assert mocks['logger'].mock_calls == [
call.warning(
'You are running awslimitchecker %s, but the latest version'
' is %s; please consider upgrading.', '1.2.3', '3.4.5'
),
call.debug('Connecting to region %s', None)
]
示例3: test_check_version_not_old
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_check_version_not_old(self):
with patch.multiple(
'awslimitchecker.checker',
logger=DEFAULT,
_get_version_info=DEFAULT,
TrustedAdvisor=DEFAULT,
_get_latest_version=DEFAULT,
autospec=True,
) as mocks:
mocks['_get_version_info'].return_value = self.mock_ver_info
mocks['_get_latest_version'].return_value = None
AwsLimitChecker()
assert mocks['_get_latest_version'].mock_calls == [call()]
assert mocks['logger'].mock_calls == [
call.debug('Connecting to region %s', None)
]
示例4: test_find_usage
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_find_usage(self):
"""test find usage method calls other methods"""
mock_conn = Mock()
with patch('%s.connect' % pb) as mock_connect:
with patch.multiple(
pb,
_find_cluster_manual_snapshots=DEFAULT,
_find_cluster_subnet_groups=DEFAULT,
) as mocks:
cls = _RedshiftService(21, 43, {}, None)
cls.conn = mock_conn
assert cls._have_usage is False
cls.find_usage()
assert mock_connect.mock_calls == [call()]
assert cls._have_usage is True
assert mock_conn.mock_calls == []
for x in [
'_find_cluster_manual_snapshots',
'_find_cluster_subnet_groups',
]:
assert mocks[x].mock_calls == [call()]
示例5: test_find_usage
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_find_usage(self):
"""test find usage method calls other methods"""
mock_conn = Mock()
with patch('%s.connect' % pb) as mock_connect:
with patch.multiple(
pb,
_find_usage_applications=DEFAULT,
_find_usage_application_versions=DEFAULT,
_find_usage_environments=DEFAULT,
) as mocks:
cls = _ElasticBeanstalkService(21, 43, {}, None)
cls.conn = mock_conn
assert cls._have_usage is False
cls.find_usage()
assert mock_connect.mock_calls == [call()]
assert cls._have_usage is True
assert mock_conn.mock_calls == []
for x in [
'_find_usage_applications',
'_find_usage_application_versions',
'_find_usage_environments',
]:
assert mocks[x].mock_calls == [call()]
示例6: test_find_usage
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_find_usage(self):
mock_conn = Mock()
with patch('%s.connect' % pb) as mock_connect:
with patch.multiple(
pb,
autospec=True,
_find_usage_apis=DEFAULT,
_find_usage_api_keys=DEFAULT,
_find_usage_certs=DEFAULT,
_find_usage_plans=DEFAULT,
_find_usage_vpc_links=DEFAULT
) as mocks:
cls = _ApigatewayService(21, 43, {}, None)
cls.conn = mock_conn
assert cls._have_usage is False
cls.find_usage()
assert mock_connect.mock_calls == [call()]
assert cls._have_usage is True
assert mock_conn.mock_calls == []
assert mocks['_find_usage_apis'].mock_calls == [call(cls)]
assert mocks['_find_usage_api_keys'].mock_calls == [call(cls)]
assert mocks['_find_usage_certs'].mock_calls == [call(cls)]
assert mocks['_find_usage_plans'].mock_calls == [call(cls)]
assert mocks['_find_usage_vpc_links'].mock_calls == [call(cls)]
示例7: test_update_limits_from_api
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_update_limits_from_api(self):
"""test _update_limits_from_api method calls other methods"""
mock_conn = Mock()
with patch('%s.connect' % pb) as mock_connect:
with patch.multiple(
pb,
_find_limit_hosted_zone=DEFAULT,
) as mocks:
cls = _Route53Service(21, 43, {}, None)
cls.conn = mock_conn
cls._update_limits_from_api()
assert mock_connect.mock_calls == [call()]
assert mock_conn.mock_calls == []
for x in [
'_find_limit_hosted_zone',
]:
assert mocks[x].mock_calls == [call()]
示例8: test_find_usage
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_find_usage(self):
mock_conn = Mock()
with patch('%s.connect' % self.pb) as mock_connect:
with patch.multiple(
self.pb,
_find_usage_instances=DEFAULT,
_find_usage_subnet_groups=DEFAULT,
_find_usage_security_groups=DEFAULT,
_update_limits_from_api=DEFAULT,
) as mocks:
cls = _RDSService(21, 43, {}, None)
cls.conn = mock_conn
assert cls._have_usage is False
cls.find_usage()
assert mock_connect.mock_calls == [call()]
assert cls._have_usage is True
for x in [
'_find_usage_instances',
'_find_usage_subnet_groups',
'_find_usage_security_groups',
'_update_limits_from_api',
]:
assert mocks[x].mock_calls == [call()]
示例9: test_destroy
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_destroy(self):
mocked_fetch = MagicMock()
mocked_sync = MagicMock()
router, mocks = self.get_new_router()
router.workers = [mocked_fetch, mocked_sync]
with patch.multiple(
"gitfs.router",
shutil=mocks["shutil"],
fetch=mocks["fetch"],
shutting_down=mocks["shutting"],
):
router.destroy("path")
assert mocked_fetch.join.call_count == 1
assert mocked_sync.join.call_count == 1
assert mocks["fetch"].set.call_count == 1
assert mocks["shutting"].set.call_count == 1
mocks["shutil"].rmtree.assert_called_once_with(mocks["repo_path"])
示例10: test_call_with_valid_operation
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_call_with_valid_operation(self):
mocked_view = MagicMock()
mocked_cache = MagicMock()
mocked_idle_event = MagicMock()
router, mocks = self.get_new_router()
router.register([("/", MagicMock(return_value=mocked_view))])
with patch.multiple(
"gitfs.router", idle=mocked_idle_event, lru_cache=mocked_cache
):
mocked_cache.get_if_exists.return_value = None
result = router("random_operation", "/")
assert result == mocked_view.random_operation("/")
assert mocked_idle_event.clear.call_count == 1
示例11: test_open
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_open(self):
mocked_full = MagicMock(return_value="full_path")
mocked_repo = MagicMock(_full_path=mocked_full)
mocked_os = MagicMock()
mocked_os.open.return_value = 1
with patch.multiple("gitfs.views.current", os=mocked_os):
current = CurrentView(
repo=mocked_repo, repo_path="repo_path", ignore=CachedIgnore()
)
current._full_path = mocked_full
current.writing = set([])
assert current.open("path/", os.O_WRONLY) == 1
mocked_os.open.assert_called_once_with("full_path", os.O_WRONLY)
示例12: test_release_without_stage
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_release_without_stage(self):
message = "No need to stage this"
mocked_os = MagicMock()
mocked_stage = MagicMock()
mocked_os.close.return_value = 0
with patch.multiple("gitfs.views.current", os=mocked_os):
current = CurrentView(
repo="repo", repo_path="repo_path", ignore=CachedIgnore()
)
current._stage = mocked_stage
current.dirty = {4: {"message": message, "stage": False}}
assert current.release("/path", 4) == 0
mocked_os.close.assert_called_once_with(4)
assert mocked_stage.call_count == 0
示例13: test_args
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_args(self):
mocked_parser = MagicMock()
mocked_args = MagicMock()
mocked_args.return_value = "args"
with patch.multiple("gitfs.mounter", Args=mocked_args):
assert parse_args(mocked_parser) == "args"
asserted_calls = [
call("remote_url", help="repo to be cloned"),
call("mount_point", help="where the repo should be mount"),
call(
"-o",
help="other options: repo_path, "
+ "user, group, branch, max_size, "
+ "max_offset, fetch_timeout, merge_timeout",
),
]
mocked_parser.add_argument.has_calls(asserted_calls)
示例14: test_while_not
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_while_not(self):
an_event = Event()
an_event.set()
mocked_method = MagicMock()
mocked_time = MagicMock()
mocked_time.sleep.side_effect = lambda x: an_event.clear()
mocked_method.__name__ = "name"
with patch.multiple(
"gitfs.utils.decorators.while_not", wraps=MockedWraps, time=mocked_time
):
not_now = while_not(an_event)
not_now(mocked_method)("arg", kwarg="kwarg")
mocked_time.sleep.assert_called_once_with(0.2)
示例15: test_init
# 需要导入模块: from mock import patch [as 别名]
# 或者: from mock.patch import multiple [as 别名]
def test_init(self):
mocked_os = MagicMock()
mocked_os.path.exists.return_value = True
mocked_re = MagicMock()
mocked_re.findall.return_value = [[None, None, "found"]]
with patch("gitfs.cache.gitignore.open", create=True) as mocked_open:
mocked_file = mocked_open.return_value.__enter__.return_value
mocked_file.read.return_value = "file"
with patch.multiple("gitfs.cache.gitignore", os=mocked_os, re=mocked_re):
gitignore = CachedIgnore("some_file", "some_file")
assert gitignore.items == [
".git",
".git/*",
"/.git/*",
"*.keep",
"*.gitmodules",
"/found/*",
"/found",
"found",
]