comparison data_schema/__init__.py @ 30:2e7c08c356ee

Test the the ValidationProblem's str() and repr()
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 08 Jul 2023 20:45:36 +0200
parents 68286d27f27d
children 271ec3abdfa3
comparison
equal deleted inserted replaced
29:68286d27f27d 30:2e7c08c356ee
219 def __repr__(self): 219 def __repr__(self):
220 try: 220 try:
221 msg = " (" + problem_message(self) + ")" 221 msg = " (" + problem_message(self) + ")"
222 except LookupError: 222 except LookupError:
223 msg = "" 223 msg = ""
224 if self.context is not None:
225 context_depth = self.context.depth
226 else:
227 context_depth = None
224 if self.index is None: 228 if self.index is None:
225 return "ValidationProblem(code={}{}, severity={}, hint={}, context=[depth={}]{})".format( 229 return "ValidationProblem(code={}{}, severity={}, hint={}, context=[depth={}]{})".format(
226 self.code.name, msg, self.severity.name, self.hint, self.context.depth, self.context) 230 self.code.name, msg, self.severity.name, self.hint, context_depth, self.context)
227 else: 231 else:
228 return "ValidationProblem(code={}{}, severity={}, hint={}, context=[depth={}]{}, index={})".format( 232 return "ValidationProblem(code={}{}, severity={}, hint={}, context=[depth={}]{}, index={})".format(
229 self.code.name, msg, self.severity.name, self.hint, self.context.depth, self.context, self.index) 233 self.code.name, msg, self.severity.name, self.hint, context_depth, self.context, self.index)
230 234
231 235
232 class SchemaError(Exception): 236 class SchemaError(Exception):
233 """An error within the schema itself""" 237 """An error within the schema itself"""
234 pass 238 pass