-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added binary support in dictionaries via base64 encoding
- Loading branch information
Dominik Andreas
committed
Jan 22, 2024
1 parent
1fb1687
commit f46d6b6
Showing
2 changed files
with
50 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
import capnp | ||
import base64 | ||
import pytest | ||
|
||
this_dir = os.path.dirname(__file__) | ||
|
||
|
||
@pytest.fixture | ||
def blob_schema(): | ||
return capnp.load(os.path.join(this_dir, "blob_test.capnp")) | ||
|
||
|
||
def test_blob_to_dict(blob_schema): | ||
blob_value = b"hello world" | ||
blob = blob_schema.BlobTest(blob=blob_value) | ||
blob_dict = blob.to_dict(encode_bytes_as_base64=True) | ||
assert base64.b64decode(blob_dict["blob"]) == blob_value | ||
msg = blob_schema.BlobTest.new_message() | ||
msg.from_dict(blob_dict) | ||
assert blob.blob == blob_value |