diff --git a/net/xeaf/rack/core/core_enum.py b/net/xeaf/rack/core/core_enum.py index 1498ba7..39187ae 100644 --- a/net/xeaf/rack/core/core_enum.py +++ b/net/xeaf/rack/core/core_enum.py @@ -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}'") - diff --git a/net/xeaf/rack/tests/core/core_enum_from_string_tests.py b/net/xeaf/rack/tests/core/core_enum_from_string_tests.py index ea44de0..2fc32f2 100644 --- a/net/xeaf/rack/tests/core/core_enum_from_string_tests.py +++ b/net/xeaf/rack/tests/core/core_enum_from_string_tests.py @@ -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): """