forked from danielgtaylor/python-betterproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test case for issue danielgtaylor#63
- Loading branch information
1 parent
659ddd9
commit 71737cf
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"signal": "PASS" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"signal": "RESIGN" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"move": { | ||
"x": 2, | ||
"y": 3 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
|
||
message Test { | ||
oneof action { | ||
Signal signal = 1; | ||
Move move = 2; | ||
} | ||
} | ||
|
||
enum Signal { | ||
PASS = 0; | ||
RESIGN = 1; | ||
} | ||
|
||
message Move { | ||
int32 x = 1; | ||
int32 y = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
|
||
import betterproto | ||
from betterproto.tests.output_betterproto.oneof_enum.oneof_enum import ( | ||
Move, | ||
Signal, | ||
Test, | ||
) | ||
from betterproto.tests.util import get_test_case_json_data | ||
|
||
|
||
@pytest.mark.xfail | ||
def test_which_one_of_returns_enum_with_default_value(): | ||
""" | ||
returns first field when it is enum and set with default value | ||
""" | ||
message = Test() | ||
message.from_json(get_test_case_json_data("oneof_enum", "oneof_enum-enum-0.json")) | ||
assert message.move is None | ||
assert message.signal == Signal.PASS | ||
assert betterproto.which_one_of(message, "action") == ("signal", Signal.PASS) | ||
|
||
|
||
@pytest.mark.xfail | ||
def test_which_one_of_returns_enum_with_non_default_value(): | ||
""" | ||
returns first field when it is enum and set with non default value | ||
""" | ||
message = Test() | ||
message.from_json(get_test_case_json_data("oneof_enum", "oneof_enum-enum-1.json")) | ||
assert message.move is None | ||
assert message.signal == Signal.PASS | ||
assert betterproto.which_one_of(message, "action") == ("signal", Signal.RESIGN) | ||
|
||
|
||
@pytest.mark.xfail | ||
def test_which_one_of_returns_second_field_when_set(): | ||
message = Test() | ||
message.from_json(get_test_case_json_data("oneof_enum")) | ||
assert message.move == Move(x=2, y=3) | ||
assert message.signal == 0 | ||
assert betterproto.which_one_of(message, "action") == ("move", Move(x=2, y=3)) |