示例#1
0
def test_build_with_annotations():
    proto = descriptor_pb2.FileDescriptorProto(
        name='spanner.proto',
        package='google.spanner.v1',
    )
    proto.options.Extensions[annotations_pb2.metadata].MergeFrom(
        metadata_pb2.Metadata(package_namespace=['Google', 'Cloud']), )
    n = naming.Naming.build(proto)
    assert n.name == 'Spanner'
    assert n.namespace == ('Google', 'Cloud')
    assert n.version == 'v1'
    assert n.product_name == 'Spanner'
示例#2
0
def test_inconsistent_metadata_error():
    # Set up the first proto.
    proto1 = descriptor_pb2.FileDescriptorProto(
        name='spanner.proto',
        package='google.spanner.v1',
    )
    proto1.options.Extensions[annotations_pb2.metadata].MergeFrom(
        metadata_pb2.Metadata(package_namespace=['Google', 'Cloud']), )

    # Set up the second proto.
    # Note that
    proto2 = descriptor_pb2.FileDescriptorProto(
        name='spanner2.proto',
        package='google.spanner.v1',
    )
    proto2.options.Extensions[annotations_pb2.metadata].MergeFrom(
        metadata_pb2.Metadata(package_namespace=['Google', 'Cloud'],
                              package_name='Spanner'), )

    # This should error. Even though the data in the metadata is consistent,
    # it is expected to exactly match, and it does not.
    with pytest.raises(ValueError):
        naming.Naming.build(proto1, proto2)