Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/modules/test_dconf.py

raw
1 # Copyright (c) 2023 Ansible Project
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
3 # https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import annotations
7
8 import pytest
9
10 from ansible_collections.community.general.plugins.modules import dconf
11
12 try:
13 from gi.repository.GLib import Variant
14 except ImportError:
15 Variant = None
16
17 DconfPreference = dconf.DconfPreference
18
19
20 @pytest.mark.parametrize(
21 "v1,v2,expected,fallback_expected",
22 (
23 ("'foo'", "'foo'", True, True),
24 ('"foo"', "'foo'", True, False),
25 ("'foo'", '"foo"', True, False),
26 ("'foo'", '"bar"', False, False),
27 ("[1, 2, 3]", "[1, 2, 3]", True, True),
28 ("[1, 2, 3]", "[3, 2, 1]", False, False),
29 ("1234", "1234", True, True),
30 ("1234", "1235", False, False),
31 ("1.0", "1.0", True, True),
32 ("1.000", "1.0", True, False),
33 ("2.0", "4.0", False, False),
34 # GVariants with different types aren't equal!
35 ("1", "1.0", False, False),
36 # Explicit types
37 ("@as []", "[]", True, False),
38 ),
39 )
40 def test_gvariant_equality(mocker, v1, v2, expected, fallback_expected):
41 assert DconfPreference.variants_are_equal(v1, v2) is (expected if Variant else fallback_expected)
42 mocker.patch.object(dconf, "Variant", None)
43 mocker.patch.object(dconf, "GError", AttributeError)
44 assert DconfPreference.variants_are_equal(v1, v2) is fallback_expected