Debian Codegraph @

ansible_collections/amazon/aws/tests/unit/plugins/module_utils/policy/test_py3cmp.py

raw
1 # (c) 2022 Red Hat Inc.
2 #
3 # This file is part of Ansible
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 import pytest
7
8 from ansible_collections.amazon.aws.plugins.module_utils.policy import _py3cmp
9
10
11 def test_py3cmp_simple():
12 assert _py3cmp(1, 1) == 0
13 assert _py3cmp(1, 2) == -1
14 assert _py3cmp(2, 1) == 1
15 assert _py3cmp("1", "1") == 0
16 assert _py3cmp("1", "2") == -1
17 assert _py3cmp("2", "1") == 1
18 assert _py3cmp("a", "a") == 0
19 assert _py3cmp("a", "b") == -1
20 assert _py3cmp("b", "a") == 1
21 assert _py3cmp(("a",), ("a",)) == 0
22 assert _py3cmp(("a",), ("b",)) == -1
23 assert _py3cmp(("b",), ("a",)) == 1
24
25
26 def test_py3cmp_mixed():
27 # Replicates the Python2 comparison behaviour of placing strings before tuples
28 assert _py3cmp(("a",), "a") == 1
29 assert _py3cmp("a", ("a",)) == -1
30
31 assert _py3cmp(("a",), "b") == 1
32 assert _py3cmp("b", ("a",)) == -1
33 assert _py3cmp(("b",), "a") == 1
34 assert _py3cmp("a", ("b",)) == -1
35
36 # intended for use by _hashable_policy, so expects either a string or a tuple
37 with pytest.raises(TypeError):
38 _py3cmp((1,), 1)
39 with pytest.raises(TypeError):
40 _py3cmp(1, (1,))