本文整理汇总了Python中mock.Mock.key方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.key方法的具体用法?Python Mock.key怎么用?Python Mock.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_clean_up_endpoint_status
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_clean_up_endpoint_status(self):
self.m_config.REPORT_ENDPOINT_STATUS = True
ep_id = EndpointId("hostname",
"openstack",
"workloadid",
"endpointid")
empty_dir = Mock()
empty_dir.key = ("/calico/felix/v1/host/hostname/workload/"
"openstack/foobar")
empty_dir.dir = True
missing_ep = Mock()
missing_ep.key = ("/calico/felix/v1/host/hostname/workload/"
"openstack/aworkload/endpoint/anendpoint")
self.client.read.return_value.leaves = [
empty_dir,
missing_ep,
]
self.watcher.clean_up_endpoint_statuses(set([ep_id]))
# Missing endpoint should have been marked for cleanup.
self.m_status_rep.mark_endpoint_dirty.assert_called_once_with(
EndpointId("hostname",
"openstack",
"aworkload",
"anendpoint"),
async=True
)
示例2: test_clean_up_endpoint_status
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_clean_up_endpoint_status(self):
self.m_config.REPORT_ENDPOINT_STATUS = True
ep_id = WloadEndpointId("foo",
"openstack",
"workloadid",
"endpointid")
empty_dir = Mock()
empty_dir.key = ("/calico/felix/v1/host/foo/workload/"
"openstack/foobar")
empty_dir.dir = True
missing_ep = Mock()
missing_ep.key = ("/calico/felix/v1/host/foo/workload/"
"openstack/aworkload/endpoint/anendpoint")
self.m_client.read.return_value.leaves = [
empty_dir,
missing_ep,
]
with patch.object(self.rep, "_mark_endpoint_dirty") as m_mark:
self.rep.clean_up_endpoint_statuses(async=True)
self.step_actor(self.rep)
# Missing endpoint should have been marked for cleanup.
m_mark.assert_called_once_with(
WloadEndpointId("foo",
"openstack",
"aworkload",
"anendpoint")
)
示例3: test_cron_status_multiple_jobs
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_cron_status_multiple_jobs(self):
(mock_api, mock_scheduler_proxy) = self.create_mock_api()
with contextlib.nested(
patch('time.sleep'),
patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
patch('apache.aurora.client.cli.context.AuroraCommandContext.print_out')) as (
_, _, _, mock_print):
response = self.create_simple_success_response()
response.result = Mock()
response.result.getJobsResult = Mock()
mockjob1 = Mock()
mockjob1.cronSchedule = "* * * * *"
mockjob1.key = Mock()
mockjob1.key.environment = "test"
mockjob1.key.name = "hello2"
mockjob1.key.role = "bozo"
mockjob2 = Mock()
mockjob2.cronSchedule = "* * * * *"
mockjob2.key = Mock()
mockjob2.key.environment = "test"
mockjob2.key.name = "hello"
mockjob2.key.role = "bozo"
response.result.getJobsResult.configs = [mockjob1, mockjob2]
mock_scheduler_proxy.getJobs.return_value = response
cmd = AuroraCommandLine()
result = cmd.execute(['cron', 'show', 'west/bozo/test/hello'])
assert result == EXIT_OK
mock_scheduler_proxy.getJobs.assert_called_once_with("bozo")
mock_print.assert_called_with("west/bozo/test/hello\t * * * * *")
示例4: test_fan_out
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_fan_out(self, mock_issue_init, mock_context, mock_get_by_id):
"""Ensure that an Issue is created for the exception and tasks are
inserted for each stack frame.
"""
mock_repo = Mock()
mock_repo.key = Mock()
mock_get_by_id.return_value = mock_repo
context = Mock()
context.insert_success = 2
mock_context.new.return_value.__enter__.return_value = context
mock_issue = Mock()
issue_key = Mock()
issue_key.id.return_value = '123'
mock_issue.key = issue_key
mock_issue_init.return_value = mock_issue
project_id = 'abc'
timestamp = time.time()
exception = 'ValueError'
message = 'oh snap!'
frame1 = ('foo.py', 24, 'foobar', 'return bar()')
frame2 = ('bar.py', 120, 'baz', 'raise ValueError')
frames = [frame1, frame2]
stacktrace = 'stacktrace'
data = {
'project_id': project_id,
'timestamp': timestamp,
'exception': exception,
'message': message,
'frames': frames,
'stacktrace': stacktrace
}
report.process_exception(data)
mock_get_by_id.assert_called_once_with(project_id)
mock_issue_init.assert_called_once_with(
repo=mock_repo.key, timestamp=datetime.fromtimestamp(timestamp),
exception=exception, message=message, frames=frames,
stacktrace=stacktrace, contacts=[])
mock_issue.put.assert_called_once_with()
expected = [
call(target=report.notify,
args=(project_id, issue_key.id.return_value, timestamp,
frame1[0], frame1[1], frame1[2], frame1[3],
stacktrace)),
call(target=report.notify,
args=(project_id, issue_key.id.return_value, timestamp,
frame2[0], frame2[1], frame2[2], frame2[3], stacktrace))
]
self.assertEqual(expected, context.add.call_args_list)
示例5: test_should_return_number_of_cores_when_in_resources
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_should_return_number_of_cores_when_in_resources(self):
resource_1 = Mock()
resource_1.key = "weLoveCamelCase"
resource_2 = Mock()
resource_2.key = "numCpuCores"
resource_2.value = 42
resource_3 = Mock()
resource_3.key = "someOtherKey"
resources = [resource_1, resource_2, resource_3]
self.raw_esx.licensableResource.resource = resources
self.assertEquals(self.wrapped_esx.get_number_of_cores(), 42)
示例6: is_attribute_unchanged_data
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def is_attribute_unchanged_data(value):
mock = Mock(Resource)
object.__setattr__(mock, 'PROPERTIES', {'key': object})
object.__setattr__(mock, '_data', {'key': value})
object.__setattr__(mock, '_dirty', dict())
mock.key = value
assert 'key' not in mock._dirty
示例7: test_exec_config_with_set_workspaces
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_exec_config_with_set_workspaces(self):
"""Test exec config with set workspaces subcommand."""
args = Mock()
args.action = "set"
args.key = "workspaces"
args.value = False
self.assertFalse(self.subcommand.execute(args))
示例8: assert_handled
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def assert_handled(self, key, exp_handler=SAME_AS_KEY, **exp_captures):
if exp_handler is SAME_AS_KEY:
exp_handler = key
if isinstance(exp_handler, types.StringTypes):
exp_handler = exp_handler.strip("/")
m_response = Mock(spec=etcd.EtcdResult)
m_response.key = key
m_response.action = self.action
self.dispatcher.handle_event(m_response)
exp_handlers = self.handlers[self.expected_handlers]
for handler_key, handler in exp_handlers.iteritems():
assert isinstance(handler, Mock)
if handler_key == exp_handler:
continue
self.assertFalse(handler.called,
"Unexpected set handler %s was called for "
"key %s" % (handler_key, key))
unexp_handlers = self.handlers[self.unexpected_handlers]
for handler_key, handler in unexp_handlers.iteritems():
assert isinstance(handler, Mock)
self.assertFalse(handler.called,
"Unexpected del handler %s was called for "
"key %s" % (handler_key, key))
if exp_handler is not None:
exp_handlers[exp_handler].assert_called_once_with(
m_response, **exp_captures)
示例9: test_request_token_fake
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_request_token_fake(self):
"""Try with a phony consumer key"""
c = Mock()
c.key = "yer"
c.secret = "mom"
r = client.get("oauth.request_token", c)
eq_(r.content, "Invalid consumer.")
示例10: mock_read_4_endpoints
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def mock_read_4_endpoints(path, recursive):
assert path == ALL_ENDPOINTS_PATH
assert recursive
leaves = []
specs = [
(CALICO_V_PATH + "/host/TEST_HOST/bird_ip", "192.168.1.1"),
(CALICO_V_PATH + "/host/TEST_HOST/bird6_ip", "fd80::4"),
(CALICO_V_PATH + "/host/TEST_HOST/config/marker", "created"),
(CALICO_V_PATH + "/host/TEST_HOST/workload/docker/1234/endpoint/567890abcdef",
EP_56.to_json()),
(CALICO_V_PATH + "/host/TEST_HOST/workload/docker/5678/endpoint/90abcdef1234",
EP_90.to_json()),
(CALICO_V_PATH + "/host/TEST_HOST2/bird_ip", "192.168.1.2"),
(CALICO_V_PATH + "/host/TEST_HOST2/bird6_ip", "fd80::3"),
(CALICO_V_PATH + "/host/TEST_HOST2/config/marker", "created"),
(CALICO_V_PATH + "/host/TEST_HOST2/workload/docker/1234/endpoint/7890abcdef12",
EP_78.to_json()),
(CALICO_V_PATH + "/host/TEST_HOST2/workload/docker/5678/endpoint/1234567890ab",
EP_12.to_json())]
for spec in specs:
leaf = Mock(spec=EtcdResult)
leaf.key = spec[0]
leaf.value = spec[1]
leaves.append(leaf)
result = Mock(spec=EtcdResult)
result.leaves = iter(leaves)
return result
示例11: test_filter_nonmatching_file_rules
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_filter_nonmatching_file_rules(self):
file_evaluator = Mock()
file_evaluator.key = "file"
file_evaluator.matches = Mock(return_value=False)
line_evaluator = Mock()
line_evaluator.key = "line"
line_evaluator.matches = Mock(return_value=False)
rule = Mock()
rule.name = "test"
rule.evaluators = [file_evaluator, line_evaluator]
code_checker = CodeChecker([], [rule])
alert = code_checker.check(self.code, {"filename": "macbeth.txt"})
self.assertEquals(1, file_evaluator.matches.call_count)
self.assertEquals(0, line_evaluator.matches.call_count)
示例12: test_repo_groups
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_repo_groups(self):
line_evaluator = Mock()
line_evaluator.key = "line"
line_evaluator.matches = Mock(return_value=True)
rule = Mock()
rule.name = "os_code_exec::python"
rule.evaluators = [line_evaluator]
junk_repo = Mock()
junk_repo.name = 'junk'
local_repo = Mock()
local_repo.name = 'tooling'
repo_groups = {
'skipped_repos': ['junk'],
'local_repos': ['tooling']
}
rules_to_groups = {
'skipped_repos': [{'except': '.*'}],
'local_repos': [
{'match': '.*'},
{'except': 'os_code_exec::.*'}
]
}
code_checker = CodeChecker(context_processors=[], rules=[rule],
repo_groups=repo_groups, rules_to_groups=rules_to_groups)
check_context = {"filename": "macbeth.txt"}
self.assertEquals(code_checker.check(lines=self.code, context=check_context, repo=junk_repo), [])
self.assertEquals(code_checker.check(lines=self.code, context=check_context, repo=local_repo), [])
示例13: fetch_access_token
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def fetch_access_token(self, *args, **kwargs):
if self.error:
raise self.error('')
response = Mock(['key', 'secret'])
response.key = self.key
response.secret = self.secret
return response
示例14: test_pinned_requirement
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_pinned_requirement(self):
req = Mock()
req.key = "django"
req.is_pinned = True
req.latest_version_within_specs = "1.10"
req.version = "1.0"
self.assertEqual(Update.get_commit_message(req), "Update django from 1.0 to 1.10")
示例15: test_requirement_pinned
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import key [as 别名]
def test_requirement_pinned(self):
req = Mock()
req.key = "django"
req.is_pinned = True
req.latest_version_within_specs = "1.10"
req.version = "1.0"
self.assertEqual(SequentialUpdate.get_branch(req), "pyup-update-django-1.0-to-1.10")