summaryrefslogtreecommitdiffstats
path: root/vnftest/common
diff options
context:
space:
mode:
authorMoshe <moshehoa@amdocs.com>2019-04-04 11:56:48 +0300
committerMoshe <moshehoa@amdocs.com>2019-04-11 10:15:38 +0300
commit3b9d9e7d03186f8925548b0ce6db5d80e2dfcb8f (patch)
tree49b7b9989a5cdbfd0c53867e6822103283a1984b /vnftest/common
parentc9cdbfc69226a34447f7e5be99a8727ac1ece278 (diff)
fix s-overflow caused by cyclic reference
Issue-ID: VNFSDK-350 Change-Id: I23c53a7e614841abc54d7e35ddf97cfffaa23a4a Signed-off-by: Moshe <moshehoa@amdocs.com> fix test Issue-ID: VNFSDK-350 Change-Id: I5b3e67c2a595ef9048d6e6fc7181ae3f0248c8d4 Signed-off-by: Moshe <moshehoa@amdocs.com> coverage report Issue-ID: VNFSDK-350 Change-Id: I685ba57fd23df551c747efeecd2061fabe825535 Signed-off-by: Moshe <moshehoa@amdocs.com>
Diffstat (limited to 'vnftest/common')
-rw-r--r--vnftest/common/utils.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/vnftest/common/utils.py b/vnftest/common/utils.py
index b3f0c05..81dc8d7 100644
--- a/vnftest/common/utils.py
+++ b/vnftest/common/utils.py
@@ -420,26 +420,32 @@ def deep_dotdict(obj):
return obj
-def normalize_data_struct(obj):
+def normalize_data_struct(obj, cache={}):
if obj is None:
return None
+ if id(obj) in cache.keys():
+ return cache[id(obj)]
if isinstance(obj, list):
- nomalized_list = []
+ normalized_list = []
for element in obj:
- element = normalize_data_struct(element)
- nomalized_list.append(element)
- return nomalized_list
+ element = normalize_data_struct(element, cache)
+ normalized_list.append(element)
+ return normalized_list
if isinstance(obj, dict):
normalized_dict = {}
for k, v in obj.items():
if isinstance(k, basestring) and not k.startswith('_'):
- v = normalize_data_struct(v)
+ v = normalize_data_struct(v, cache)
normalized_dict[k] = v
return normalized_dict
# return obj if it is string, integer, bool ect.
if not hasattr(obj, '__dict__'):
return obj
- return normalize_data_struct(obj.__dict__)
+ obj_as_dict = {}
+ cache[id(obj)] = obj_as_dict
+ normalized = normalize_data_struct(obj.__dict__, cache)
+ obj_as_dict.update(normalized)
+ return obj_as_dict
def xml_to_dict(xml_str):