Move the output around - first print the unexpected messages, only then fail the assertions

This commit is contained in:
Pim van Pelt
2022-03-21 10:23:49 +00:00
parent 58d0ebe71e
commit 551b06bb67
2 changed files with 6 additions and 28 deletions

View File

@ -58,12 +58,6 @@ class YAMLTest(unittest.TestCase):
v = Validator(schema=self.yaml_schema) v = Validator(schema=self.yaml_schema)
rv, msgs = v.validate(cfg) rv, msgs = v.validate(cfg)
count = 0
if 'test' in unittest and 'errors' in unittest['test'] and 'count' in unittest['test']['errors']:
count = unittest['test']['errors']['count']
if len(msgs) != count:
print(msgs, file=sys.stderr)
self.assertEqual(len(msgs), count)
msgs_unexpected = 0 msgs_unexpected = 0
msgs_expected = [] msgs_expected = []
@ -80,6 +74,12 @@ class YAMLTest(unittest.TestCase):
if not this_msg_expected: if not this_msg_expected:
print("%s: Unexpected message: %s" % (self.yaml_filename, m), file=sys.stderr) print("%s: Unexpected message: %s" % (self.yaml_filename, m), file=sys.stderr)
fail = True fail = True
count = 0
if 'test' in unittest and 'errors' in unittest['test'] and 'count' in unittest['test']['errors']:
count = unittest['test']['errors']['count']
self.assertEqual(len(msgs), count)
self.assertFalse(fail) self.assertFalse(fail)
return return

View File

@ -1,22 +0,0 @@
test:
description: "The length of the generated child LCP name is too long"
errors:
expected:
- "sub-interface .* has LCP with too long name"
count: 1
---
interfaces:
GigabitEthernet1/0/0:
lcp: "e01234"
sub-interfaces:
100:
description: "Dot1Q subinterface"
encapsulation:
dot1q: 1234
101:
description: "QinQ subinterface"
addresses: [ 192.0.2.1/24 ]
encapsulation:
dot1q: 1234
inner-dot1q: 2345