File: test_enum.py

package info (click to toggle)
pontos 25.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,744 kB
  • sloc: python: 44,602; makefile: 21; sh: 10; xml: 3
file content (37 lines) | stat: -rw-r--r-- 924 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
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later


import unittest
from argparse import ArgumentTypeError

from pontos.enum import StrEnum, enum_type


class EnumTypeTestCase(unittest.TestCase):
    def test_enum_type(self):
        class FooEnum(StrEnum):
            ALL = "all"
            NONE = "none"

        func = enum_type(FooEnum)

        self.assertEqual(func("all"), FooEnum.ALL)
        self.assertEqual(func("none"), FooEnum.NONE)

        self.assertEqual(func(FooEnum.ALL), FooEnum.ALL)
        self.assertEqual(func(FooEnum.NONE), FooEnum.NONE)

    def test_enum_type_error(self):
        class FooEnum(StrEnum):
            ALL = "all"
            NONE = "none"

        func = enum_type(FooEnum)

        with self.assertRaisesRegex(
            ArgumentTypeError,
            r"invalid value foo. Expected one of all, none",
        ):
            func("foo")