From 61d192e2075680b03557276ed0bf980c97be4e0e Mon Sep 17 00:00:00 2001 From: Girts Date: Sun, 15 Oct 2023 20:18:24 -0700 Subject: [PATCH] test for issue #305, marked with xfail (#306) --- tests/inputs/oneof/oneof.proto | 5 +++++ tests/inputs/oneof/test_oneof.py | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/inputs/oneof/oneof.proto b/tests/inputs/oneof/oneof.proto index 21aa6c6..41f93b0 100644 --- a/tests/inputs/oneof/oneof.proto +++ b/tests/inputs/oneof/oneof.proto @@ -2,6 +2,10 @@ syntax = "proto3"; package oneof; +message MixedDrink { + int32 shots = 1; +} + message Test { oneof foo { int32 pitied = 1; @@ -13,6 +17,7 @@ message Test { oneof bar { int32 drinks = 11; string bar_name = 12; + MixedDrink mixed_drink = 13; } } diff --git a/tests/inputs/oneof/test_oneof.py b/tests/inputs/oneof/test_oneof.py index 92e8e77..b7d2d94 100644 --- a/tests/inputs/oneof/test_oneof.py +++ b/tests/inputs/oneof/test_oneof.py @@ -1,5 +1,10 @@ +import pytest + import betterproto -from tests.output_betterproto.oneof import Test +from tests.output_betterproto.oneof import ( + MixedDrink, + Test, +) from tests.output_betterproto_pydantic.oneof import Test as TestPyd from tests.util import get_test_case_json_data @@ -19,3 +24,20 @@ def test_which_name(): def test_which_count_pyd(): message = TestPyd(pitier="Mr. T", just_a_regular_field=2, bar_name="a_bar") assert betterproto.which_one_of(message, "foo") == ("pitier", "Mr. T") + + +def test_oneof_constructor_assign(): + message = Test(mixed_drink=MixedDrink(shots=42)) + field, value = betterproto.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 = betterproto.which_one_of(message, "bar") + assert field == "mixed_drink" + assert value.shots == 42