本文整理汇总了Python中mock.MagicMock.value方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.value方法的具体用法?Python MagicMock.value怎么用?Python MagicMock.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getHostGuestMapping_incomplete_data
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_getHostGuestMapping_incomplete_data(self, mock_client):
expected_hostname = None
expected_hypervisorId = 'Fake_uuid'
expected_guestId = 'guest1UUID'
expected_guest_state = Guest.STATE_UNKNOWN
fake_parent = MagicMock()
fake_parent.value = 'Fake_parent'
fake_vm_id = MagicMock()
fake_vm_id.value = 'guest1'
fake_vm = MagicMock()
fake_vm.ManagedObjectReference = [fake_vm_id]
fake_vms = {'guest1': {'runtime.powerState': 'BOGUS_STATE',
'config.uuid': expected_guestId}}
self.esx.vms = fake_vms
fake_host = {'hardware.systemInfo.uuid': expected_hypervisorId,
'parent': fake_parent,
'vm': fake_vm
}
fake_hosts = {'random-host-id': fake_host}
self.esx.hosts = fake_hosts
expected_result = Hypervisor(hypervisorId=expected_hypervisorId,
name=expected_hostname,
guestIds=[Guest(expected_guestId,
self.esx,
expected_guest_state,
hypervisorType='vmware')
]
)
result = self.esx.getHostGuestMapping()['hypervisors'][0]
self.assertEqual(expected_result.toDict(), result.toDict())
示例2: test_getHostGuestMapping
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_getHostGuestMapping(self, mock_client):
expected_hostname = 'Fake_hostname'
expected_hypervisorId = 'Fake_uuid'
expected_guestId = 'guest1UUID'
expected_guest_state = Guest.STATE_RUNNING
fake_parent = MagicMock()
fake_parent.value = 'Fake_parent'
fake_vm_id = MagicMock()
fake_vm_id.value = 'guest1'
fake_vm = MagicMock()
fake_vm.ManagedObjectReference = [fake_vm_id]
fake_vms = {'guest1': {'runtime.powerState': 'poweredOn',
'config.uuid': expected_guestId}}
self.esx.vms = fake_vms
fake_host = {'hardware.systemInfo.uuid': expected_hypervisorId,
'name': expected_hostname,
'parent': fake_parent,
'vm': fake_vm
}
fake_hosts = {'random-host-id': fake_host}
self.esx.hosts = fake_hosts
expected_result = Hypervisor(hypervisorId=expected_hypervisorId,
name=expected_hostname,
guestIds=[Guest(expected_guestId,
self.esx,
expected_guest_state)
]
)
result = self.esx.getHostGuestMapping()['hypervisors'][0]
self.assertTrue(expected_result.toDict() == result.toDict())
示例3: test_getHostGuestMappingNoHostName
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_getHostGuestMappingNoHostName(self, mock_client):
expected_hypervisorId = 'Fake_uuid'
expected_guestId = 'guest1UUID'
expected_guest_state = Guest.STATE_RUNNING
fake_parent = MagicMock()
fake_parent.value = 'fake_parent_id'
fake_parent._type = 'ClusterComputeResource'
fake_vm_id = MagicMock()
fake_vm_id.value = 'guest1'
fake_vm = MagicMock()
fake_vm.ManagedObjectReference = [fake_vm_id]
fake_vms = {'guest1': {'runtime.powerState': 'poweredOn',
'config.uuid': expected_guestId}}
self.esx.vms = fake_vms
fake_host = {'hardware.systemInfo.uuid': expected_hypervisorId,
'config.network.dnsConfig.domainName': 'domainname',
'config.product.version': '1.2.3',
'hardware.cpuInfo.numCpuPackages': '1',
'parent': fake_parent,
'vm': fake_vm,
}
fake_hosts = {'random-host-id': fake_host}
self.esx.hosts = fake_hosts
fake_cluster = {'name': 'Fake_cluster_name'}
self.esx.clusters = {'fake_parent_id': fake_cluster}
assert (len(self.esx.getHostGuestMapping()['hypervisors']) == 0)
示例4: test_getHostGuestMapping
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_getHostGuestMapping(self, mock_client):
expected_hostname = 'hostname.domainname'
expected_hypervisorId = 'Fake_uuid'
expected_guestId = 'guest1UUID'
expected_guest_state = Guest.STATE_RUNNING
fake_parent = MagicMock()
fake_parent.value = 'fake_parent_id'
fake_parent._type = 'ClusterComputeResource'
fake_vm_id = MagicMock()
fake_vm_id.value = 'guest1'
fake_vm = MagicMock()
fake_vm.ManagedObjectReference = [fake_vm_id]
fake_vms = {'guest1': {'runtime.powerState': 'poweredOn',
'config.uuid': expected_guestId}}
self.esx.vms = fake_vms
fake_host = {'hardware.systemInfo.uuid': expected_hypervisorId,
'config.network.dnsConfig.hostName': 'hostname',
'config.network.dnsConfig.domainName': 'domainname',
'config.product.version': '1.2.3',
'hardware.cpuInfo.numCpuPackages': '1',
'name': expected_hostname,
'parent': fake_parent,
'vm': fake_vm,
}
fake_hosts = {'random-host-id': fake_host}
self.esx.hosts = fake_hosts
fake_cluster = {'name': 'Fake_cluster_name'}
self.esx.clusters = {'fake_parent_id': fake_cluster}
expected_result = Hypervisor(
hypervisorId=expected_hypervisorId,
name=expected_hostname,
guestIds=[
Guest(
expected_guestId,
self.esx.CONFIG_TYPE,
expected_guest_state,
)
],
facts={
Hypervisor.CPU_SOCKET_FACT: '1',
Hypervisor.HYPERVISOR_TYPE_FACT: 'vmware',
Hypervisor.HYPERVISOR_VERSION_FACT: '1.2.3',
Hypervisor.HYPERVISOR_CLUSTER: 'Fake_cluster_name',
Hypervisor.SYSTEM_UUID_FACT: expected_hypervisorId
}
)
result = self.esx.getHostGuestMapping()['hypervisors'][0]
self.assertEqual(expected_result.toDict(), result.toDict())
示例5: test_walk_BooleanNode
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_walk_BooleanNode(self):
nw = GraphDSLNodeWalker(self.graphmgr)
node = MagicMock()
node.value = 'TRUE'
nw.walk_BooleanNode(node, [])
self.assertTrue(node.value)
node = MagicMock()
node.value = 'FALSE'
nw.walk_BooleanNode(node, [])
self.assertFalse(node.value)
示例6: _test_wlvllogg_import_from_diveroffice_files
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def _test_wlvllogg_import_from_diveroffice_files(self, filenames, mock_filenames, mock_skippopup, mock_encoding, mock_iface, mock_askuser, mock_notfoundquestion, mock_messagebarandlog):
mocks_notfoundquestion = []
for answer, value in [['ok', 'rb1'],
['ok', 'rb2'],
['skip', 'rb3']]:
a_mock = MagicMock()
a_mock.answer = answer
a_mock.value = value
a_mock.reuse_column = 'location'
mocks_notfoundquestion.append(a_mock)
mock_notfoundquestion.side_effect = mocks_notfoundquestion
mock_filenames.return_value = filenames
mock_encoding.return_value = ['utf-8']
ms = MagicMock()
ms.settingsdict = OrderedDict()
importer = DiverofficeImport(self.iface.mainWindow(), ms)
importer.select_files_and_load_gui()
importer.start_import(importer.files, importer.skip_rows.checked, importer.confirm_names.checked, importer.import_all_data.checked)
print('\n'.join([str(x) for x in mock_messagebarandlog.mock_calls]))
示例7: test_use
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_use(self):
ammo = Ammo(manager)
target = Mock()
target.value = 10
target.name = "mock"
ammo.use(target)
assert_equal(0, ammo.amt)
示例8: test_getHostGuestMapping
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_getHostGuestMapping(self, mock_client):
expected_hostname = 'hostname.domainname'
expected_hypervisorId = 'Fake_uuid'
expected_guestId = 'guest1UUID'
expected_guest_state = Guest.STATE_RUNNING
fake_parent = MagicMock()
fake_parent.value = 'Fake_parent'
fake_vm_id = MagicMock()
fake_vm_id.value = 'guest1'
fake_vm = MagicMock()
fake_vm.ManagedObjectReference = [fake_vm_id]
fake_vms = {'guest1': {'runtime.powerState': 'poweredOn',
'config.uuid': expected_guestId}}
self.esx.vms = fake_vms
fake_host = {'hardware.systemInfo.uuid': expected_hypervisorId,
'config.network.dnsConfig.hostName': 'hostname',
'config.network.dnsConfig.domainName': 'domainname',
'hardware.cpuInfo.numCpuPackages': '1',
'name': expected_hostname,
'parent': fake_parent,
'vm': fake_vm
}
fake_hosts = {'random-host-id': fake_host}
self.esx.hosts = fake_hosts
expected_result = Hypervisor(
hypervisorId=expected_hypervisorId,
name=expected_hostname,
guestIds=[
Guest(
expected_guestId,
self.esx,
expected_guest_state,
hypervisorType='vmware'
)
],
facts={
'cpu.cpu_socket(s)': '1',
}
)
result = self.esx.getHostGuestMapping()['hypervisors'][0]
self.assertEqual(expected_result.toDict(), result.toDict())
示例9: test_walk_StringNode
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_walk_StringNode(self):
nw = GraphDSLNodeWalker(self.graphmgr)
node = MagicMock()
node.value = 'expected'
nw.walk_StringNode(node, [])
self.assertEqual(node.value, 'expected')
示例10: test_walk_NaturalNode
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_walk_NaturalNode(self):
nw = GraphDSLNodeWalker(self.graphmgr)
node = MagicMock()
node.value = '42'
nw.walk_NaturalNode(node, [])
self.assertEqual(node.value, 42)
示例11: test_update_host_cache_in_thread
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_update_host_cache_in_thread(self, disconnect_mock, connect_mock,
spec_mock, update_mock,
update_host_mock, query_spec_mock,
perf_manager_mock,
prop_collector_mock):
# Test Values.
counter = MagicMock()
counter.groupInfo.key = "mem"
counter.nameInfo.key = "consumed"
counter.key = 65613
n = 5
statValues = ','.join([str(x) for x in range(1, n+1)])
statAverage = sum(range(1, n+1)) / len(range(1, n+1))
stat = MagicMock()
stat.value = [MagicMock()]
stat.value[0].id.counterId = 65613
stat.value[0].value = statValues
# Mock the Vim APIs.
pc_return_mock = MagicMock({'WaitForUpdatesEx.return_value': {}})
summarize_stats = {'QueryPerf.return_value': [stat]}
pm_return_mock = MagicMock(perfCounter=[counter], **summarize_stats)
# Tie the mocked APIs with VimClient.
prop_collector_mock.return_value = pc_return_mock
perf_manager_mock.return_value = pm_return_mock
# Create VimClient.
vim_client = VimClient("esx.local", "root", "password",
min_interval=0.1, auto_sync=True,
stats_interval=0.2)
# Verify that the update mock is called a few times.
retry = 0
while update_mock.call_count < 5 and retry < 10:
time.sleep(0.2)
retry += 1
assert_that(retry, is_not(10), "VimClient.update_mock is not "
"called repeatedly")
# Disconnect the client and stop the thread.
vim_client.disconnect(wait=True)
assert_that(disconnect_mock.called, is_(True))
# Verify that update_host_mock is called atleast once and is called
# less number of times than update_mock.
assert_that(update_host_mock.call_count, is_not(0),
"VimClient.update_host_mock is not called repeatedly")
assert_that(update_host_mock.call_count,
less_than(update_mock.call_count))
host_stats = update_host_mock.call_args_list
for host in host_stats:
assert_that(host[0][0]['mem.consumed'], equal_to(statAverage))
示例12: test_done_error
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_done_error(self):
"""
The done deferred should errback if the process didn't exit with a
success code.
"""
proto = SimpleProtocol(lambda x: None)
status = MagicMock()
status.value = ProcessTerminated()
proto.processEnded(status)
self.assertFailure(proto.done, ProcessTerminated)
示例13: test_done
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_done(self):
"""
The done callback should be called when the process is ended
"""
proto = SimpleProtocol(lambda x: None)
status = MagicMock()
status.value = MagicMock()
status.value.exitCode = 0
proto.processEnded(status)
self.assertEqual(self.successResultOf(proto.done), status.value)
示例14: test_result_ascending_order_with_same_value
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_result_ascending_order_with_same_value(self):
mock1 = MagicMock()
mock1.value = [20, 'units']
mock1_run_object = MagicMock()
mock1_run_object.getProperty = MagicMock(return_value=mock1)
nxsdata_to_compare_with = MagicMock()
nxsdata_to_compare_with.active_data.nxs.getRun = MagicMock(return_value=mock1_run_object)
mock2 = MagicMock()
mock2.value = [20, 'units']
mock2_run_object = MagicMock()
mock2_run_object.getProperty = MagicMock(return_value=mock2)
nxsdata_to_position = MagicMock()
nxsdata_to_position.active_data.nxs.getRun = MagicMock(return_value=mock2_run_object)
criteria1 = ['arg1', 'descending']
criteria2 = ['arg2', 'descending']
cmp_nxs_data = CompareTwoNXSData(nxsdata_to_compare_with=nxsdata_to_compare_with,
nxsdata_to_position=nxsdata_to_position,
criteria1=criteria1,
criteria2=criteria2)
self.assertEqual(0, cmp_nxs_data.result())
示例15: test_getValue_to_position
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import value [as 别名]
def test_getValue_to_position(self):
''' Assert retrieve value of getRun object for nexusToPosition '''
mock1 = MagicMock()
mock1.value = [10, 'units']
mock_run_object = MagicMock()
mock_run_object.getProperty = MagicMock(return_value=mock1)
nxsdata_to_position = MagicMock()
nxsdata_to_position.active_data.nxs.getRun = MagicMock(return_value=mock_run_object)
cmp_nxs_data = CompareTwoNXSData(nxsdata_to_compare_with=mock1,
nxsdata_to_position=nxsdata_to_position,
criteria1=self.criteria1,
criteria2=self.criteria2)
_param_nexus_to_position = cmp_nxs_data.param_nexus_to_position
self.assertEqual(10, _param_nexus_to_position)