8000 test for issue #305, marked with xfail (#306) · mgorny/python-betterproto@61d192e · GitHub
[go: up one dir, main page]

Skip to content

Commit 61d192e

Browse files
authored
test for issue danielgtaylor#305, marked with xfail (danielgtaylor#306)
1 parent 8b5dd6c commit 61d192e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tests/inputs/oneof/oneof.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ syntax = "proto3";
22

33
package oneof;
44

5+
message MixedDrink {
6+
int32 shots = 1;
7+
}
8+
59
message 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

tests/inputs/oneof/test_oneof.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import pytest
2+
13
import betterproto
2-
from tests.output_betterproto.oneof import Test
4+
from tests.output_betterproto.oneof import (
5+
MixedDrink,
6+
Test,
7+
)
38
from tests.output_betterproto_pydantic.oneof import Test as TestPyd
49
from tests.util import get_test_case_json_data
510

@@ -19,3 +24,20 @@ def test_which_name():
1924
def 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

0 commit comments

Comments
 (0)
0