33 """Tests for google.protobuf.proto_builder."""
36 from collections
import OrderedDict
38 from ordereddict
import OrderedDict
40 import unittest2
as unittest
54 (
'foo', descriptor_pb2.FieldDescriptorProto.TYPE_INT64),
55 (
'bar', descriptor_pb2.FieldDescriptorProto.TYPE_STRING),
60 """Test that we can create a proto class."""
61 proto_cls = proto_builder.MakeSimpleProtoClass(
63 full_name=
'net.proto2.python.public.proto_builder_test.Test')
67 self.assertMultiLineEqual(
68 'bar: "asdf"\nfoo: 12345\n', text_format.MessageToString(proto))
71 """Test that the field order is maintained when given an OrderedDict."""
72 proto_cls = proto_builder.MakeSimpleProtoClass(
74 full_name=
'net.proto2.python.public.proto_builder_test.OrderedTest')
78 self.assertMultiLineEqual(
79 'foo: 12345\nbar: "asdf"\n', text_format.MessageToString(proto))
82 """Test that the DescriptorPool is used."""
84 proto_cls1 = proto_builder.MakeSimpleProtoClass(
86 full_name=
'net.proto2.python.public.proto_builder_test.Test',
88 proto_cls2 = proto_builder.MakeSimpleProtoClass(
90 full_name=
'net.proto2.python.public.proto_builder_test.Test',
92 self.assertIs(proto_cls1.DESCRIPTOR, proto_cls2.DESCRIPTOR)
95 if __name__ ==
'__main__':