Skip to content

Instantly share code, notes, and snippets.

@joshkel
Created September 25, 2018 02:23
Show Gist options
  • Select an option

  • Save joshkel/36183faee736400c0fe1e863867e15ef to your computer and use it in GitHub Desktop.

Select an option

Save joshkel/36183faee736400c0fe1e863867e15ef to your computer and use it in GitHub Desktop.

Revisions

  1. joshkel created this gist Sep 25, 2018.
    25 changes: 25 additions & 0 deletions protobuf_test.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/usr/bin/env python3
    # Test file demonstrating issues from
    # https://github.com/protocolbuffers/protobuf/pull/5166
    # Try running with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
    # and with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp

    import subprocess

    proto_definition = """
    syntax = "proto2";
    message TestMessage
    {
    optional int32 value = 1;
    }
    """

    with open('test.proto', 'w') as f:
    f.write(proto_definition)
    subprocess.check_call(['protoc', '--python_out=.', 'test.proto'])

    import test_pb2 # noqa

    test_message = test_pb2.TestMessage()
    print(test_message.ParseFromString(b'test'))