File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ syntax = "proto3";
22
33package oneof ;
44
5+ message MixedDrink {
6+ int32 shots = 1 ;
7+ }
8+
59message Test {
610 oneof foo {
711 int32 pitied = 1 ;
@@ -13,6 +17,7 @@ message Test {
1317 oneof bar {
1418 int32 drinks = 11 ;
1519 string bar_name = 12 ;
20+ MixedDrink mixed_drink = 13 ;
1621 }
1722}
1823
Original file line number Diff line number Diff line change 1+ import pytest
2+
13import betterproto
2- from tests .output_betterproto .oneof import Test
4+ from tests .output_betterproto .oneof import (
5+ MixedDrink ,
6+ Test ,
7+ )
38from tests .output_betterproto_pydantic .oneof import Test as TestPyd
49from tests .util import get_test_case_json_data
510
@@ -19,3 +24,20 @@ def test_which_name():
1924def test_which_count_pyd ():
2025 message = TestPyd (pitier = "Mr. T" , just_a_regular_field = 2 , bar_name = "a_bar" )
2126 assert betterproto .which_one_of (message , "foo" ) == ("pitier" , "Mr. T" )
27+
28+
29+ def test_oneof_constructor_assign ():
30+ message = Test (mixed_drink = MixedDrink (shots = 42 ))
31+ field , value = betterproto .which_one_of (message , "bar" )
32+ assert field == "mixed_drink"
33+ assert value .shots == 42
34+
35+
36+ # Issue #305:
37+ @pytest .mark .xfail
38+ def test_oneof_nested_assign ():
39+ message = Test ()
40+ message .mixed_drink .shots = 42
41+ field , value = betterproto .which_one_of (message , "bar" )
42+ assert field == "mixed_drink"
43+ assert value .shots == 42
You can’t perform that action at this time.
0 commit comments