summaryrefslogtreecommitdiffstats
path: root/tests/inputs/oneof
diff options
context:
space:
mode:
Diffstat (limited to 'tests/inputs/oneof')
-rw-r--r--tests/inputs/oneof/oneof-name.json3
-rw-r--r--tests/inputs/oneof/oneof.json3
-rw-r--r--tests/inputs/oneof/oneof.proto23
-rw-r--r--tests/inputs/oneof/oneof_name.json3
-rw-r--r--tests/inputs/oneof/test_oneof.py43
5 files changed, 75 insertions, 0 deletions
diff --git a/tests/inputs/oneof/oneof-name.json b/tests/inputs/oneof/oneof-name.json
new file mode 100644
index 0000000..605484b
--- /dev/null
+++ b/tests/inputs/oneof/oneof-name.json
@@ -0,0 +1,3 @@
+{
+ "pitier": "Mr. T"
+}
diff --git a/tests/inputs/oneof/oneof.json b/tests/inputs/oneof/oneof.json
new file mode 100644
index 0000000..65cafc5
--- /dev/null
+++ b/tests/inputs/oneof/oneof.json
@@ -0,0 +1,3 @@
+{
+ "pitied": 100
+}
diff --git a/tests/inputs/oneof/oneof.proto b/tests/inputs/oneof/oneof.proto
new file mode 100644
index 0000000..41f93b0
--- /dev/null
+++ b/tests/inputs/oneof/oneof.proto
@@ -0,0 +1,23 @@
+syntax = "proto3";
+
+package oneof;
+
+message MixedDrink {
+ int32 shots = 1;
+}
+
+message Test {
+ oneof foo {
+ int32 pitied = 1;
+ string pitier = 2;
+ }
+
+ int32 just_a_regular_field = 3;
+
+ oneof bar {
+ int32 drinks = 11;
+ string bar_name = 12;
+ MixedDrink mixed_drink = 13;
+ }
+}
+
diff --git a/tests/inputs/oneof/oneof_name.json b/tests/inputs/oneof/oneof_name.json
new file mode 100644
index 0000000..605484b
--- /dev/null
+++ b/tests/inputs/oneof/oneof_name.json
@@ -0,0 +1,3 @@
+{
+ "pitier": "Mr. T"
+}
diff --git a/tests/inputs/oneof/test_oneof.py b/tests/inputs/oneof/test_oneof.py
new file mode 100644
index 0000000..8a38496
--- /dev/null
+++ b/tests/inputs/oneof/test_oneof.py
@@ -0,0 +1,43 @@
+import pytest
+
+import aristaproto
+from tests.output_aristaproto.oneof import (
+ MixedDrink,
+ Test,
+)
+from tests.output_aristaproto_pydantic.oneof import Test as TestPyd
+from tests.util import get_test_case_json_data
+
+
+def test_which_count():
+ message = Test()
+ message.from_json(get_test_case_json_data("oneof")[0].json)
+ assert aristaproto.which_one_of(message, "foo") == ("pitied", 100)
+
+
+def test_which_name():
+ message = Test()
+ message.from_json(get_test_case_json_data("oneof", "oneof_name.json")[0].json)
+ assert aristaproto.which_one_of(message, "foo") == ("pitier", "Mr. T")
+
+
+def test_which_count_pyd():
+ message = TestPyd(pitier="Mr. T", just_a_regular_field=2, bar_name="a_bar")
+ assert aristaproto.which_one_of(message, "foo") == ("pitier", "Mr. T")
+
+
+def test_oneof_constructor_assign():
+ message = Test(mixed_drink=MixedDrink(shots=42))
+ field, value = aristaproto.which_one_of(message, "bar")
+ assert field == "mixed_drink"
+ assert value.shots == 42
+
+
+# Issue #305:
+@pytest.mark.xfail
+def test_oneof_nested_assign():
+ message = Test()
+ message.mixed_drink.shots = 42
+ field, value = aristaproto.which_one_of(message, "bar")
+ assert field == "mixed_drink"
+ assert value.shots == 42