Debian Codegraph @

test/units/plugins/lookup/test_ini.py

raw
1 # -*- coding: utf-8 -*-
2 # (c) 2015, Toshio Kuratomi <[email protected]>
3 #
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18
19 from __future__ import annotations
20
21 import unittest
22 from ansible.plugins.lookup.ini import _parse_params
23
24
25 class TestINILookup(unittest.TestCase):
26
27 # Currently there isn't a new-style
28 old_style_params_data = (
29 # Simple case
30 dict(
31 term=u'keyA section=sectionA file=/path/to/file',
32 expected=[u'file=/path/to/file', u'keyA', u'section=sectionA'],
33 ),
34 dict(
35 term=u'keyB section=sectionB with space file=/path/with/embedded spaces and/file',
36 expected=[u'file=/path/with/embedded spaces and/file', u'keyB', u'section=sectionB with space'],
37 ),
38 dict(
39 term=u'keyC section=sectionC file=/path/with/equals/cn=com.ansible',
40 expected=[u'file=/path/with/equals/cn=com.ansible', u'keyC', u'section=sectionC'],
41 ),
42 dict(
43 term=u'keyD section=sectionD file=/path/with space and/equals/cn=com.ansible',
44 expected=[u'file=/path/with space and/equals/cn=com.ansible', u'keyD', u'section=sectionD'],
45 ),
46 dict(
47 term=u'keyE section=sectionE file=/path/with/unicode/くらとみ/file',
48 expected=[u'file=/path/with/unicode/くらとみ/file', u'keyE', u'section=sectionE'],
49 ),
50 dict(
51 term=u'keyF section=sectionF file=/path/with/utf 8 and spaces/くらとみ/file',
52 expected=[u'file=/path/with/utf 8 and spaces/くらとみ/file', u'keyF', u'section=sectionF'],
53 ),
54 )
55
56 def test_parse_parameters(self):
57 pvals = {'file': '', 'section': '', 'key': '', 'type': '', 're': '', 'default': '', 'encoding': ''}
58 for testcase in self.old_style_params_data:
59 # print(testcase)
60 params = _parse_params(testcase['term'], pvals)
61 params.sort()
62 self.assertEqual(params, testcase['expected'])