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
3
tests/inputs/oneof/oneof-name.json
Normal file
3
tests/inputs/oneof/oneof-name.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"pitier": "Mr. T"
|
||||
}
|
3
tests/inputs/oneof/oneof.json
Normal file
3
tests/inputs/oneof/oneof.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"pitied": 100
|
||||
}
|
23
tests/inputs/oneof/oneof.proto
Normal file
23
tests/inputs/oneof/oneof.proto
Normal file
|
@ -0,0 +1,23 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package oneof;
|
||||
|
||||
message MixedDrink {
|
||||
int32 shots = 1;
|
||||
}
|
||||
|
||||
message Test {
|
||||
oneof foo {
|
||||
int32 pitied = 1;
|
||||
string pitier = 2;
|
||||
}
|
||||
|
||||
int32 just_a_regular_field = 3;
|
||||
|
||||
oneof bar {
|
||||
int32 drinks = 11;
|
||||
string bar_name = 12;
|
||||
MixedDrink mixed_drink = 13;
|
||||
}
|
||||
}
|
||||
|
3
tests/inputs/oneof/oneof_name.json
Normal file
3
tests/inputs/oneof/oneof_name.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"pitier": "Mr. T"
|
||||
}
|
43
tests/inputs/oneof/test_oneof.py
Normal file
43
tests/inputs/oneof/test_oneof.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
import pytest
|
||||
|
||||
import aristaproto
|
||||
from tests.output_aristaproto.oneof import (
|
||||
MixedDrink,
|
||||
Test,
|
||||
)
|
||||
from tests.output_aristaproto_pydantic.oneof import Test as TestPyd
|
||||
from tests.util import get_test_case_json_data
|
||||
|
||||
|
||||
def test_which_count():
|
||||
message = Test()
|
||||
message.from_json(get_test_case_json_data("oneof")[0].json)
|
||||
assert aristaproto.which_one_of(message, "foo") == ("pitied", 100)
|
||||
|
||||
|
||||
def test_which_name():
|
||||
message = Test()
|
||||
message.from_json(get_test_case_json_data("oneof", "oneof_name.json")[0].json)
|
||||
assert aristaproto.which_one_of(message, "foo") == ("pitier", "Mr. T")
|
||||
|
||||
|
||||
def test_which_count_pyd():
|
||||
message = TestPyd(pitier="Mr. T", just_a_regular_field=2, bar_name="a_bar")
|
||||
assert aristaproto.which_one_of(message, "foo") == ("pitier", "Mr. T")
|
||||
|
||||
|
||||
def test_oneof_constructor_assign():
|
||||
message = Test(mixed_drink=MixedDrink(shots=42))
|
||||
field, value = aristaproto.which_one_of(message, "bar")
|
||||
assert field == "mixed_drink"
|
||||
assert value.shots == 42
|
||||
|
||||
|
||||
# Issue #305:
|
||||
@pytest.mark.xfail
|
||||
def test_oneof_nested_assign():
|
||||
message = Test()
|
||||
message.mixed_drink.shots = 42
|
||||
field, value = aristaproto.which_one_of(message, "bar")
|
||||
assert field == "mixed_drink"
|
||||
assert value.shots == 42
|
Loading…
Add table
Add a link
Reference in a new issue