Mercurial > hgrepos > Python > libs > data-schema
changeset 15:696b83f29363
Use enum props when printing validation problems
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 07 Jul 2023 02:17:45 +0200 |
| parents | cfb97c7c9e5b |
| children | 2a9e7c4b717e |
| files | data_schema/__init__.py tests/test_schema.py |
| diffstat | 2 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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):
--- 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))
