Skip to content

Commit

Permalink
Add: Add basic test for own internal Enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks authored and greenbonebot committed Jun 14, 2024
1 parent 1291040 commit 70cef3b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest

from gvm._enum import Enum
from gvm.errors import InvalidArgument


class SomeEnum(Enum):
FOO = "foo"
BAR = "bar"


class SomeClass:
def __str__(self) -> str:
return "foo"


class EnumTestCase(unittest.TestCase):
def test_enum(self) -> None:
enum = SomeEnum("FOO")
self.assertEqual(enum, SomeEnum.FOO)
enum = SomeEnum("BAR")
self.assertEqual(enum, SomeEnum.BAR)

enum = SomeEnum("foo")
self.assertEqual(enum, SomeEnum.FOO)
enum = SomeEnum("bar")
self.assertEqual(enum, SomeEnum.BAR)

enum = SomeEnum(SomeClass())
self.assertEqual(enum, SomeEnum.FOO)

def test_invalid(self) -> None:
with self.assertRaisesRegex(
InvalidArgument,
"^Invalid argument BAZ. Allowed values are FOO,BAR.$",
):
SomeEnum("BAZ")

def test_from_string(self) -> None:
enum = SomeEnum.from_string("FOO")
self.assertEqual(enum, SomeEnum.FOO)
enum = SomeEnum.from_string("BAR")
self.assertEqual(enum, SomeEnum.BAR)

enum = SomeEnum.from_string("foo")
self.assertEqual(enum, SomeEnum.FOO)
enum = SomeEnum.from_string("bar")
self.assertEqual(enum, SomeEnum.BAR)

0 comments on commit 70cef3b

Please sign in to comment.