Skip to content

Commit

Permalink
Remove proto_builder_test_wrapper for python's proto_builder_test.
Browse files Browse the repository at this point in the history
The test wrappers were another way to document nonconformant behaviour between
different python backends. We can achieve the same by removing the wrapper
script and adding an if-condition in the test itself based on
api_implementation.Type(). Since we already do that for nonconformance between
pure Python vs. C++ backends, this change makes it easier to look for UPB
nonconformance instead of going through another layer of indirection.

PiperOrigin-RevId: 702723759
  • Loading branch information
tonyliaoss authored and copybara-github committed Dec 4, 2024
1 parent 8e78b9d commit 60d43aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
23 changes: 20 additions & 3 deletions python/google/protobuf/internal/proto_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from google.protobuf import descriptor_pool
from google.protobuf import proto_builder
from google.protobuf import text_format
from google.protobuf.internal import api_implementation


class ProtoBuilderTest(unittest.TestCase):
Expand Down Expand Up @@ -70,13 +71,29 @@ def testMakeLargeProtoClass(self):
'foo%d' % i: descriptor_pb2.FieldDescriptorProto.TYPE_INT64
for i in range(num_fields)
}
if api_implementation.Type() == 'upb':
with self.assertRaisesRegex(
TypeError, "Couldn't build proto file into descriptor pool"
):
proto_cls = proto_builder.MakeSimpleProtoClass(
fields,
full_name=(
'net.proto2.python.public.proto_builder_test.LargeProtoTest'
),
)
return

proto_cls = proto_builder.MakeSimpleProtoClass(
fields,
full_name='net.proto2.python.public.proto_builder_test.LargeProtoTest')
full_name='net.proto2.python.public.proto_builder_test.LargeProtoTest',
)

reserved_field_numbers = set(
range(descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER,
descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER + 1))
range(
descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER,
descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER + 1,
)
)
proto_field_numbers = set(proto_cls.DESCRIPTOR.fields_by_number)
self.assertFalse(reserved_field_numbers.intersection(proto_field_numbers))

Expand Down
2 changes: 0 additions & 2 deletions python/pb_unit_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ pyproto_test_wrapper(name = "descriptor_pool_test")

pyproto_test_wrapper(name = "generator_test")

pyproto_test_wrapper(name = "proto_builder_test")

pyproto_test_wrapper(name = "reflection_test")

filegroup(
Expand Down
37 changes: 0 additions & 37 deletions python/pb_unit_tests/proto_builder_test_wrapper.py

This file was deleted.

0 comments on commit 60d43aa

Please sign in to comment.