Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetDebugString to Python FileDescriptor interface. #7498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions python/google/protobuf/internal/descriptor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
name: 'TestEmptyMessage'
"""

TEST_FILE_DESCRIPTOR_DEBUG = """syntax = "proto2";

package protobuf_unittest;

message NestedMessage {
enum ForeignEnum {
FOREIGN_FOO = 4;
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
}
optional int32 bb = 1;
}

message ResponseMessage {
}

service Service {
rpc CallMethod(.protobuf_unittest.NestedMessage) returns (.protobuf_unittest.ResponseMessage);
}

"""


warnings.simplefilter('error', DeprecationWarning)

Expand Down Expand Up @@ -121,6 +143,13 @@ def testContainingTypeFixups(self):
def testContainingServiceFixups(self):
self.assertEqual(self.my_service, self.my_method.containing_service)

@unittest.skipIf(
api_implementation.Type() != 'cpp',
'GetDebugString is only available with the cpp implementation',
)
def testGetDebugString(self):
self.assertEqual(self.my_file.GetDebugString(), TEST_FILE_DESCRIPTOR_DEBUG)

Comment on lines +146 to +152
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this test be executed in python too as this PR merged that feature?
(sry just needed that feature and debugged on an older python-protobuf and stumbled over this PR, pls just ignore if everything is as it should be :)!

def testGetOptions(self):
self.assertEqual(self.my_enum.GetOptions(),
descriptor_pb2.EnumOptions())
Expand Down
5 changes: 5 additions & 0 deletions python/google/protobuf/pyext/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,10 @@ static int SetHasOptions(PyFileDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("has_options");
}

static PyObject* GetDebugString(PyFileDescriptor *self) {
return PyString_FromCppString(_GetDescriptor(self)->DebugString());
}

static PyObject* GetOptions(PyFileDescriptor *self) {
return GetOrBuildOptions(_GetDescriptor(self));
}
Expand Down Expand Up @@ -1439,6 +1443,7 @@ static PyGetSetDef Getters[] = {
};

static PyMethodDef Methods[] = {
{ "GetDebugString", (PyCFunction)GetDebugString, METH_NOARGS, },
{ "GetOptions", (PyCFunction)GetOptions, METH_NOARGS, },
{ "CopyToProto", (PyCFunction)CopyToProto, METH_O, },
{NULL}
Expand Down