# HG changeset patch # User Franz Glasner # Date 1688689065 -7200 # Node ID 696b83f293638582bd1b2c812ba940a221967ad3 # Parent cfb97c7c9e5b0ae676525eb61a04ec13cfc5bdfc Use enum props when printing validation problems diff -r cfb97c7c9e5b -r 696b83f29363 data_schema/__init__.py --- a/data_schema/__init__.py Fri Jul 07 02:13:16 2023 +0200 +++ b/data_schema/__init__.py Fri Jul 07 02:17:45 2023 +0200 @@ -182,7 +182,7 @@ cause=None, index=None): if code is None: - raise TypeError("`code' must be given") + raise TypeError("`code' must be given") # check validity if code not in ERRORS and code not in WARNINGS: raise ValueError( @@ -216,11 +216,11 @@ except LookupError: msg = "" if self.index is None: - return "ValidationProblem(code={!r}{}, severity={!r}, hint={}, context=[depth={}]{})".format( - self.code, msg, self.severity, self.hint, self.context.depth, self.context) + return "ValidationProblem(code={}{}, severity={!r}, hint={}, context=[depth={}]{})".format( + self.code.name, msg, self.severity, self.hint, self.context.depth, self.context) else: - return "ValidationProblem(code={!r}{}, severity={!r}, hint={}, context=[depth={}]{}, index={})".format( - self.code, msg, self.severity, self.hint, self.context.depth, self.context, self.index) + return "ValidationProblem(code={}{}, severity={!r}, hint={}, context=[depth={}]{}, index={})".format( + self.code.name, msg, self.severity, self.hint, self.context.depth, self.context, self.index) class SchemaError(Exception): diff -r cfb97c7c9e5b -r 696b83f29363 tests/test_schema.py --- a/tests/test_schema.py Fri Jul 07 02:13:16 2023 +0200 +++ b/tests/test_schema.py Fri Jul 07 02:17:45 2023 +0200 @@ -1330,6 +1330,11 @@ class BasicValidation(unittest.TestCase): + def test_enum_name(self): + code = ERRORS.E10001 + self.assertEqual("ERRORS.E10001", str(code)) + self.assertEqual("E10001", code.name) + def test_schema_must_be_a_dict_alike(self): try: pr = list(data_schema.validate(None, None))