Skip to content

Commit

Permalink
Remove message_test_wrapper for python's message_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: 699321395
  • Loading branch information
tonyliaoss authored and copybara-github committed Nov 23, 2024
1 parent b9e69e8 commit a02ec0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 55 deletions.
18 changes: 13 additions & 5 deletions python/google/protobuf/internal/message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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):
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 @@ -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(
Expand Down
48 changes: 0 additions & 48 deletions python/pb_unit_tests/message_test_wrapper.py

This file was deleted.

0 comments on commit a02ec0f

Please sign in to comment.