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.
…nielgtaylor#510) # Conflicts: # poetry.lock # src/betterproto/__init__.py # src/betterproto/plugin/parser.py # Conflicts: # poetry.lock # pyproject.toml
- Loading branch information
1 parent
17c1ba3
commit f0af6b6
Showing
10 changed files
with
144 additions
and
31 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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,46 @@ | ||
from dataclasses import dataclass | ||
|
||
import pytest | ||
|
||
import betterproto | ||
|
||
|
||
def test_oneof_pattern_matching(): | ||
@dataclass | ||
class Sub(betterproto.Message): | ||
val: int = betterproto.int32_field(1) | ||
|
||
@dataclass | ||
class Foo(betterproto.Message): | ||
bar: int = betterproto.int32_field(1, group="group1") | ||
baz: str = betterproto.string_field(2, group="group1") | ||
sub: Sub = betterproto.message_field(3, group="group2") | ||
abc: str = betterproto.string_field(4, group="group2") | ||
|
||
foo = Foo(baz="test1", abc="test2") | ||
|
||
match foo: | ||
case Foo(bar=_): | ||
pytest.fail("Matched 'bar' instead of 'baz'") | ||
case Foo(baz=v): | ||
assert v == "test1" | ||
case _: | ||
pytest.fail("Matched neither 'bar' nor 'baz'") | ||
|
||
match foo: | ||
case Foo(sub=_): | ||
pytest.fail("Matched 'sub' instead of 'abc'") | ||
case Foo(abc=v): | ||
assert v == "test2" | ||
case _: | ||
pytest.fail("Matched neither 'sub' nor 'abc'") | ||
|
||
foo.sub = Sub(val=1) | ||
|
||
match foo: | ||
case Foo(sub=Sub(val=v)): | ||
assert v == 1 | ||
case Foo(abc=v): | ||
pytest.fail("Matched 'abc' instead of 'sub'") | ||
case _: | ||
pytest.fail("Matched neither 'sub' nor 'abc'") |
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