diff --git a/python/google/protobuf/internal/proto_builder_test.py b/python/google/protobuf/internal/proto_builder_test.py index fcb4a027269ef..a594eec8a0600 100644 --- a/python/google/protobuf/internal/proto_builder_test.py +++ b/python/google/protobuf/internal/proto_builder_test.py @@ -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): @@ -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)) diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index 2f1453c3fb13e..77d74a186a748 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -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( diff --git a/python/pb_unit_tests/proto_builder_test_wrapper.py b/python/pb_unit_tests/proto_builder_test_wrapper.py deleted file mode 100644 index 468d13e66251c..0000000000000 --- a/python/pb_unit_tests/proto_builder_test_wrapper.py +++ /dev/null @@ -1,37 +0,0 @@ -# Protocol Buffers - Google's data interchange format -# Copyright 2023 Google LLC. All rights reserved. -# https://developers.google.com/protocol-buffers/ -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google LLC nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -from google.protobuf.internal.proto_builder_test import * -import unittest - -ProtoBuilderTest.testMakeLargeProtoClass.__unittest_expecting_failure__ = True - -if __name__ == '__main__': - unittest.main(verbosity=2)