Debian Codegraph @

ansible_collections/community/dns/tests/unit/plugins/module_utils/test__utils.py

raw
1 # Copyright (c) 2025, Felix Fontein <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from __future__ import annotations
6
7 from .utils import patch_dict, patch_dict_absent
8
9
10 def test_patch_dict():
11 a = {1: True}
12 assert a[1] is True
13 assert 2 not in a
14 with patch_dict(a, 1, False):
15 assert a[1] is False
16 assert 2 not in a
17 assert a[1] is True
18 assert 2 not in a
19 with patch_dict(a, 2, False):
20 assert a[1] is True
21 assert a[2] is False
22 assert a[1] is True
23 assert 2 not in a
24
25
26 def test_patch_dict_absent():
27 a = {1: True}
28 assert a[1] is True
29 assert 2 not in a
30 with patch_dict_absent(a, 1):
31 assert 1 not in a
32 assert 2 not in a
33 assert a[1] is True
34 assert 2 not in a
35 with patch_dict_absent(a, 2):
36 assert a[1] is True
37 assert 2 not in a
38 assert a[1] is True
39 assert 2 not in a