diff --git a/testimony/__init__.py b/testimony/__init__.py index afd6240..a76cacb 100755 --- a/testimony/__init__.py +++ b/testimony/__init__.py @@ -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 diff --git a/testimony/config.py b/testimony/config.py index cd86e6f..f3234cc 100644 --- a/testimony/config.py +++ b/testimony/config.py @@ -18,7 +18,7 @@ import yaml -TOKEN_TYPES = ['choice'] +from testimony.constants import TOKEN_TYPES def parse_config(filehandle): diff --git a/testimony/constants.py b/testimony/constants.py index 9f916a4..1cf54eb 100644 --- a/testimony/constants.py +++ b/testimony/constants.py @@ -16,6 +16,10 @@ VALIDATE_DOCSTRING_REPORT, ) +TOKEN_TYPES = [ + 'choice', +] + DEFAULT_TOKENS = ( 'assert', 'bz', diff --git a/tests/sample_output.txt b/tests/sample_output.txt index 5055886..bb421cc 100644 --- a/tests/sample_output.txt +++ b/tests/sample_output.txt @@ -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%)