-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14442 from haberman/23-cherrypick
Cherry-picked Python tests and updated upb dep
- Loading branch information
Showing
3 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
__author__ = '[email protected] (Matt Toia)' | ||
|
||
import unittest | ||
import gc | ||
|
||
from google.protobuf import descriptor_pb2 | ||
from google.protobuf.internal import api_implementation | ||
|
@@ -285,5 +286,29 @@ def FindFileByName(self, name): | |
self.assertEqual(345, m.Extensions[ext2].setting) | ||
|
||
|
||
def testOndemandCreateMetaClass(self): | ||
def loadFile(): | ||
f = descriptor_pb2.FileDescriptorProto.FromString( | ||
factory_test1_pb2.DESCRIPTOR.serialized_pb) | ||
return message_factory.GetMessages([f]) | ||
|
||
messages = loadFile() | ||
data = factory_test1_pb2.Factory1Message() | ||
data.map_field['hello'] = 'welcome' | ||
# Force GC to collect. UPB python will clean up the map entry class. | ||
# cpp extension and pure python will still keep the map entry class. | ||
gc.collect() | ||
message = messages['google.protobuf.python.internal.Factory1Message']() | ||
message.ParseFromString(data.SerializeToString()) | ||
value = message.map_field | ||
values = [ | ||
# The entry class will be created on demand in upb python. | ||
value.GetEntryClass()(key=k, value=value[k]) for k in sorted(value) | ||
] | ||
gc.collect() | ||
self.assertEqual(1, len(values)) | ||
self.assertEqual('hello', values[0].key) | ||
self.assertEqual('welcome', values[0].value) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |