betterproto: support Struct
and Value
(#551)
* betterproto: support `Struct` and `Value` Signed-off-by: William Woodruff <william@trailofbits.com> * betterproto: handle struct in to_dict as well Signed-off-by: William Woodruff <william@trailofbits.com> * tests: add Struct roundtrip tests Signed-off-by: William Woodruff <william@trailofbits.com> * specialize from_dict and to_dict on Struct ...rather than special-casing in the Message ABC. Signed-off-by: William Woodruff <william@trailofbits.com> * betterproto: `poe format` Signed-off-by: William Woodruff <william@trailofbits.com> * Update src/betterproto/__init__.py Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com> * remove future annotations Signed-off-by: William Woodruff <william@trailofbits.com> * replace type[...] with typing.T Signed-off-by: William Woodruff <william@trailofbits.com> * quote instead Signed-off-by: William Woodruff <william@trailofbits.com> --------- Signed-off-by: William Woodruff <william@trailofbits.com> Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
This commit is contained in:
24
tests/test_struct.py
Normal file
24
tests/test_struct.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import json
|
||||
|
||||
from betterproto.lib.google.protobuf import Struct
|
||||
|
||||
|
||||
def test_struct_roundtrip():
|
||||
data = {
|
||||
"foo": "bar",
|
||||
"baz": None,
|
||||
"quux": 123,
|
||||
"zap": [1, {"two": 3}, "four"],
|
||||
}
|
||||
data_json = json.dumps(data)
|
||||
|
||||
struct_from_dict = Struct().from_dict(data)
|
||||
assert struct_from_dict.fields == data
|
||||
assert struct_from_dict.to_dict() == data
|
||||
assert struct_from_dict.to_json() == data_json
|
||||
|
||||
struct_from_json = Struct().from_json(data_json)
|
||||
assert struct_from_json.fields == data
|
||||
assert struct_from_json.to_dict() == data
|
||||
assert struct_from_json == struct_from_dict
|
||||
assert struct_from_json.to_json() == data_json
|
Reference in New Issue
Block a user