fix: support pydantic-version google pb (#568)

* feat: pydantic version of google pb

* fix: patch pb Struct to support json, dict rountrip

* fix: pydantic-version google pb, json, dict rntrip

* chore: remove `@generated`, remove gen, code fmt

* chore: test case for pydantic-version google pb
This commit is contained in:
Maple
2024-04-09 05:54:36 +07:00
committed by GitHub
parent df1ba911b7
commit c3c20556e0
16 changed files with 5606 additions and 1869 deletions

View File

@@ -1,6 +1,7 @@
import json
from betterproto.lib.google.protobuf import Struct
from betterproto.lib.pydantic.google.protobuf import Struct as StructPydantic
def test_struct_roundtrip():
@@ -22,3 +23,14 @@ def test_struct_roundtrip():
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