mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-26 13:56:09 -07:00
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.17) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.10) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.12) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.7) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
* Adjust all __future__ imports: for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i; done * Remove all UTF-8 encoding specifications for Python source files: for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i; done * Remove __metaclass__ = type: for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do sed -e '/^__metaclass__ = type/d' -i $i; done
165 lines
4.2 KiB
Python
165 lines
4.2 KiB
Python
# 2018.07.26 --- use DictComparison instead of GcpRequest
|
|
#
|
|
# Copyright (c) 2016, Tom Melendez <tom@supertom.com>
|
|
#
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from __future__ import annotations
|
|
|
|
from ansible_collections.community.internal_test_tools.tests.unit.compat import unittest
|
|
from ansible_collections.community.general.plugins.module_utils.hwc_utils import are_different_dicts
|
|
|
|
|
|
class HwcDictComparisonTestCase(unittest.TestCase):
|
|
def test_simple_no_difference(self):
|
|
value1 = {
|
|
'foo': 'bar',
|
|
'test': 'original'
|
|
}
|
|
|
|
self.assertFalse(are_different_dicts(value1, value1))
|
|
|
|
def test_simple_different(self):
|
|
value1 = {
|
|
'foo': 'bar',
|
|
'test': 'original'
|
|
}
|
|
value2 = {
|
|
'foo': 'bar',
|
|
'test': 'different'
|
|
}
|
|
value3 = {
|
|
'test': 'original'
|
|
}
|
|
|
|
self.assertTrue(are_different_dicts(value1, value2))
|
|
self.assertTrue(are_different_dicts(value1, value3))
|
|
self.assertTrue(are_different_dicts(value2, value3))
|
|
|
|
def test_nested_dictionaries_no_difference(self):
|
|
value1 = {
|
|
'foo': {
|
|
'quiet': {
|
|
'tree': 'test'
|
|
},
|
|
'bar': 'baz'
|
|
},
|
|
'test': 'original'
|
|
}
|
|
|
|
self.assertFalse(are_different_dicts(value1, value1))
|
|
|
|
def test_nested_dictionaries_with_difference(self):
|
|
value1 = {
|
|
'foo': {
|
|
'quiet': {
|
|
'tree': 'test'
|
|
},
|
|
'bar': 'baz'
|
|
},
|
|
'test': 'original'
|
|
}
|
|
value2 = {
|
|
'foo': {
|
|
'quiet': {
|
|
'tree': 'baz'
|
|
},
|
|
'bar': 'hello'
|
|
},
|
|
'test': 'original'
|
|
}
|
|
value3 = {
|
|
'foo': {
|
|
'quiet': {
|
|
'tree': 'test'
|
|
},
|
|
'bar': 'baz'
|
|
}
|
|
}
|
|
|
|
self.assertTrue(are_different_dicts(value1, value2))
|
|
self.assertTrue(are_different_dicts(value1, value3))
|
|
self.assertTrue(are_different_dicts(value2, value3))
|
|
|
|
def test_arrays_strings_no_difference(self):
|
|
value1 = {
|
|
'foo': [
|
|
'baz',
|
|
'bar'
|
|
]
|
|
}
|
|
|
|
self.assertFalse(are_different_dicts(value1, value1))
|
|
|
|
def test_arrays_strings_with_difference(self):
|
|
value1 = {
|
|
'foo': [
|
|
'baz',
|
|
'bar',
|
|
]
|
|
}
|
|
|
|
value2 = {
|
|
'foo': [
|
|
'baz',
|
|
'hello'
|
|
]
|
|
}
|
|
value3 = {
|
|
'foo': [
|
|
'bar',
|
|
]
|
|
}
|
|
|
|
self.assertTrue(are_different_dicts(value1, value2))
|
|
self.assertTrue(are_different_dicts(value1, value3))
|
|
self.assertTrue(are_different_dicts(value2, value3))
|
|
|
|
def test_arrays_dicts_with_no_difference(self):
|
|
value1 = {
|
|
'foo': [
|
|
{
|
|
'test': 'value',
|
|
'foo': 'bar'
|
|
},
|
|
{
|
|
'different': 'dict'
|
|
}
|
|
]
|
|
}
|
|
|
|
self.assertFalse(are_different_dicts(value1, value1))
|
|
|
|
def test_arrays_dicts_with_difference(self):
|
|
value1 = {
|
|
'foo': [
|
|
{
|
|
'test': 'value',
|
|
'foo': 'bar'
|
|
},
|
|
{
|
|
'different': 'dict'
|
|
}
|
|
]
|
|
}
|
|
value2 = {
|
|
'foo': [
|
|
{
|
|
'test': 'value2',
|
|
'foo': 'bar2'
|
|
},
|
|
]
|
|
}
|
|
value3 = {
|
|
'foo': [
|
|
{
|
|
'test': 'value',
|
|
'foo': 'bar'
|
|
}
|
|
]
|
|
}
|
|
|
|
self.assertTrue(are_different_dicts(value1, value2))
|
|
self.assertTrue(are_different_dicts(value1, value3))
|
|
self.assertTrue(are_different_dicts(value2, value3))
|