-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Add basic test for own internal Enum class
- Loading branch information
1 parent
1291040
commit 70cef3b
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |