Skip to content

Filter out unrelated filter messages when assertFilterErrors fails #11

Description

@todofixthis

assertFilterErrors output includes a lot of irrelevant output that makes it difficult to identify the cause of a test failure.

Example:

AssertionError: Filter generated unexpected error codes (expected {"trytes.0": ["empty"], "trytes.1": ["wrong_type"], "trytes.2": ["wrong_type"], "trytes.3": ["empty"], "trytes.4": ["not_trytes"], "trytes.6": ["wrong_type"], "trytes.7": ["wrong_format"]}):

{'trytes.0': [FilterMessage('This value is required.', {'value': b'', 'filter': 'Required(allow_none=False)', 'key': 'trytes.0', 'replacement': None, 'code': 'empty'})],
 'trytes.1': [FilterMessage('str is not valid (allowed types: TryteString, bytearray, bytes).', {'value': 'TRYTEVALUEHERE', 'filter': 'Type(TryteString, bytearray, bytes, allow_subclass=True)', 'key': 'trytes.1', 'replacement': None, 'code': 'wrong_type'})],
 'trytes.2': [FilterMessage('bool is not valid (allowed types: TryteString, bytearray, bytes).', {'value': True, 'filter': 'Type(TryteString, bytearray, bytes, allow_subclass=True)', 'key': 'trytes.2', 'replacement': None, 'code': 'wrong_type'})],
 'trytes.3': [FilterMessage('This value is required.', {'value': None, 'filter': 'Required(allow_none=False)', 'key': 'trytes.3', 'replacement': None, 'code': 'empty'})],
 'trytes.4': [FilterMessage('This value is not a valid tryte sequence.', {'value': b'not valid trytes', 'filter': 'Trytes()', 'key': 'trytes.4', 'replacement': None, 'code': 'not_trytes'})],
 'trytes.6': [FilterMessage('int is not valid (allowed types: TryteString, bytearray, bytes).', {'value': 2130706433, 'filter': 'Type(TryteString, bytearray, bytes, allow_subclass=True)', 'key': 'trytes.6', 'replacement': None, 'code': 'wrong_type'})]}

To make it easier to decipher the output, it would be helpful if irrelevant filter messages were removed from the result. E.g.:

AssertionError: Filter generated incorrect error codes:

- [missing] 'trytes.6'

- [unexpected] 'trytes.7': 'wrong_type'
    [FilterMessage('int is not valid (allowed types: TryteString, bytearray, bytes).', {'value': 2130706433, 'filter': 'Type(TryteString, bytearray, bytes, allow_subclass=True)', 'key': 'trytes.6', 'replacement': None, 'code': 'wrong_type'})]}

- [wrong code]: 'trytes.8': 'wrong_type' (expected 'empty')
    [FilterMessage('int is not valid (allowed types: TryteString, bytearray, bytes).', {'value': 2130706433, 'filter': 'Type(TryteString, bytearray, bytes, allow_subclass=True)', 'key': 'trytes.6', 'replacement': None, 'code': 'wrong_type'})]}

Bonus Points

Pretty-print the FilterMessage values, e.g.:

- [wrong code]: 'trytes.8': 'wrong_type' (expected 'empty')
    [FilterMessage(
      message='int is not valid (allowed types: TryteString, bytearray, bytes).',
      context={'value': 2130706433,
               'code': 'wrong_type',
               'filter': 'Type(TryteString, bytearray, bytes, allow_subclass=True)',
               'key': 'trytes.6',
               'replacement': None})]}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions