Добавлены тесты для CoreEnum
This commit is contained in:
@@ -49,6 +49,24 @@ class CoreEnum(StrEnum):
|
||||
cls._check_is_empty()
|
||||
return [item.value for item in cls.__members__.values()]
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, value: str) -> CoreEnum:
|
||||
"""
|
||||
Возвращает перечисление по строковому значению
|
||||
|
||||
:param value: Строковое значение
|
||||
|
||||
:return: Перечисление
|
||||
"""
|
||||
|
||||
cls._check_is_empty()
|
||||
|
||||
for item in cls:
|
||||
if item.value == value:
|
||||
return item
|
||||
|
||||
raise ValueError(f"The {cls.__name__} enum does not contain the value '{value}'")
|
||||
|
||||
@classmethod
|
||||
def _check_is_empty(cls):
|
||||
"""
|
||||
@@ -61,19 +79,3 @@ class CoreEnum(StrEnum):
|
||||
if count == 0:
|
||||
raise ValueError(f"The {cls.__name__} enum must not be empty.")
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, value: str) -> CoreEnum:
|
||||
"""
|
||||
Возвращает перечисление по строковому значению
|
||||
|
||||
:param value: Строковое значение
|
||||
|
||||
:return: Перечисление
|
||||
"""
|
||||
|
||||
for item in cls:
|
||||
if item.value == value:
|
||||
return item
|
||||
|
||||
raise ValueError(f"The {cls.__name__} enum does not contain the value '{value}'")
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class CoreEnumFromStringTests(CoreSimpleTestCase):
|
||||
with self.assertRaises(ValueError) as context:
|
||||
TestEmptyEnum.from_string("any_value")
|
||||
|
||||
self.assertIn("enum does not contain the value 'any_value'", str(context.exception))
|
||||
self.assertIn("enum must not be empty", str(context.exception))
|
||||
|
||||
def test_from_string_works_with_single_member_enum(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user