From 2fbfba0ef3d6056ee0bbcf50d317f38490aad1cf Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 3 May 2017 10:25:08 -0500 Subject: [PATCH] Make Reporter class hold all results, move line/col into results, and out of message (#24127) * Make Reporter class hold all results, move line/col into results, and out of message * Move line/col out of message for YAML parser errors * We have lineno for the DOC var, use it for YAML parser errors * Remove valdiate-modules files from legacy-files * pep8 indentation fixes * Add todo for line/col in _validate_docs_schema --- test/sanity/pep8/legacy-files.txt | 2 - test/sanity/validate-modules/module_args.py | 2 +- test/sanity/validate-modules/schema.py | 2 +- test/sanity/validate-modules/utils.py | 22 +- test/sanity/validate-modules/validate-modules | 583 +++++++++++------- 5 files changed, 385 insertions(+), 226 deletions(-) diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 3a462537ec6..63062f09188 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -965,8 +965,6 @@ test/integration/setup_gce.py test/integration/targets/async/library/async_test.py test/integration/targets/uri/files/testserver.py test/sanity/code-smell/ansible-var-precedence-check.py -test/sanity/validate-modules/module_args.py -test/sanity/validate-modules/schema.py test/units/cli/test_galaxy.py test/units/contrib/inventory/test_vmware_inventory.py test/units/errors/test_errors.py diff --git a/test/sanity/validate-modules/module_args.py b/test/sanity/validate-modules/module_args.py index 473e69d42f8..2d8a6909b59 100644 --- a/test/sanity/validate-modules/module_args.py +++ b/test/sanity/validate-modules/module_args.py @@ -70,7 +70,7 @@ def add_mocks(filename): if [s for s in sources if s[:7] in ['ansible', '__main_']]: parts = module.split('.') for i in range(len(parts)): - dotted = '.'.join(parts[:i+1]) + dotted = '.'.join(parts[:i + 1]) # Never mock out ansible or ansible.module_utils # we may get here if a specific module_utils file needed mocked if dotted in ('ansible', 'ansible.module_utils',): diff --git a/test/sanity/validate-modules/schema.py b/test/sanity/validate-modules/schema.py index 008e53bc069..42ce90c45bc 100644 --- a/test/sanity/validate-modules/schema.py +++ b/test/sanity/validate-modules/schema.py @@ -81,6 +81,7 @@ def return_schema(data): extra=PREVENT_EXTRA ) + def doc_schema(module_name): if module_name.startswith('_'): module_name = module_name[1:] @@ -116,7 +117,6 @@ def metadata_schema(deprecated): ) - # Things to add soon #################### # 1) Recursively validate `type: complex` fields diff --git a/test/sanity/validate-modules/utils.py b/test/sanity/validate-modules/utils.py index c997de64a69..280cb48e64d 100644 --- a/test/sanity/validate-modules/utils.py +++ b/test/sanity/validate-modules/utils.py @@ -85,17 +85,25 @@ def parse_yaml(value, lineno, module, name, load_all=False): except yaml.MarkedYAMLError as e: e.problem_mark.line += lineno - 1 e.problem_mark.name = '%s.%s' % (module, name) - errors.append('%s is not valid YAML. Line %d column %d' % - (name, e.problem_mark.line + 1, - e.problem_mark.column + 1)) + errors.append({ + 'msg': '%s is not valid YAML' % name, + 'line': e.problem_mark.line + 1, + 'column': e.problem_mark.column + 1 + }) traces.append(e) except yaml.reader.ReaderError as e: traces.append(e) - errors.append('%s is not valid YAML. Character ' - '0x%x at position %d.' % - (name, e.character, e.position)) + # TODO: Better line/column detection + errors.append({ + 'msg': ('%s is not valid YAML. Character ' + '0x%x at position %d.' % (name, e.character, e.position)), + 'line': lineno + }) except yaml.YAMLError as e: traces.append(e) - errors.append('%s is not valid YAML: %s: %s' % (name, type(e), e)) + errors.append({ + 'msg': '%s is not valid YAML: %s: %s' % (name, type(e), e), + 'line': lineno + }) return data, errors, traces diff --git a/test/sanity/validate-modules/validate-modules b/test/sanity/validate-modules/validate-modules index 717b7b95376..399378d57cd 100755 --- a/test/sanity/validate-modules/validate-modules +++ b/test/sanity/validate-modules/validate-modules @@ -41,7 +41,7 @@ from ansible.utils.plugin_docs import BLACKLIST, get_docstring from module_args import get_argument_spec -from schema import doc_schema, option_schema, metadata_schema, return_schema +from schema import doc_schema, metadata_schema, return_schema from utils import CaptureStd, parse_yaml from voluptuous.humanize import humanize_error @@ -63,18 +63,18 @@ TYPE_REGEX = re.compile(r'.*(if|or)(\s+[^"\']*|\s+)(?