summaryrefslogtreecommitdiffstats
path: root/test/units/vars/test_module_response_deepcopy.py
blob: d484da0643ccd78d15c894c1a0f7d8c4b1227262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# (c) 2018 Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import annotations

from ansible.vars.clean import module_response_deepcopy


def test_module_response_deepcopy_basic():
    x = 42
    y = module_response_deepcopy(x)
    assert y == x


def test_module_response_deepcopy_atomic():
    tests = [None, 42, 2**100, 3.14, True, False, 1j,
             "hello", u"hello\u1234"]
    for x in tests:
        assert module_response_deepcopy(x) is x


def test_module_response_deepcopy_list():
    x = [[1, 2], 3]
    y = module_response_deepcopy(x)
    assert y == x
    assert x is not y
    assert x[0] is not y[0]


def test_module_response_deepcopy_empty_tuple():
    x = ()
    y = module_response_deepcopy(x)
    assert x is y


def test_module_response_deepcopy_tuple_of_immutables():
    x = ((1, 2), 3)
    y = module_response_deepcopy(x)
    assert x is y


def test_module_response_deepcopy_dict():
    x = {"foo": [1, 2], "bar": 3}
    y = module_response_deepcopy(x)
    assert y == x
    assert x is not y
    assert x["foo"] is not y["foo"]