File: test_oneof_enum.py

package info (click to toggle)
python-aristaproto 1.2%2B20240521-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,484 kB
  • sloc: python: 5,915; java: 106; xml: 84; makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,601 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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))