1# -*- coding: utf-8 -*- 2# Copyright (c) 2019 Ansible Project 3# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 4 5from __future__ import absolute_import, division, print_function 6__metaclass__ = type 7 8import pytest 9 10from ansible.module_utils._text import to_native 11from ansible.module_utils.common.validation import check_type_str 12 13 14TEST_CASES = ( 15 ('string', 'string'), 16 (100, '100'), 17 (1.5, '1.5'), 18 ({'k1': 'v1'}, "{'k1': 'v1'}"), 19 ([1, 2, 'three'], "[1, 2, 'three']"), 20 ((1, 2,), '(1, 2)'), 21) 22 23 24@pytest.mark.parametrize('value, expected', TEST_CASES) 25def test_check_type_str(value, expected): 26 assert expected == check_type_str(value) 27 28 29@pytest.mark.parametrize('value, expected', TEST_CASES[1:]) 30def test_check_type_str_no_conversion(value, expected): 31 with pytest.raises(TypeError) as e: 32 check_type_str(value, allow_conversion=False) 33 assert 'is not a string and conversion is not allowed' in to_native(e.value) 34