File: test__constants.py

package info (click to toggle)
anta 1.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,048 kB
  • sloc: python: 48,164; sh: 28; javascript: 9; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 1,568 bytes parent folder | download | duplicates (2)
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
# Copyright (c) 2023-2025 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Unit tests for the asynceapi._constants module."""

import pytest

from asynceapi._constants import EapiCommandFormat


class TestEapiCommandFormat:
    """Test cases for the EapiCommandFormat enum."""

    def test_enum_values(self) -> None:
        """Test that the enum has the expected values."""
        assert EapiCommandFormat.JSON.value == "json"
        assert EapiCommandFormat.TEXT.value == "text"

    def test_str_method(self) -> None:
        """Test that the __str__ method returns the string value."""
        assert str(EapiCommandFormat.JSON) == "json"
        assert str(EapiCommandFormat.TEXT) == "text"

        # Test in string formatting
        assert f"Format: {EapiCommandFormat.JSON}" == "Format: json"

    def test_string_behavior(self) -> None:
        """Test that the enum behaves like a string."""
        # String methods should work
        assert EapiCommandFormat.JSON.upper() == "JSON"

        # String comparisons should work
        assert EapiCommandFormat.JSON == "json"
        assert EapiCommandFormat.TEXT == "text"

    def test_enum_lookup(self) -> None:
        """Test enum lookup by value."""
        assert EapiCommandFormat("json") is EapiCommandFormat.JSON
        assert EapiCommandFormat("text") is EapiCommandFormat.TEXT

        with pytest.raises(ValueError, match="'invalid' is not a valid EapiCommandFormat"):
            EapiCommandFormat("invalid")