diff options
author | 2018-03-26 13:54:47 +0300 | |
---|---|---|
committer | 2018-03-26 13:54:56 +0300 | |
commit | 4391bbd783c9ca51eef7883b61292ff1b1beba7c (patch) | |
tree | 4a60c271553c42363c808527fe59d7ac66522362 /vnftest/common | |
parent | ea90f9ba9d0e317dfc5521dda9946844b7336abd (diff) |
Add unit tests to improve coverage
Issue-ID: VNFSDK-183
Change-Id: I26d2412d3fcfd25431722a3da7cb40b23e2a98b4
Signed-off-by: Moshe <moshehoa@amdocs.com>
Diffstat (limited to 'vnftest/common')
-rw-r--r-- | vnftest/common/utils.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/vnftest/common/utils.py b/vnftest/common/utils.py index e62b5db..fbc8391 100644 --- a/vnftest/common/utils.py +++ b/vnftest/common/utils.py @@ -397,3 +397,30 @@ class Timer(object): def __getattr__(self, item): return getattr(self.delta, item) + +def find_relative_file(path, task_path): + """ + Find file in one of places: in abs of path or relative to a directory path, + in this order. + + :param path: + :param task_path: + :return str: full path to file + """ + # fixme: create schema to validate all fields have been provided + for lookup in [os.path.abspath(path), os.path.join(task_path, path)]: + try: + with open(lookup): + return lookup + except IOError: + pass + raise IOError(errno.ENOENT, 'Unable to find {} file'.format(path)) + + +def open_relative_file(path, task_path): + try: + return open(path) + except IOError as e: + if e.errno == errno.ENOENT: + return open(os.path.join(task_path, path)) + raise |