summaryrefslogtreecommitdiffstats
path: root/tests/inputs/oneof_enum
diff options
context:
space:
mode:
Diffstat (limited to 'tests/inputs/oneof_enum')
-rw-r--r--tests/inputs/oneof_enum/oneof_enum-enum-0.json3
-rw-r--r--tests/inputs/oneof_enum/oneof_enum-enum-1.json3
-rw-r--r--tests/inputs/oneof_enum/oneof_enum.json6
-rw-r--r--tests/inputs/oneof_enum/oneof_enum.proto20
-rw-r--r--tests/inputs/oneof_enum/test_oneof_enum.py47
5 files changed, 79 insertions, 0 deletions
diff --git a/tests/inputs/oneof_enum/oneof_enum-enum-0.json b/tests/inputs/oneof_enum/oneof_enum-enum-0.json
new file mode 100644
index 0000000..be30cf0
--- /dev/null
+++ b/tests/inputs/oneof_enum/oneof_enum-enum-0.json
@@ -0,0 +1,3 @@
+{
+ "signal": "PASS"
+}
diff --git a/tests/inputs/oneof_enum/oneof_enum-enum-1.json b/tests/inputs/oneof_enum/oneof_enum-enum-1.json
new file mode 100644
index 0000000..cb63873
--- /dev/null
+++ b/tests/inputs/oneof_enum/oneof_enum-enum-1.json
@@ -0,0 +1,3 @@
+{
+ "signal": "RESIGN"
+}
diff --git a/tests/inputs/oneof_enum/oneof_enum.json b/tests/inputs/oneof_enum/oneof_enum.json
new file mode 100644
index 0000000..3220b70
--- /dev/null
+++ b/tests/inputs/oneof_enum/oneof_enum.json
@@ -0,0 +1,6 @@
+{
+ "move": {
+ "x": 2,
+ "y": 3
+ }
+}
diff --git a/tests/inputs/oneof_enum/oneof_enum.proto b/tests/inputs/oneof_enum/oneof_enum.proto
new file mode 100644
index 0000000..906abcb
--- /dev/null
+++ b/tests/inputs/oneof_enum/oneof_enum.proto
@@ -0,0 +1,20 @@
+syntax = "proto3";
+
+package oneof_enum;
+
+message Test {
+ oneof action {
+ Signal signal = 1;
+ Move move = 2;
+ }
+}
+
+enum Signal {
+ PASS = 0;
+ RESIGN = 1;
+}
+
+message Move {
+ int32 x = 1;
+ int32 y = 2;
+} \ No newline at end of file
diff --git a/tests/inputs/oneof_enum/test_oneof_enum.py b/tests/inputs/oneof_enum/test_oneof_enum.py
new file mode 100644
index 0000000..98de22a
--- /dev/null
+++ b/tests/inputs/oneof_enum/test_oneof_enum.py
@@ -0,0 +1,47 @@
+import pytest
+
+import aristaproto
+from tests.output_aristaproto.oneof_enum import (
+ Move,
+ Signal,
+ Test,
+)
+from tests.util import get_test_case_json_data
+
+
+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")[0].json
+ )
+
+ assert not hasattr(message, "move")
+ assert object.__getattribute__(message, "move") == aristaproto.PLACEHOLDER
+ assert message.signal == Signal.PASS
+ assert aristaproto.which_one_of(message, "action") == ("signal", Signal.PASS)
+
+
+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")[0].json
+ )
+ assert not hasattr(message, "move")
+ assert object.__getattribute__(message, "move") == aristaproto.PLACEHOLDER
+ assert message.signal == Signal.RESIGN
+ assert aristaproto.which_one_of(message, "action") == ("signal", Signal.RESIGN)
+
+
+def test_which_one_of_returns_second_field_when_set():
+ message = Test()
+ message.from_json(get_test_case_json_data("oneof_enum")[0].json)
+ assert message.move == Move(x=2, y=3)
+ assert not hasattr(message, "signal")
+ assert object.__getattribute__(message, "signal") == aristaproto.PLACEHOLDER
+ assert aristaproto.which_one_of(message, "action") == ("move", Move(x=2, y=3))