Skip to content

Commit

Permalink
Remove message_factory_test_wrapper for python's message_factory_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: 700127942
  • Loading branch information
tonyliaoss authored and copybara-github committed Nov 26, 2024
1 parent 2ad21af commit 1544885
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
37 changes: 26 additions & 11 deletions python/google/protobuf/internal/message_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,34 @@ def testDuplicateExtensionNumber(self):
type_name='Duplicate',
extendee='Container',
)
pool.Add(f)
if api_implementation.Type() == 'upb':
with self.assertRaisesRegex(
TypeError,
# TODO - b/380939902: Figure out why this fails with an OOM message.
"Couldn't build proto file into descriptor pool: out of memory",
):
pool.Add(f)
else:
pool.Add(f)

with self.assertRaises(Exception) as cm:
message_factory.GetMessageClassesForFiles([f.name], pool)
with self.assertRaises(Exception) as cm:
message_factory.GetMessageClassesForFiles([f.name], pool)

self.assertIn(str(cm.exception),
['Extensions '
'"google.protobuf.python.internal.Duplicate.extension_field" and'
' "google.protobuf.python.internal.Extension.extension_field"'
' both try to extend message type'
' "google.protobuf.python.internal.Container"'
' with field number 2.',
'Double registration of Extensions'])
self.assertIn(
str(cm.exception),
[
(
'Extensions'
' "google.protobuf.python.internal.Duplicate.extension_field"'
' and'
' "google.protobuf.python.internal.Extension.extension_field"'
' both try to extend message type'
' "google.protobuf.python.internal.Container" with field'
' number 2.'
),
'Double registration of Extensions',
],
)

def testExtensionValueInDifferentFile(self):
# Add Container message.
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 @@ -17,8 +17,6 @@ pyproto_test_wrapper(name = "descriptor_test")

pyproto_test_wrapper(name = "generator_test")

pyproto_test_wrapper(name = "message_factory_test")

pyproto_test_wrapper(name = "proto_builder_test")

pyproto_test_wrapper(name = "reflection_test")
Expand Down
37 changes: 0 additions & 37 deletions python/pb_unit_tests/message_factory_test_wrapper.py

This file was deleted.

0 comments on commit 1544885

Please sign in to comment.