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";
2
2
3
3
package oneof ;
4
4
5
+ message MixedDrink {
6
+ int32 shots = 1 ;
7
+ }
8
+
5
9
message Test {
6
10
oneof foo {
7
11
int32 pitied = 1 ;
@@ -13,6 +17,7 @@ message Test {
13
17
oneof bar {
14
18
int32 drinks = 11 ;
15
19
string bar_name = 12 ;
20
+ MixedDrink mixed_drink = 13 ;
16
21
}
17
22
}
18
23
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
1
3
import betterproto
2
- from tests .output_betterproto .oneof import Test
4
+ from tests .output_betterproto .oneof import (
5
+ MixedDrink ,
6
+ Test ,
7
+ )
3
8
from tests .output_betterproto_pydantic .oneof import Test as TestPyd
4
9
from tests .util import get_test_case_json_data
5
10
@@ -19,3 +24,20 @@ def test_which_name():
19
24
def test_which_count_pyd ():
20
25
message = TestPyd (pitier = "Mr. T" , just_a_regular_field = 2 , bar_name = "a_bar" )
21
26
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