aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBozawglanian, Hagop (hb755d) <hb755d@att.com>2018-07-31 20:44:18 +0000
committerBozawglanian, Hagop (hb755d) <hb755d@att.com>2018-07-31 23:19:25 +0000
commit06511c3ae3ed91250586d4b1c14130d83eaa64c8 (patch)
tree4f45aad21db26dcae58ea795f7d1f5d75e52faf0
parent20b8e673c02ed57cc2393b81bbdda3904ed91da5 (diff)
[VVP] Updating error reporting for helpers
Change-Id: Ib93b6ff452613b2ee1f2804d958f4c6f66d6dee4 Issue-ID: VVP-80 Signed-off-by: Bozawglanian, Hagop (hb755d) <hb755d@att.com>
-rwxr-xr-x[-rw-r--r--]ice_validator/tests/helpers.py7
-rwxr-xr-x[-rw-r--r--]ice_validator/tests/parametrizers.py126
-rwxr-xr-x[-rw-r--r--]ice_validator/tests/utils/volumes.py8
3 files changed, 85 insertions, 56 deletions
diff --git a/ice_validator/tests/helpers.py b/ice_validator/tests/helpers.py
index 82d0201..37fd01f 100644..100755
--- a/ice_validator/tests/helpers.py
+++ b/ice_validator/tests/helpers.py
@@ -55,10 +55,11 @@ 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 = ''
@@ -67,8 +68,8 @@ def get_parsed_yml_for_yaml_files(yaml_files, sections=[]):
with open(yaml_file) as fh:
yml = yaml.load(fh)
except Exception as e:
- print(e)
-
+ print('Error in %s: %s' % (yaml_file, e))
+ continue
if yml:
if sections:
for k in yml.keys():
diff --git a/ice_validator/tests/parametrizers.py b/ice_validator/tests/parametrizers.py
index 0d9971f..33b214b 100644..100755
--- a/ice_validator/tests/parametrizers.py
+++ b/ice_validator/tests/parametrizers.py
@@ -37,7 +37,6 @@
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
#
-
from os import path, listdir
import re
import yaml
@@ -45,6 +44,10 @@ import pytest
from .helpers import get_parsed_yml_for_yaml_files, check_basename_ending
from .utils.nested_files import get_list_of_nested_files
+VERSION = '1.0.0'
+
+# pylint: disable=invalid-name
+
def get_template_dir(metafunc):
'''
@@ -73,74 +76,86 @@ def get_nested_files(filenames):
if "resources" not in yml:
continue
nested_files.extend(get_list_of_nested_files(
- yml["resources"], path.dirname(filename)))
- except Exception as e:
- print(e)
+ yml["resources"],
+ path.dirname(filename)))
+ except yaml.YAMLError as e:
+ print(e) # pylint: disable=superfluous-parens
continue
return nested_files
-def list_filenames_in_template_dir(metafunc, extensions, template_type='',
- sub_dirs=[]):
+def list_filenames_in_template_dir(
+ metafunc,
+ extensions,
+ template_type='',
+ sub_dirs=None):
'''
returns the filenames in a template_dir, either as its passed in
on CLI or, during --self-test, the directory whos name matches
the current tests module name
'''
+ sub_dirs = [] if sub_dirs is None else sub_dirs
template_dir = get_template_dir(metafunc)
filenames = []
-
- try:
- if metafunc.config.getoption('self_test'):
- filenames = [path.join(template_dir, s, f)
- for s in sub_dirs
- for f in listdir(path.join(template_dir, s))
- if path.isfile(path.join(template_dir, s, f)) and
- path.splitext(f)[-1] in extensions and
- check_basename_ending(template_type,
- path.splitext(f)[0])]
- else:
- filenames = [path.join(template_dir, f)
- for f in listdir(template_dir)
- if path.isfile(path.join(template_dir, f)) and
- path.splitext(f)[-1] in extensions and
- check_basename_ending(template_type,
- path.splitext(f)[0])]
-
- except Exception as e:
- print(e)
-
+ if metafunc.config.getoption('self_test'):
+ filenames = [path.join(template_dir, s, f)
+ for s in sub_dirs
+ for f in listdir(path.join(template_dir, s))
+ if path.isfile(path.join(template_dir, s, f))
+ and path.splitext(f)[-1] in extensions
+ and check_basename_ending(
+ template_type,
+ path.splitext(f)[0])]
+ else:
+ filenames = [path.join(template_dir, f)
+ for f in listdir(template_dir)
+ if path.isfile(path.join(template_dir, f))
+ and path.splitext(f)[-1] in extensions
+ and check_basename_ending(
+ template_type,
+ path.splitext(f)[0])]
return filenames
-def list_template_dir(metafunc, extensions, exclude_nested=True,
- template_type='', sub_dirs=[]):
+def list_template_dir(
+ metafunc,
+ extensions,
+ exclude_nested=True,
+ template_type='',
+ sub_dirs=None):
'''
returns the filenames excluding the nested files for a template_dir,
either as its passed in on CLI or, during --self-test, the
directory whos name matches the current tests module name
'''
+ sub_dirs = [] if sub_dirs is None else sub_dirs
filenames = []
nested_files = []
-
- try:
- filenames = list_filenames_in_template_dir(metafunc, extensions,
- template_type, sub_dirs)
- if exclude_nested:
- nested_files = get_nested_files(filenames)
- except Exception as e:
- print(e)
-
+ filenames = list_filenames_in_template_dir(
+ metafunc,
+ extensions,
+ template_type,
+ sub_dirs)
+ if exclude_nested:
+ nested_files = get_nested_files(filenames)
return list(set(filenames) - set(nested_files))
-def get_filenames_list(metafunc, extensions=[".yaml", ".yml", ".env"],
- exclude_nested=False, template_type=''):
+def get_filenames_list(
+ metafunc,
+ extensions=None,
+ exclude_nested=False,
+ template_type=''):
'''
returns the filename fixtures for the template dir, either as by how its
passed in on CLI or, during --self-test, the directory whos name
matches the current tests module name
'''
+ extensions = [
+ ".yaml",
+ ".yml",
+ ".env"
+ ] if extensions is None else extensions
if metafunc.config.getoption('self_test'):
filenames_list = list_template_dir(metafunc,
extensions,
@@ -162,13 +177,21 @@ def get_filenames_list(metafunc, extensions=[".yaml", ".yml", ".env"],
return filenames_list
-def get_filenames_lists(metafunc, extensions=[".yaml", ".yml", ".env"],
- exclude_nested=False, template_type=''):
+def get_filenames_lists(
+ metafunc,
+ extensions=None,
+ exclude_nested=False,
+ template_type=''):
'''
returns the list of files in the template dir, either as by how its
passed in on CLI or, during --self-test, the directory whos name
matches the current tests module name
'''
+ extensions = [
+ ".yaml",
+ ".yml",
+ ".env"
+ ] if extensions is None else extensions
filenames_lists = []
if metafunc.config.getoption('self_test'):
filenames_lists.append(list_template_dir(metafunc,
@@ -188,17 +211,21 @@ def get_filenames_lists(metafunc, extensions=[".yaml", ".yml", ".env"],
extensions,
exclude_nested,
template_type))
-
return filenames_lists
-def get_parsed_yaml_files(metafunc, extensions, exclude_nested=True,
- template_type='', sections=[]):
+def get_parsed_yaml_files(
+ metafunc,
+ extensions,
+ exclude_nested=True,
+ template_type='',
+ sections=None):
'''
returns the list of parsed yaml files in the specified template dir,
either as by how its passed in on CLI or, during --self-test, the
directory whos name matches the current tests module name
'''
+ sections = [] if sections is None else sections
extensions = [".yaml", ".yml"]
if metafunc.config.getoption('self_test'):
@@ -217,7 +244,6 @@ def get_parsed_yaml_files(metafunc, extensions, exclude_nested=True,
yaml_files = list_template_dir(metafunc, extensions)
parsed_yml_list = get_parsed_yml_for_yaml_files(yaml_files,
sections)
-
return parsed_yml_list
@@ -405,8 +431,8 @@ def parametrize_environment_pair(metafunc, template_type=''):
else:
pairs.append({"name": basename, "yyml": yyml, "eyml": eyml})
- except Exception as e:
- print(e)
+ except yaml.YAMLError as e:
+ print(e) # pylint: disable=superfluous-parens
metafunc.parametrize('environment_pair', pairs)
@@ -450,7 +476,7 @@ def parametrize_heat_volume_pair(metafunc):
else:
pairs.append({"name": basename, "yyml": yyml, "vyml": vyml})
- except Exception as e:
- print(e)
+ except yaml.YAMLError as e:
+ print(e) # pylint: disable=superfluous-parens
metafunc.parametrize('heat_volume_pair', pairs)
diff --git a/ice_validator/tests/utils/volumes.py b/ice_validator/tests/utils/volumes.py
index 03ac611..7cdd147 100644..100755
--- a/ice_validator/tests/utils/volumes.py
+++ b/ice_validator/tests/utils/volumes.py
@@ -38,8 +38,10 @@
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
#
-import yaml
from os import path
+import yaml
+
+VERSION = '1.0.0'
def get_volume_resources(heat_template):
@@ -60,8 +62,8 @@ def get_volume_resources(heat_template):
try:
with open(volume_template) as fh:
yml = yaml.load(fh)
- except Exception as e:
- print(e)
+ except yaml.YAMLError as e:
+ print(e) # pylint: disable=superfluous-parens
return {}
if 'outputs' not in yml: