Debian Codegraph @

test/units/module_utils/common/text/converters/test_jsonify.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright 2019, Andrew Klychkov @Andersson007 <[email protected]>
3 # Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
4
5 from __future__ import annotations
6
7 import pytest
8
9 from ansible.module_utils import _internal
10 from ansible.module_utils.common.text.converters import jsonify
11
12
13 @pytest.mark.parametrize(
14 'test_input,expected',
15 [
16 (1, '1'),
17 ('string', '"string"'),
18 ('くらとみ', '"\\u304f\\u3089\\u3068\\u307f"'),
19 ('café', '"caf\\u00e9"'),
20 pytest.param(b'string', '"string"', marks=pytest.mark.skipif(_internal.is_controller, reason="bytes not supported by controller")),
21 (False, 'false'),
22 pytest.param('string'.encode('utf-8'), '"string"', marks=pytest.mark.skipif(_internal.is_controller, reason="bytes not supported by controller")),
23 ]
24 )
25 def test_jsonify(test_input, expected):
26 """Test for jsonify()."""
27 assert jsonify(test_input) == expected