From cbecd9d2fa1d7187cca63a8c18838e87a4f613ec Mon Sep 17 00:00:00 2001 From: Tony Liao Date: Wed, 27 Nov 2024 16:10:58 -0800 Subject: [PATCH] Remove descriptor_test_wrapper for python's descriptor_test. 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: 700829382 --- .../protobuf/internal/descriptor_test.py | 18 +++++++-- python/pb_unit_tests/BUILD | 2 - .../pb_unit_tests/descriptor_test_wrapper.py | 39 ------------------- 3 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 python/pb_unit_tests/descriptor_test_wrapper.py diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index 134c36586a90..45810c945667 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -543,7 +543,8 @@ def testFileDescriptor(self): @unittest.skipIf( api_implementation.Type() == 'python', - 'Immutability of descriptors is only enforced in v2 implementation') + 'Immutability of descriptors is only enforced in c++ and upb backends', + ) def testImmutableCppDescriptor(self): file_descriptor = unittest_pb2.DESCRIPTOR message_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR @@ -568,8 +569,19 @@ def testImmutableCppDescriptor(self): enum_descriptor.has_options = False with self.assertRaises(AttributeError) as e: message_descriptor.has_options = True - self.assertEqual('attribute is not writable: has_options', - str(e.exception)) + + if api_implementation.Type() == 'cpp': + self.assertEqual( + 'attribute is not writable: has_options', str(e.exception) + ) + else: + self.assertEqual(api_implementation.Type(), 'upb') + self.assertEqual( + "attribute 'has_options' of " + "'google._upb._message.Descriptor' " + 'objects is not writable', + str(e.exception), + ) def testDefault(self): message_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index fb0e5413aca9..2f1453c3fb13 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -13,8 +13,6 @@ licenses(["notice"]) pyproto_test_wrapper(name = "descriptor_pool_test") -pyproto_test_wrapper(name = "descriptor_test") - pyproto_test_wrapper(name = "generator_test") pyproto_test_wrapper(name = "proto_builder_test") diff --git a/python/pb_unit_tests/descriptor_test_wrapper.py b/python/pb_unit_tests/descriptor_test_wrapper.py deleted file mode 100644 index 3b49caf16382..000000000000 --- a/python/pb_unit_tests/descriptor_test_wrapper.py +++ /dev/null @@ -1,39 +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.descriptor_test import * -import unittest - -# We pass this test, but the error message is slightly different. -# Our error message is better. -NewDescriptorTest.testImmutableCppDescriptor.__unittest_expecting_failure__ = True - -if __name__ == '__main__': - unittest.main(verbosity=2)