X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fhelpers.py;h=ff82c71096a232e5b12d4b366e080d531f0ad221;hb=940ae7b0283191d590de40b71a9136bebc80e83c;hp=6a6fb732bee14c5328a8d231affe825ac458de6a;hpb=9e39bf74ce93945b322c554349e85afca3a79852;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/helpers.py b/ice_validator/tests/helpers.py index 6a6fb73..ff82c71 100644 --- a/ice_validator/tests/helpers.py +++ b/ice_validator/tests/helpers.py @@ -47,7 +47,16 @@ from collections import defaultdict from boltons import funcutils from tests import cached_yaml as yaml -VERSION = "1.1.0" +__path__ = [os.path.dirname(os.path.abspath(__file__))] +DEFAULT_OUTPUT_DIR = "{}/../output".format(__path__[0]) +RE_BASE = re.compile(r"(^base$)|(^base_)|(_base_)|(_base$)") + + +def is_base_module(template_path): + basename = os.path.basename(template_path).lower() + name, extension = os.path.splitext(basename) + is_yaml = extension in {".yml", ".yaml"} + return is_yaml and RE_BASE.search(name) and not name.endswith("_volume") def check_basename_ending(template_type, basename): @@ -262,9 +271,6 @@ def check_indices(pattern, values, value_type): return invalid_params -RE_BASE = re.compile(r"(^base$)|(^base_)|(_base_)|(_base$)") - - def get_base_template_from_yaml_files(yaml_files): """Return first filepath to match RE_BASE """ @@ -338,3 +344,15 @@ def get_param(property_value): else: return param return None + + +def get_output_dir(config): + """ + Retrieve the output directory for the reports and create it if necessary + :param config: pytest configuration + :return: output directory as string + """ + output_dir = config.option.output_dir or DEFAULT_OUTPUT_DIR + if not os.path.exists(output_dir): + os.makedirs(output_dir, exist_ok=True) + return output_dir