当前位置: 首页>>代码示例>>Python>>正文


Python timestamp_pb2.Timestamp方法代码示例

本文整理汇总了Python中google.protobuf.timestamp_pb2.Timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python timestamp_pb2.Timestamp方法的具体用法?Python timestamp_pb2.Timestamp怎么用?Python timestamp_pb2.Timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.protobuf.timestamp_pb2的用法示例。


在下文中一共展示了timestamp_pb2.Timestamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_message

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def create_message(data, ack_id="ACKID", delivery_attempt=0, ordering_key="", **attrs):
    with mock.patch.object(time, "time") as time_:
        time_.return_value = RECEIVED_SECONDS
        msg = message.Message(
            message=types.PubsubMessage(
                attributes=attrs,
                data=data,
                message_id="message_id",
                publish_time=timestamp_pb2.Timestamp(
                    seconds=PUBLISHED_SECONDS, nanos=PUBLISHED_MICROS * 1000
                ),
                ordering_key=ordering_key,
            ),
            ack_id=ack_id,
            delivery_attempt=delivery_attempt,
            request_queue=queue.Queue(),
        )
        return msg 
开发者ID:googleapis,项目名称:python-pubsub,代码行数:20,代码来源:test_message.py

示例2: test_create_reservation

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_create_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    start = datetime.datetime.fromtimestamp(1000000000)
    end = datetime.datetime.fromtimestamp(1000003600)
    users = ['jeff@google.com']
    result = qtypes.QuantumReservation(
        name='projects/proj/processors/processor0/reservations/papar-party-44',
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000003600),
        whitelisted_users=users,
    )
    grpc_client.create_quantum_reservation.return_value = result

    client = EngineClient()
    assert client.create_reservation('proj', 'processor0', start, end,
                                     users) == result
    assert grpc_client.create_quantum_reservation.call_count == 1
    kwargs = grpc_client.create_quantum_reservation.call_args[1]
    # The outgoing argument will not have the resource name
    result.name = ''
    assert kwargs == {
        'parent': 'projects/proj/processors/processor0',
        'quantum_reservation': result
    } 
开发者ID:quantumlib,项目名称:Cirq,代码行数:26,代码来源:engine_client_test.py

示例3: test_cancel_reservation

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_cancel_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000002000),
        whitelisted_users=['jeff@google.com'],
    )
    grpc_client.cancel_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.cancel_reservation('proj', 'processor0',
                                      'papar-party-44') == result)
    kwargs = grpc_client.cancel_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
    } 
开发者ID:quantumlib,项目名称:Cirq,代码行数:20,代码来源:engine_client_test.py

示例4: test_delete_reservation

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_delete_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000002000),
        whitelisted_users=['jeff@google.com'],
    )
    grpc_client.delete_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.delete_reservation('proj', 'processor0',
                                      'papar-party-44') == result)
    kwargs = grpc_client.delete_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
    } 
开发者ID:quantumlib,项目名称:Cirq,代码行数:20,代码来源:engine_client_test.py

示例5: test_get_reservation

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_get_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000002000),
        whitelisted_users=['jeff@google.com'],
    )
    grpc_client.get_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.get_reservation('proj', 'processor0',
                                   'papar-party-44') == result)
    kwargs = grpc_client.get_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
    } 
开发者ID:quantumlib,项目名称:Cirq,代码行数:20,代码来源:engine_client_test.py

示例6: test_from_to_proto_plain

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
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 
开发者ID:quantumlib,项目名称:Cirq,代码行数:20,代码来源:engine_timeslot_test.py

示例7: test_from_to_proto_reservation

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
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 
开发者ID:quantumlib,项目名称:Cirq,代码行数:23,代码来源:engine_timeslot_test.py

示例8: test_from_to_proto_maintenance

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
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 
开发者ID:quantumlib,项目名称:Cirq,代码行数:26,代码来源:engine_timeslot_test.py

示例9: test_create_reservation

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_create_reservation(create_reservation):
    name = 'projects/proj/processors/p0/reservations/psherman-wallaby-way'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000003600),
        whitelisted_users=['dstrain@google.com'],
    )
    create_reservation.return_value = result
    processor = cg.EngineProcessor('proj', 'p0', EngineContext())
    assert processor.create_reservation(
        datetime.datetime.fromtimestamp(1000000000),
        datetime.datetime.fromtimestamp(1000003600), ['dstrain@google.com'])
    create_reservation.assert_called_once_with(
        'proj', 'p0', datetime.datetime.fromtimestamp(1000000000),
        datetime.datetime.fromtimestamp(1000003600), ['dstrain@google.com']) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:18,代码来源:engine_processor_test.py

示例10: test_remove_reservation_delete

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_remove_reservation_delete(delete_reservation, get_reservation):
    name = 'projects/proj/processors/p0/reservations/rid'
    now = int(datetime.datetime.now().timestamp())
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=now + 20000),
        end_time=Timestamp(seconds=now + 23610),
        whitelisted_users=['dstrain@google.com'],
    )
    get_reservation.return_value = result
    delete_reservation.return_value = result
    processor = cg.EngineProcessor(
        'proj', 'p0', EngineContext(),
        qtypes.QuantumProcessor(schedule_frozen_period=Duration(seconds=10000)))
    assert processor.remove_reservation('rid') == result
    delete_reservation.assert_called_once_with('proj', 'p0', 'rid') 
开发者ID:quantumlib,项目名称:Cirq,代码行数:18,代码来源:engine_processor_test.py

示例11: test_remove_reservation_cancel

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_remove_reservation_cancel(cancel_reservation, get_reservation):
    name = 'projects/proj/processors/p0/reservations/rid'
    now = int(datetime.datetime.now().timestamp())
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=now + 10),
        end_time=Timestamp(seconds=now + 3610),
        whitelisted_users=['dstrain@google.com'],
    )
    get_reservation.return_value = result
    cancel_reservation.return_value = result
    processor = cg.EngineProcessor(
        'proj', 'p0', EngineContext(),
        qtypes.QuantumProcessor(schedule_frozen_period=Duration(seconds=10000)))
    assert processor.remove_reservation('rid') == result
    cancel_reservation.assert_called_once_with('proj', 'p0', 'rid') 
开发者ID:quantumlib,项目名称:Cirq,代码行数:18,代码来源:engine_processor_test.py

示例12: test_remove_reservation_failures

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_remove_reservation_failures(get_reservation, get_processor):
    name = 'projects/proj/processors/p0/reservations/rid'
    now = int(datetime.datetime.now().timestamp())
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=now + 10),
        end_time=Timestamp(seconds=now + 3610),
        whitelisted_users=['dstrain@google.com'],
    )
    get_reservation.return_value = result
    get_processor.return_value = None

    # no processor
    processor = cg.EngineProcessor('proj', 'p0', EngineContext())
    with pytest.raises(ValueError):
        processor.remove_reservation('rid')

    # No freeze period defined
    processor = cg.EngineProcessor('proj', 'p0', EngineContext(),
                                   qtypes.QuantumProcessor())
    with pytest.raises(ValueError):
        processor.remove_reservation('rid') 
开发者ID:quantumlib,项目名称:Cirq,代码行数:24,代码来源:engine_processor_test.py

示例13: test_update_reservation

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_update_reservation(update_reservation):
    name = 'projects/proj/processors/p0/reservations/rid'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000003600),
        whitelisted_users=['dstrain@google.com'],
    )
    start = datetime.datetime.fromtimestamp(1000000000)
    end = datetime.datetime.fromtimestamp(1000003600)
    update_reservation.return_value = result
    processor = cg.EngineProcessor('proj', 'p0', EngineContext())
    assert processor.update_reservation('rid', start, end,
                                        ['dstrain@google.com']) == result
    update_reservation.assert_called_once_with(
        'proj',
        'p0',
        'rid',
        start=start,
        end=end,
        whitelisted_users=['dstrain@google.com']) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:23,代码来源:engine_processor_test.py

示例14: test_get_schedule_filter_by_time_slot

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def test_get_schedule_filter_by_time_slot(list_time_slots):
    results = [
        qtypes.QuantumTimeSlot(
            processor_name='potofgold',
            start_time=Timestamp(seconds=1000020000),
            end_time=Timestamp(seconds=1000040000),
            slot_type=qenums.QuantumTimeSlot.TimeSlotType.MAINTENANCE,
            maintenance_config=qtypes.QuantumTimeSlot.MaintenanceConfig(
                title='Testing',
                description='Testing some new configuration.',
            ),
        )
    ]
    list_time_slots.return_value = results
    processor = cg.EngineProcessor('proj', 'p0', EngineContext())

    assert processor.get_schedule(
        datetime.datetime.fromtimestamp(1000000000),
        datetime.datetime.fromtimestamp(1000050000),
        qenums.QuantumTimeSlot.TimeSlotType.MAINTENANCE) == results
    list_time_slots.assert_called_once_with(
        'proj', 'p0', 'start_time < 1000050000 AND end_time > 1000000000 AND ' +
        'time_slot_type = MAINTENANCE') 
开发者ID:quantumlib,项目名称:Cirq,代码行数:25,代码来源:engine_processor_test.py

示例15: _to_bq_value

# 需要导入模块: from google.protobuf import timestamp_pb2 [as 别名]
# 或者: from google.protobuf.timestamp_pb2 import Timestamp [as 别名]
def _to_bq_value(value, field_desc):
  if field_desc.enum_type:
    # Enums are stored as strings.
    enum_val = field_desc.enum_type.values_by_number.get(value)
    if not enum_val:
      raise ValueError('Invalid value %r for enum type %s' % (
          value, field_desc.enum_type.full_name))
    return enum_val.name
  elif isinstance(value, duration_pb2.Duration):
    return value.ToTimedelta().total_seconds()
  elif isinstance(value, struct_pb2.Struct):
    # Structs are stored as JSONPB strings,
    # see https://bit.ly/chromium-bq-struct
    return json_format.MessageToJson(value)
  elif isinstance(value, timestamp_pb2.Timestamp):
    return value.ToDatetime().isoformat()
  elif isinstance(value, message_pb.Message):
    return message_to_dict(value)
  else:
    return value 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:bqh.py


注:本文中的google.protobuf.timestamp_pb2.Timestamp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。