本文整理汇总了Python中mock.MagicMock.id方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.id方法的具体用法?Python MagicMock.id怎么用?Python MagicMock.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_from_rest_analyte
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_create_from_rest_analyte(self):
udfs = {"Some udf": 10}
api_resource = MagicMock()
api_resource.udf = udfs
api_resource.location = [None, "B:2"]
sample = MagicMock()
sample.id = "sample1"
api_resource.samples = [sample]
api_resource.id = "art1"
api_resource.name = "sample1"
container_repo = MagicMock()
container = fake_container("cont1")
container_repo.get_container.return_value = container
clarity_mapper = ClarityMapper()
analyte = clarity_mapper.analyte_create_object(
api_resource, is_input=True, container_repo=container_repo, process_type=MagicMock())
expected_analyte = fake_analyte(container_id="cont1", artifact_id="art1", sample_ids=["sample1"],
analyte_name="sample1", well_key="B:2", is_input=True,
requested_volume=10, udfs=udfs)
self.assertEqual(expected_analyte.udf_some_udf,
analyte.udf_some_udf)
self.assertEqual(expected_analyte.id, analyte.id)
self.assertEqual(expected_analyte.name, analyte.name)
self.assertEqual(expected_analyte.well.__repr__(),
analyte.well.__repr__())
self.assertEqual(expected_analyte.well.artifact.name,
analyte.well.artifact.name)
示例2: test_writing_device_output
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_writing_device_output(self):
""" Tests that the Driver class can pass its output to its registered pipelines. The default implementation of the
Driver.write_output() method only writes to active pipelines that specify this device as its output device.
"""
# Load a device to test with
test_driver = self.device_manager.get_device_driver("test_device")
# Create some mock pipelines and register them with the device
test_pipeline = MagicMock()
test_pipeline.id = "test_pipeline"
test_pipeline.is_active = False
test_driver.register_pipeline(test_pipeline)
test_pipeline_2 = MagicMock()
test_pipeline_2.id = "test_pipeline_2"
test_pipeline_2.is_active = True
test_driver.register_pipeline(test_pipeline_2)
test_pipeline_3 = MagicMock()
test_pipeline_3.id = "test_pipeline_3"
test_pipeline_3.is_active = True
test_pipeline_3.output_device = test_driver
test_driver.register_pipeline(test_pipeline_3)
# Write some output to the associated pipelines
test_driver.write_output("waffles")
# Make sure the output never made it to the non-active pipeline
self.assertEqual(test_pipeline.write_output.call_count, 0)
# Make sure that test_pipeline_2 was never called (doesn't specify test_device as its output device)
self.assertEqual(test_pipeline_2.write_output.call_count, 0)
# Verify that test_pipeline_3 was called with the correct output
test_pipeline_3.write_output.assert_called_once_with("waffles")
示例3: test_service_registration
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_service_registration(self):
""" Verifies that the Pipeline class can correctly register services. The service registration feature allows
devices to offer services or script access to other devices in the pipeline.
"""
# Load the pipeline configuration and create a test pipeline
self.config.read_configuration(self.source_data_directory+'/hardware/pipelines/tests/data/pipeline_configuration_valid.yml')
test_pipeline = pipeline.Pipeline(self.config.get('pipelines')[0], self.device_manager, self.command_parser)
test_service_type = 'waffle'
# Create and register a mock service
test_service = MagicMock()
test_service.id = 'test_service'
test_service.type = test_service_type
test_pipeline.register_service(test_service)
self.assertTrue(test_pipeline.services[test_service_type]['test_service'] is test_service)
# Create and register a mock service with the same type but a different ID
test_service_2 = MagicMock()
test_service_2.id = 'test_service_2'
test_service_2.type = test_service_type
test_pipeline.register_service(test_service_2)
self.assertTrue(test_pipeline.services[test_service_type]['test_service_2'] is test_service_2)
# Try to register a third service with the same type and ID as an earlier service
test_service_3 = MagicMock()
test_service_3.id = 'test_service'
test_service_3.type = test_service_type
self.assertRaises(pipeline.ServiceAlreadyRegistered, test_pipeline.register_service, test_service_3)
示例4: test_pipeline_registration
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_pipeline_registration(self):
""" Verifies that the base driver class can correctly register pipelines
"""
# Load a driver to test with
test_driver = self.device_manager.get_device_driver("test_device")
# Create some mock pipelines to register with the device
test_pipeline = MagicMock()
test_pipeline.id = "test_pipeline"
test_pipeline.output_device = test_driver
test_pipeline_2 = MagicMock()
test_pipeline_2.id = "test_pipeline_2"
test_pipeline_2.output_device = test_driver
# Register the pipelines
test_driver.register_pipeline(test_pipeline)
test_driver.register_pipeline(test_pipeline_2)
self.assertTrue((test_driver.associated_pipelines[test_pipeline.id].id == test_pipeline.id) and
(test_driver.associated_pipelines[test_pipeline.id].output_device is test_driver))
self.assertTrue((test_driver.associated_pipelines[test_pipeline_2.id].id == test_pipeline_2.id) and
(test_driver.associated_pipelines[test_pipeline_2.id].output_device is test_driver))
# Make sure that pipelines can't be re-registered
self.assertRaises(driver.PipelineAlreadyRegistered, test_driver.register_pipeline, test_pipeline)
示例5: test_30_updateVMInfo
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_30_updateVMInfo(self, get_driver):
radl_data = """
network net (outbound = 'yes')
system test (
cpu.arch='x86_64' and
cpu.count=1 and
memory.size=512m and
net_interface.0.connection = 'net' and
net_interface.0.ip = '158.42.1.1' and
net_interface.0.dns_name = 'test' and
disk.0.os.name = 'linux' and
disk.0.image.url = 'aws://ami-id' and
disk.0.os.credentials.username = 'user' and
disk.0.os.credentials.password = 'pass'
)"""
radl = radl_parse.parse_radl(radl_data)
radl.check()
auth = Authentication([{'id': 'libcloud', 'type': 'LibCloud', 'username': 'user',
'password': 'pass', 'driver': 'EC2'}])
lib_cloud = self.get_lib_cloud()
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", lib_cloud.cloud, radl, radl, lib_cloud)
driver = MagicMock()
driver.name = "Amazon EC2"
get_driver.return_value = driver
node = MagicMock()
node.id = "1"
node.state = "running"
node.extra = {'availability': 'use-east-1'}
node.public_ips = []
node.private_ips = ['10.0.0.1']
node.driver = driver
node.size = MagicMock()
node.size.ram = 512
node.size.price = 1
node.size.disk = 1
node.size.vcpus = 1
node.size.name = "small"
driver.list_nodes.return_value = [node]
volume = MagicMock()
volume.id = "vol1"
volume.extra = {"state": "available"}
volume.attach.return_value = True
driver.create_volume.return_value = volume
driver.ex_allocate_address.return_value = "10.0.0.1"
success, vm = lib_cloud.updateVMInfo(vm, auth)
self.assertTrue(success, msg="ERROR: updating VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例6: test_service_activation_and_lookup
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_service_activation_and_lookup(self):
""" This tests that the service activation and lookup methods are working as expected. In order for a service to be
query-able, it must be active (as specified by the configuration for the session using the pipeline).
"""
# Create a test pipeline to work with
self.config.read_configuration(self.source_data_directory+'/hardware/pipelines/tests/data/pipeline_configuration_valid.yml')
test_pipeline = pipeline.Pipeline(self.config.get('pipelines')[0], self.device_manager, self.command_parser)
# Create some mock services and register them with the pipeline
test_tracker_service = MagicMock()
test_tracker_service.id = "sgp4"
test_tracker_service.type = "tracker"
test_pipeline.register_service(test_tracker_service)
test_logger_service = MagicMock()
test_logger_service.id = "basic"
test_logger_service.type = "logger"
test_pipeline.register_service(test_logger_service)
test_cornballer_service = MagicMock()
test_cornballer_service.id = "deluxe"
test_cornballer_service.type = "cornballer"
test_pipeline.register_service(test_cornballer_service)
# Define a callback to continue the test after the schedule has been loaded
def continue_test(reservation_schedule):
# Load a reservation that specifies some active services
test_reservation_config = self._load_reservation_config(reservation_schedule, 'RES.5')
# Create a new session
test_session = session.Session(test_reservation_config, test_pipeline, self.command_parser)
# Register the session with the pipeline; this will also activate the reservation's services
test_pipeline.register_session(test_session)
# Make sure the active services can be loaded
self.assertTrue(test_pipeline.load_service("tracker") is test_tracker_service)
self.assertTrue(test_pipeline.load_service("logger") is test_logger_service)
self.assertRaises(pipeline.ServiceTypeNotFound, test_pipeline.load_service, "cornballer")
# Add an unknown active service type to the reservation configuration and re-register it
test_pipeline.current_session = None
test_reservation_config['active_services']['nonexistent_type'] = "nonexistent_service"
test_session = session.Session(test_reservation_config, test_pipeline, self.command_parser)
self.assertRaises(pipeline.ServiceInvalid, test_pipeline.register_session, test_session)
# Add an unknown active service ID to the reservation configuration and re-register it
test_pipeline.current_session = None
test_reservation_config['active_services'].pop("nonexistent_type", None)
test_reservation_config['active_services']['tracker'] = "nonexistent_service"
test_session = session.Session(test_reservation_config, test_pipeline, self.command_parser)
self.assertRaises(pipeline.ServiceInvalid, test_pipeline.register_session, test_session)
# Load up a test schedule to work with
schedule_update_deferred = self._load_test_schedule()
schedule_update_deferred.addCallback(continue_test)
return schedule_update_deferred
示例7: mock_artifact_resource
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def mock_artifact_resource(resouce_id=None, sample_name=None, well_position=None):
api_resource = MagicMock()
if well_position:
api_resource.location = [None, well_position]
sample = MagicMock()
sample.id = sample_name
api_resource.samples = [sample]
api_resource.id = resouce_id
api_resource.name = sample_name
return api_resource
示例8: test_30_updateVMInfo
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_30_updateVMInfo(self, get_driver):
radl_data = """
network net (outbound = 'yes')
system test (
cpu.arch='x86_64' and
cpu.count=1 and
memory.size=512m and
net_interface.0.connection = 'net' and
net_interface.0.dns_name = 'test' and
disk.0.os.name = 'linux' and
disk.0.image.url = 'gce://us-central1-a/centos-6' and
disk.0.os.credentials.username = 'user' and
disk.1.size=1GB and
disk.1.device='hdb' and
disk.1.mount_path='/mnt/path'
)"""
radl = radl_parse.parse_radl(radl_data)
radl.check()
auth = Authentication([{'id': 'one', 'type': 'GCE', 'username': 'user',
'password': 'pass\npass', 'project': 'proj'}])
gce_cloud = self.get_gce_cloud()
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", gce_cloud.cloud, radl, radl, gce_cloud)
driver = MagicMock()
get_driver.return_value = driver
node = MagicMock()
zone = MagicMock()
node.id = "1"
node.state = "running"
node.extra = {'flavorId': 'small'}
node.public_ips = []
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
zone.name = 'us-central1-a'
node.extra = {'zone': zone}
driver.ex_get_node.return_value = node
volume = MagicMock()
volume.id = "vol1"
volume.attach.return_value = True
volume.extra = {'status': 'READY'}
driver.create_volume.return_value = volume
success, vm = gce_cloud.updateVMInfo(vm, auth)
self.assertTrue(success, msg="ERROR: updating VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例9: test_session_termination
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_session_termination(self):
""" This test checks that the session coordinator can correctly clean up sessions once they expire (as determined by
their reservation timestamp range).
"""
# Load in some valid configuration and set the defaults using validate_configuration()
self.config.read_configuration(self.source_data_directory+'/core/tests/data/test_config_basic.yml')
self.config.read_configuration(self.source_data_directory+'/hardware/pipelines/tests/data/pipeline_configuration_valid.yml')
self.config.validate_configuration()
# Setup the pipeline manager
test_pipelines = pipeline_manager.PipelineManager(self.device_manager, self.command_parser)
# Create the expected mock services
test_tracker_service = MagicMock()
test_tracker_service.id = "sgp4"
test_tracker_service.type = "tracker"
test_pipelines.pipelines['test_pipeline3'].register_service(test_tracker_service)
test_logger_service = MagicMock()
test_logger_service.id = "basic"
test_logger_service.type = "logger"
test_pipelines.pipelines['test_pipeline3'].register_service(test_logger_service)
# Setup the schedule manager
test_schedule = schedule.ScheduleManager(self.source_data_directory+'/sessions/tests/data/test_schedule_valid.json')
# Initialize the session coordinator
session_coordinator = coordinator.SessionCoordinator(test_schedule,
self.device_manager,
test_pipelines,
self.command_parser)
def continue_test(loaded_schedule):
# Activate the test reservation
session_coordinator._check_for_new_reservations()
self.assertTrue('RES.6' in session_coordinator.active_sessions)
res6 = session_coordinator.active_sessions['RES.6']
res6.kill_session = MagicMock()
# Change the expiration time on the reservation to make it expire
res6.configuration['time_end'] = 1383264000
# Kill the expired session
session_coordinator._check_for_finished_sessions()
res6.kill_session.assert_called_once_with()
self.assertTrue('RES.6' in session_coordinator.closed_sessions and
'RES.6' not in session_coordinator.active_sessions)
# Update the schedule to load in the reservations
schedule_update_deferred = test_schedule.update_schedule()
schedule_update_deferred.addCallback(continue_test)
return schedule_update_deferred
示例10: test_session_startup_pipeline_setup_command_errors
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_session_startup_pipeline_setup_command_errors(self):
""" Tests that the Session class correctly handles fatal pipeline setup command errors when starting a new session.
"""
# First create a pipeline that contains invalid pipeline setup commands (to force an error)
test_pipeline = pipeline.Pipeline(self.config.get('pipelines')[2], self.device_manager, self.command_parser)
# Create the expected mock services
test_tracker_service = MagicMock()
test_tracker_service.id = "sgp4"
test_tracker_service.type = "tracker"
test_pipeline.register_service(test_tracker_service)
test_logger_service = MagicMock()
test_logger_service.id = "basic"
test_logger_service.type = "logger"
test_pipeline.register_service(test_logger_service)
# Define a callback to check the results of the session start procedure
def check_results(session_start_failure, test_session):
# Check if the correct error was generated (caused by a failed pipeline setup command)
self.assertTrue(isinstance(session_start_failure.value, parser.CommandFailed))
# Make sure the session is not active
self.assertTrue(not test_session.is_active)
# Make sure that the pipeline was freed after the error
self.assertTrue(not test_pipeline.is_active)
for temp_device in test_pipeline.devices:
# Try to lock the devices, if this fails then something wasn't unlocked correctly
test_pipeline.devices[temp_device].reserve_device()
# Define a callback to continue the test after the schedule has been loaded
def continue_test(reservation_schedule):
# Find the reservation that we want to test with
test_reservation_config = self._load_reservation_config(reservation_schedule, 'RES.5')
# Create a new session
test_session = session.Session(test_reservation_config, test_pipeline, self.command_parser)
# Start the session
session_start_deferred = test_session.start_session()
session_start_deferred.addErrback(check_results, test_session)
return session_start_deferred
# Now load up a test schedule to work with
schedule_update_deferred = self._load_test_schedule()
schedule_update_deferred.addCallback(continue_test)
return schedule_update_deferred
示例11: test_60_finalize
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_60_finalize(self, get_driver):
auth = Authentication([{'id': 'libcloud', 'type': 'LibCloud', 'username': 'user',
'password': 'pass', 'driver': 'EC2'}])
lib_cloud = self.get_lib_cloud()
radl_data = """
system test (
cpu.count>=2 and
memory.size>=2048m
)"""
radl = radl_parse.parse_radl(radl_data)
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", lib_cloud.cloud, radl, radl, lib_cloud)
vm.keypair = ""
driver = MagicMock()
driver.name = "Amazon EC2"
get_driver.return_value = driver
node = MagicMock()
node.id = "1"
node.state = "running"
node.driver = driver
node.destroy.return_value = True
driver.list_nodes.return_value = [node]
sg = MagicMock()
sg.id = sg.name = "sg1"
driver.ex_get_node_security_groups.return_value = [sg]
keypair = MagicMock()
driver.get_key_pair.return_value = keypair
vm.keypair = keypair
volume = MagicMock()
volume.id = "id"
vm.volumes = [volume]
driver.delete_key_pair.return_value = True
driver.ex_describe_addresses_for_node.return_value = ["ip"]
driver.ex_disassociate_address.return_value = True
success, _ = lib_cloud.finalize(vm, auth)
self.assertTrue(success, msg="ERROR: finalizing VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例12: test_no_members_cannot_post
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_no_members_cannot_post(self, gi):
'If there are no posting members then everyone can post'
g = self.get_group_with_posting_members([])
u = MagicMock()
u.id = 'postingMember'
pm = PostingMember(u, g)
pm.check()
self.assert_can_post(pm)
u = MagicMock()
u.id = 'normalMember'
pm = PostingMember(u, g)
pm.check()
self.assert_can_post(pm)
示例13: test__get_relative_path
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test__get_relative_path(self):
repo = MagicMock()
repo.id = 'awesome_repo'
relative_path = publish._get_relative_path(repo)
self.assertEqual(relative_path, repo.id)
示例14: test__remove_repository_protection
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test__remove_repository_protection(self, delete_protected_repo):
repo = MagicMock()
repo.id = 'reporeporeporepo'
publish.remove_repository_protection(repo)
delete_protected_repo.assert_called_once_with(publish._get_relative_path(repo))
示例15: test_recursive_removal
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import id [as 别名]
def test_recursive_removal(self):
item1 = MagicMock()
item1.id = "item1"
item1._deps = ["item2"]
item2 = MagicMock()
item2.id = "item2"
item2._deps = ["item3"]
item3 = MagicMock()
item3.id = "item3"
item3._deps = []
items = [item1, item2, item3]
self.assertEqual(
deps.remove_item_dependents(items, "item3"),
([item3], [item2, item1]),
)