Merge "Revert "Add function helpers.compare_dict""

This commit is contained in:
Zuul 2018-12-21 19:13:11 +00:00 committed by Gerrit Code Review
commit 6bbac3c726
3 changed files with 0 additions and 42 deletions

View File

@ -90,19 +90,6 @@ class TestCompareElements(base.BaseTestCase):
['juve', 'napoli']))
class TestCompare(base.BaseTestCase):
def test_compare(self):
self.assertTrue(helpers.compare_dict({'a': 2}, {'a': 2}))
self.assertFalse(helpers.compare_dict({'a': 2}, {'a': 3}))
self.assertTrue(helpers.compare_dict({'a': [1, 2]}, {'a': [2, 1]}))
self.assertFalse(helpers.compare_dict({'a': [1, 2]}, {'a': [1]}))
self.assertTrue(helpers.compare_dict({'a': 'value1'}, {'a': 'value1'}))
self.assertFalse(helpers.compare_dict({'a': 'value'}, {'a': 'value1'}))
self.assertFalse(helpers.compare_dict({'a': '1'},
{'a': '1', 'b': '2'}))
class TestDictUtils(base.BaseTestCase):
def test_dict2str(self):

View File

@ -74,29 +74,6 @@ def compare_elements(a, b):
return set(a or []) == set(b or [])
def compare_dict(a, b):
"""Compare two dicts, including keys and values.
Useful because dict comparison was removed in Python 3.0.1.
:param a: The first dict to compare.
:param b: The second dict to compare.
:returns: True if a and b have the same keys and values, False otherwise.
"""
if sorted(list(a.keys())) != sorted(list(b.keys())):
return False
for key, value in a.items():
if not isinstance(value, type(b[key])):
return False
if isinstance(value, dict) and not compare_dict(value, b[key]):
return False
if isinstance(value, list) and not value.sort() == b[key].sort():
return False
elif value != b[key]:
return False
return True
def safe_sort_key(value):
"""Return value hash or build one for dictionaries.

View File

@ -1,6 +0,0 @@
---
features:
- |
Introduced ``compare_dict`` function in ``neutron_lib.utils.helpers``. It
allows you to compare two dictionaries, checking both the keys and the
values they contain.