1
0
Fork 0

Adding upstream version 1.2+20240521.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-05 14:24:15 +01:00
parent 6b2864e4b9
commit 8512f66c5a
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
229 changed files with 19561 additions and 0 deletions

View file

@ -0,0 +1,13 @@
{
"test1": 128,
"test2": true,
"test3": "A value",
"test4": "aGVsbG8=",
"test5": {
"test": "Hello"
},
"test6": "B",
"test7": "8589934592",
"test8": 2.5,
"test9": "2022-01-24T12:12:42Z"
}

View file

@ -0,0 +1,26 @@
syntax = "proto3";
package proto3_field_presence;
import "google/protobuf/timestamp.proto";
message InnerTest {
string test = 1;
}
message Test {
optional uint32 test1 = 1;
optional bool test2 = 2;
optional string test3 = 3;
optional bytes test4 = 4;
optional InnerTest test5 = 5;
optional TestEnum test6 = 6;
optional uint64 test7 = 7;
optional float test8 = 8;
optional google.protobuf.Timestamp test9 = 9;
}
enum TestEnum {
A = 0;
B = 1;
}

View file

@ -0,0 +1,9 @@
{
"test1": 0,
"test2": false,
"test3": "",
"test4": "",
"test6": "A",
"test7": "0",
"test8": 0
}

View file

@ -0,0 +1,48 @@
import json
from tests.output_aristaproto.proto3_field_presence import (
InnerTest,
Test,
TestEnum,
)
def test_null_fields_json():
"""Ensure that using "null" in JSON is equivalent to not specifying a
field, for fields with explicit presence"""
def test_json(ref_json: str, obj_json: str) -> None:
"""`ref_json` and `obj_json` are JSON strings describing a `Test` object.
Test that deserializing both leads to the same object, and that
`ref_json` is the normalized format."""
ref_obj = Test().from_json(ref_json)
obj = Test().from_json(obj_json)
assert obj == ref_obj
assert json.loads(obj.to_json(0)) == json.loads(ref_json)
test_json("{}", '{ "test1": null, "test2": null, "test3": null }')
test_json("{}", '{ "test4": null, "test5": null, "test6": null }')
test_json("{}", '{ "test7": null, "test8": null }')
test_json('{ "test5": {} }', '{ "test3": null, "test5": {} }')
# Make sure that if include_default_values is set, None values are
# exported.
obj = Test()
assert obj.to_dict() == {}
assert obj.to_dict(include_default_values=True) == {
"test1": None,
"test2": None,
"test3": None,
"test4": None,
"test5": None,
"test6": None,
"test7": None,
"test8": None,
"test9": None,
}
def test_unset_access(): # see #523
assert Test().test1 is None
assert Test(test1=None).test1 is None