mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Improved/actionable keys out of order error message
This commit is contained in:
@@ -21,9 +21,13 @@ class SortEnforcingLoader(SafeLoader):
|
||||
self.flatten_mapping(node)
|
||||
ret = self.construct_pairs(node)
|
||||
keys = [d[0] for d in ret]
|
||||
if keys != sorted(keys, key=_natsort_key):
|
||||
raise ConstructorError(None, None, "keys out of order: {}"
|
||||
.format(', '.join(keys)), node.start_mark)
|
||||
keys_sorted = sorted(keys, key=_natsort_key)
|
||||
for key in keys:
|
||||
expected = keys_sorted.pop(0)
|
||||
if key != expected:
|
||||
raise ConstructorError(None, None, 'keys out of order: '
|
||||
'expected {} got {} at {}'
|
||||
.format(expected, key, node.start_mark))
|
||||
return dict(ret)
|
||||
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ class TestYaml(TestCase):
|
||||
'*.11.2': 'd'
|
||||
'*.10.1': 'c'
|
||||
''')
|
||||
self.assertEquals('keys out of order: *.2.2, *.1.2, *.11.2, *.10.1',
|
||||
ctx.exception.problem)
|
||||
self.assertTrue('keys out of order: expected *.1.2 got *.2.2 at' in
|
||||
ctx.exception.problem)
|
||||
|
||||
buf = StringIO()
|
||||
safe_dump({
|
||||
|
||||
Reference in New Issue
Block a user