Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out unrelated filter messages when assertFilterErrors fails #11

Open
todofixthis opened this issue Jan 14, 2017 · 1 comment
Open
Assignees

Comments

@todofixthis
Copy link
Contributor

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})]}
@todofixthis
Copy link
Contributor Author

Need to consider how to format output when expected/actual contains multiple errors for a single key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant