Skip to content

Commit

Permalink
Update the validation output to include choices list
Browse files Browse the repository at this point in the history
Update the string formatting pattern for validation, list the available choices when appropriate
  • Loading branch information
mshriver authored and elyezer committed Nov 25, 2020
1 parent 861b92c commit 1a607c7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
34 changes: 25 additions & 9 deletions testimony/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,33 @@ def validate_docstring_report(testcases):
if not SETTINGS['tokens'][token].validate(value):
invalid_token_values.setdefault(token, value)
if invalid_token_values:
invalid_token_strings = []
for key, value in sorted(invalid_token_values.items()):
settings_token = SETTINGS['tokens'][key]
# TODO: Rework constants to not compare bare string
if settings_token.token_type == 'choice':
valid_choices_string = '\n choices: {}'.format(
settings_token.choices
)
else:
valid_choices_string = ''
invalid_token_strings.append(
'{token}: {value}'
'\n type: {type}'
'\n case sensitive: {sensitive}'
'{choices}'.format(
token=key.capitalize(),
value=value,
type=settings_token.token_type,
sensitive=settings_token.casesensitive,
choices=valid_choices_string,
)
)

issues.append('Tokens with invalid values:\n{0}'.format(
indent(
'\n'.join([
"{0}: {1} (type: '{2}')".format(
key.capitalize(), value,
SETTINGS['tokens'][key].token_type
)
for key, value in
sorted(invalid_token_values.items())
]),
' '
'\n'.join(invalid_token_strings),
' ',
)
))
invalid_token_value_count += 1
Expand Down
2 changes: 1 addition & 1 deletion testimony/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import yaml

TOKEN_TYPES = ['choice']
from testimony.constants import TOKEN_TYPES


def parse_config(filehandle):
Expand Down
4 changes: 4 additions & 0 deletions testimony/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
VALIDATE_DOCSTRING_REPORT,
)

TOKEN_TYPES = [
'choice',
]

DEFAULT_TOKENS = (
'assert',
'bz',
Expand Down
20 changes: 16 additions & 4 deletions tests/sample_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,27 @@ ConfigurationFileTestCase::test_multiple_invalid_keys:208
---------------------------------------------------------

* Tokens with invalid values:
Caseimportance: Lowest (type: 'choice')
Status: Invalid (type: 'choice')
Caseimportance: Lowest
type: choice
case sensitive: True
choices: ['Critical', 'High', 'Medium', 'Low']
Status: Invalid
type: choice
case sensitive: False
choices: ['manual', 'automated']

ConfigurationFileTestCase::test_case_mismatch_case_sensitive_values:236
-----------------------------------------------------------------------

* Tokens with invalid values:
Caseautomation: AUTOMATED (type: 'choice')
Caseimportance: critical (type: 'choice')
Caseautomation: AUTOMATED
type: choice
case sensitive: True
choices: ['Automated', 'NotAutomated', 'ManualOnly']
Caseimportance: critical
type: choice
case sensitive: True
choices: ['Critical', 'High', 'Medium', 'Low']

Total number of tests: 21
Total number of invalid docstrings: 6 (28.57%)
Expand Down

0 comments on commit 1a607c7

Please sign in to comment.