-
Notifications
You must be signed in to change notification settings - Fork 47
MsgpackSerializer.loadsCall: honor ext_hook (symmetric with loads) #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5045ce
Update serializers.py. Added ext_hook to loadsCall in MsgpackSerializ…
daqiii 8526e4d
Create test_msgpack_ext_hook_loadsCall.py
daqiii 089d7af
Move the loadsCall ext_hook regression tests into test_serialize.py
daqiii 3d6154f
Remove the standalone test file (moved into test_serialize.py)
daqiii 4ebec4d
Address round 2 review: remove redundant msgpack import, fix indent
daqiii 03bf0f5
updates to incorrect indents
daqiii 36edd6d
Add files via upload
daqiii ef24828
Address round 2 review: remove redundant msgpack import, fix indent, …
daqiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """ | ||
| Regression test: MsgpackSerializer.loadsCall must honor ext_hook so that | ||
| ExtType-encoded call arguments round-trip when a subclass overrides | ||
| ext_hook to handle custom codes. The sibling loads() has always passed | ||
| both hooks; loadsCall used to pass only object_hook. | ||
| """ | ||
| import unittest | ||
|
|
||
| import msgpack | ||
|
|
||
| import Pyro5.serializers as serializers | ||
|
|
||
|
|
||
| CUSTOM_EXT_CODE = 0x40 | ||
|
|
||
|
|
||
| class Thing: | ||
| def __init__(self, value): | ||
| self.value = value | ||
|
|
||
|
|
||
| class CustomMsgpackSerializer(serializers.MsgpackSerializer): | ||
| def default(self, obj): | ||
| if isinstance(obj, Thing): | ||
| return msgpack.ExtType(CUSTOM_EXT_CODE, str(obj.value).encode("ascii")) | ||
| return super().default(obj) | ||
|
|
||
| def ext_hook(self, code, data): | ||
| if code == CUSTOM_EXT_CODE: | ||
| return Thing(int(data)) | ||
| return super().ext_hook(code, data) | ||
|
|
||
|
|
||
| class TestMsgpackExtHookLoadsCall(unittest.TestCase): | ||
| def test_loadsCall_honors_ext_hook(self): | ||
| """ | ||
| Pack a call message whose first vararg is a custom-ExtType-encoded | ||
| object and verify loadsCall reconstructs it via the subclass's | ||
| ext_hook. Before the fix this returned msgpack.ExtType, not Thing. | ||
| """ | ||
| ser = CustomMsgpackSerializer() | ||
| data = ser.dumpsCall("obj-id", "method-name", (Thing(42),), {}) | ||
| obj, method, vargs, kwargs = ser.loadsCall(data) | ||
| self.assertEqual(obj, "obj-id") | ||
| self.assertEqual(method, "method-name") | ||
| self.assertIsInstance(vargs[0], Thing) | ||
| self.assertEqual(vargs[0].value, 42) | ||
| self.assertEqual(kwargs, {}) | ||
|
|
||
| def test_loads_already_honors_ext_hook(self): | ||
| """ | ||
| Symmetric sanity check on the working sibling path. Would have | ||
| passed before the fix too; included so future regressions on | ||
| either method surface symmetrically. | ||
| """ | ||
| ser = CustomMsgpackSerializer() | ||
| data = ser.dumps(Thing(7)) | ||
| back = ser.loads(data) | ||
| self.assertIsInstance(back, Thing) | ||
| self.assertEqual(back.value, 7) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please integrate these tests in test_serialize.py ? Instead of introducing a new file for just these two.