summaryrefslogtreecommitdiffstats
path: root/test/units/module_utils/common/text/formatters/test_lenient_lowercase.py
blob: 1ecc013e59bd37cba7daed3b56f946c85e7f7a68 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
# Copyright 2019, Andrew Klychkov @Andersson007 <aaklychkov@mail.ru>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

from datetime import datetime

import pytest

from ansible.module_utils.common.text.formatters import lenient_lowercase


INPUT_LIST = [
    u'HELLO',
    u'Ёлка',
    u'cafÉ',
    u'くらとみ',
    b'HELLO',
    1,
    {1: 'Dict'},
    True,
    [1],
    3.14159,
]

EXPECTED_LIST = [
    u'hello',
    u'ёлка',
    u'café',
    u'くらとみ',
    b'hello',
    1,
    {1: 'Dict'},
    True,
    [1],
    3.14159,
]

result_list = lenient_lowercase(INPUT_LIST)


@pytest.mark.parametrize(
    'input_value,expected_outcome',
    [
        (result_list[0], EXPECTED_LIST[0]),
        (result_list[1], EXPECTED_LIST[1]),
        (result_list[2], EXPECTED_LIST[2]),
        (result_list[3], EXPECTED_LIST[3]),
        (result_list[4], EXPECTED_LIST[4]),
        (result_list[5], EXPECTED_LIST[5]),
        (result_list[6], EXPECTED_LIST[6]),
        (result_list[7], EXPECTED_LIST[7]),
        (result_list[8], EXPECTED_LIST[8]),
        (result_list[9], EXPECTED_LIST[9]),
    ]
)
def test_lenient_lowercase(input_value, expected_outcome):
    """Test that lenient_lowercase() proper results."""
    assert input_value == expected_outcome


@pytest.mark.parametrize('input_data', [1, False, 1.001, 1j, datetime.now(), ])
def test_lenient_lowercase_illegal_data_type(input_data):
    """Test passing objects of illegal types to lenient_lowercase()."""
    with pytest.raises(TypeError, match='object is not iterable'):
        lenient_lowercase(input_data)