Adding upstream version 1.2+20240521.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
6b2864e4b9
commit
8512f66c5a
229 changed files with 19561 additions and 0 deletions
36
tests/test_struct.py
Normal file
36
tests/test_struct.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
import json
|
||||
|
||||
from aristaproto.lib.google.protobuf import Struct
|
||||
from aristaproto.lib.pydantic.google.protobuf import Struct as StructPydantic
|
||||
|
||||
|
||||
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
|
||||
|
||||
struct_pyd_from_dict = StructPydantic(fields={}).from_dict(data)
|
||||
assert struct_pyd_from_dict.fields == data
|
||||
assert struct_pyd_from_dict.to_dict() == data
|
||||
assert struct_pyd_from_dict.to_json() == data_json
|
||||
|
||||
struct_pyd_from_dict = StructPydantic(fields={}).from_json(data_json)
|
||||
assert struct_pyd_from_dict.fields == data
|
||||
assert struct_pyd_from_dict.to_dict() == data
|
||||
assert struct_pyd_from_dict == struct_pyd_from_dict
|
||||
assert struct_pyd_from_dict.to_json() == data_json
|
Loading…
Add table
Add a link
Reference in a new issue