Exemplo n.º 1
0
 def to_proto(self):
     time_slot = qtypes.QuantumTimeSlot(
         processor_name=self.processor_id,
         start_time=_to_timestamp(self.start_time),
         end_time=_to_timestamp(self.end_time),
         slot_type=self.slot_type,
     )
     if self.project_id:
         time_slot.reservation_config.project_id = self.project_id
     config = time_slot.maintenance_config
     if self.maintenance_title:
         config.title = self.maintenance_title
     if self.maintenance_description:
         config.description = self.maintenance_description
     return time_slot
Exemplo n.º 2
0
def test_from_to_proto_plain():
    slot = enums.QuantumTimeSlot.TimeSlotType.RESERVATION
    proto = qtypes.QuantumTimeSlot(
        processor_name='potofgold',
        start_time=Timestamp(seconds=1500000000),
        end_time=Timestamp(seconds=1500010000),
        slot_type=slot,
    )
    time_slot = cg.EngineTimeSlot(
        processor_id='potofgold',
        start_time=datetime.datetime.fromtimestamp(1500000000),
        end_time=datetime.datetime.fromtimestamp(1500010000),
        slot_type=slot,
    )
    actual_from_proto = cg.EngineTimeSlot.from_proto(proto)
    assert actual_from_proto == time_slot
    actual_to_proto = cg.EngineTimeSlot.to_proto(time_slot)
    assert actual_to_proto == proto
Exemplo n.º 3
0
def test_from_to_proto_reservation():
    slot = enums.QuantumTimeSlot.TimeSlotType.RESERVATION
    proto = qtypes.QuantumTimeSlot(
        processor_name='potofgold',
        start_time=Timestamp(seconds=1500000000),
        end_time=Timestamp(seconds=1500010000),
        slot_type=slot,
        reservation_config=qtypes.QuantumTimeSlot.ReservationConfig(
            project_id='super_secret_quantum'),
    )
    time_slot = cg.EngineTimeSlot(
        processor_id='potofgold',
        start_time=datetime.datetime.fromtimestamp(1500000000),
        end_time=datetime.datetime.fromtimestamp(1500010000),
        slot_type=slot,
        project_id='super_secret_quantum',
    )
    actual_from_proto = cg.EngineTimeSlot.from_proto(proto)
    assert actual_from_proto == time_slot
    actual_to_proto = cg.EngineTimeSlot.to_proto(time_slot)
    assert actual_to_proto == proto
Exemplo n.º 4
0
def test_from_to_proto_maintenance():
    slot = enums.QuantumTimeSlot.TimeSlotType.MAINTENANCE
    proto = qtypes.QuantumTimeSlot(
        processor_name='potofgold',
        start_time=Timestamp(seconds=1500020000),
        end_time=Timestamp(seconds=1500040000),
        slot_type=slot,
        maintenance_config=qtypes.QuantumTimeSlot.MaintenanceConfig(
            title='Testing',
            description='Testing some new configuration.',
        ),
    )
    time_slot = cg.EngineTimeSlot(
        processor_id='potofgold',
        start_time=datetime.datetime.fromtimestamp(1500020000),
        end_time=datetime.datetime.fromtimestamp(1500040000),
        slot_type=slot,
        maintenance_title='Testing',
        maintenance_description='Testing some new configuration.',
    )
    actual_from_proto = cg.EngineTimeSlot.from_proto(proto)
    assert actual_from_proto == time_slot
    actual_to_proto = cg.EngineTimeSlot.to_proto(time_slot)
    assert actual_to_proto == proto