From b923cac0329c8b3176d913be51f2b7194a6c0d7e Mon Sep 17 00:00:00 2001 From: "Nick V. Anokhin" Date: Sun, 19 Jul 2026 23:58:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20CoreEnum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- net/xeaf/rack/core/core_enum.py | 34 ++++++++++--------- .../tests/core/core_enum_from_string_tests.py | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) 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): """