diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 5604ffd050e04..6d7a4d9cfc286 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -353,7 +353,12 @@ def testExtremeDoubleValues(self, message_module): def testFloatPrinting(self, message_module): message = message_module.TestAllTypes() message.optional_float = 2.0 - self.assertEqual(str(message), 'optional_float: 2.0\n') + # Python/C++ customizes the C++ TextFormat to always print trailing ".0" for + # floats. upb doesn't do this, it matches C++ TextFormat. + if api_implementation.Type() == 'upb': + self.assertEqual(str(message), 'optional_float: 2\n') + else: + self.assertEqual(str(message), 'optional_float: 2.0\n') def testFloatNanPrinting(self, message_module): message = message_module.TestAllTypes() @@ -1662,7 +1667,8 @@ def test_documentation(self): doc = pydoc.html.document(unittest_pb2.TestAllTypes, 'message') self.assertIn('class TestAllTypes', doc) self.assertIn('SerializePartialToString', doc) - self.assertIn('repeated_float', doc) + if api_implementation.Type() != 'upb': + self.assertIn('repeated_float', doc) base = unittest_pb2.TestAllTypes.__bases__[0] self.assertRaises(AttributeError, getattr, base, '_extensions_by_name') @@ -2258,15 +2264,17 @@ def testMergeFromBadType(self): with self.assertRaisesRegex( TypeError, r'Parameter to MergeFrom\(\) must be instance of same class: expected ' - r'.+TestMap got int\.'): + r'.+TestMap.+got.+int.+', + ): msg.MergeFrom(1) def testCopyFromBadType(self): msg = map_unittest_pb2.TestMap() with self.assertRaisesRegex( TypeError, - r'Parameter to [A-Za-z]*From\(\) must be instance of same class: ' - r'expected .+TestMap got int\.'): + r'Parameter to (Copy|Merge)From\(\) must be instance of same class: ' + r'expected .+TestMap.+got.+int.+', + ): msg.CopyFrom(1) def testIntegerMapWithLongs(self): diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index 38905afc8751a..01330b405c7a9 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -21,8 +21,6 @@ pyproto_test_wrapper(name = "message_factory_test") pyproto_test_wrapper(name = "proto_builder_test") -pyproto_test_wrapper(name = "message_test") - pyproto_test_wrapper(name = "reflection_test") filegroup( diff --git a/python/pb_unit_tests/message_test_wrapper.py b/python/pb_unit_tests/message_test_wrapper.py deleted file mode 100644 index 78f35853ab3a6..0000000000000 --- a/python/pb_unit_tests/message_test_wrapper.py +++ /dev/null @@ -1,48 +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.message_test import * -import unittest - -# Python/C++ customizes the C++ TextFormat to always print trailing ".0" for -# floats. upb doesn't do this, it matches C++ TextFormat. -MessageTest.testFloatPrinting_proto2.__unittest_expecting_failure__ = True -MessageTest.testFloatPrinting_proto3.__unittest_expecting_failure__ = True - -# For these tests we are throwing the correct error, only the text of the error -# message is a mismatch. For technical reasons around the limited API, matching -# the existing error message exactly is not feasible. -Proto3Test.testCopyFromBadType.__unittest_expecting_failure__ = True -Proto3Test.testMergeFromBadType.__unittest_expecting_failure__ = True - -Proto2Test.test_documentation.__unittest_expecting_failure__ = True - -if __name__ == '__main__': - unittest.main(verbosity=2)