X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fhelpers.py;h=5e4f3d38d772c8ecd64a9c5affcbf7fda71f81c2;hb=1af0d577ab6d8c431ae1322657c50efd5e0a1a93;hp=9cde1faf11ff4b149b2dec2e4a9aca3829c88a9c;hpb=cc21b8b08b6dbcec577bfb26ff397ac899da8002;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/helpers.py b/ice_validator/tests/helpers.py index 9cde1fa..5e4f3d3 100644 --- a/ice_validator/tests/helpers.py +++ b/ice_validator/tests/helpers.py @@ -1,12 +1,12 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the “License”); +# under the Apache License, Version 2.0 (the "License"); # you may not use this software except in compliance with the License. # You may obtain a copy of the License at # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); # you may not use this documentation except in compliance with the License. # You may obtain a copy of the License at # @@ -38,8 +38,14 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # +"""Helpers +""" + +from boltons import funcutils import yaml +VERSION = '1.1.0' + def check_basename_ending(template_type, basename): ''' @@ -54,25 +60,49 @@ def check_basename_ending(template_type, basename): return not basename.endswith('_volume') -def get_parsed_yml_for_yaml_files(yaml_files, sections=[]): +def get_parsed_yml_for_yaml_files(yaml_files, sections=None): ''' get the parsed yaml for a list of yaml files ''' + sections = [] if sections is None else sections parsed_yml_list = [] for yaml_file in yaml_files: - yml = '' - try: with open(yaml_file) as fh: yml = yaml.load(fh) - except Exception as e: - print(e) - + except yaml.YAMLError as e: + # pylint: disable=superfluous-parens + print('Error in %s: %s' % (yaml_file, e)) + continue if yml: if sections: for k in yml.keys(): if k not in sections: del yml[k] parsed_yml_list.append(yml) - return parsed_yml_list + + +def validates(*requirement_ids): + """Decorator that tags the test function with one or more requirement IDs. + + Example: + >>> @validates('R-12345', 'R-12346') + ... def test_something(): + ... pass + >>> assert test_something.requirement_ids == ['R-12345', 'R-12346'] + """ + # pylint: disable=missing-docstring + def decorator(func): + # NOTE: We use a utility here to ensure that function signatures are + # maintained because pytest inspects function signatures to inject + # fixtures. I experimented with a few options, but this is the only + # library that worked. Other libraries dynamically generated a + # function at run-time, and then lost the requirement_ids attribute + @funcutils.wraps(func) + def wrapper(*args, **kw): + return func(*args, **kw) + wrapper.requirement_ids = requirement_ids + return wrapper + decorator.requirement_ids = requirement_ids + return decorator