File: test_config.py

package info (click to toggle)
python-hacking 0.11.0-2.1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 304 kB
  • sloc: python: 911; sh: 30; makefile: 22
file content (58 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download | duplicates (6)
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
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import fixtures

from hacking import config
from hacking import tests


TEST_TOX_INI = """[hacking]
option_1 = val_1
option_2 =
    val_2
option_3 =
    val_1,val_2, val_3,
    val_4 , val_5 , val_6,
    val_7
    ,
     val_8
     val_9
"""


class ConfigTest(tests.TestCase):
    def setUp(self):
        tox_ini_path = os.path.join(self.useFixture(fixtures.TempDir()).path,
                                    'tox.ini')

        with open(tox_ini_path, 'w') as tox_ini:
            tox_ini.write(TEST_TOX_INI)
        self.conf = config.Config('hacking', tox_ini_path)
        super(ConfigTest, self).setUp()

    def test_get(self):
        self.assertEqual('val_1', self.conf.get('option_1'))
        self.assertEqual('val_2', self.conf.get('option_2'))
        self.assertEqual('val_3', self.conf.get('option_4', default='val_3'))

    def test_get_multiple(self):
        self.assertEqual(['val_1', 'val_2', 'val_3', 'val_4', 'val_5', 'val_6',
                          'val_7', 'val_8', 'val_9'],
                         self.conf.get_multiple('option_3'))

        self.assertEqual(['val_1', 'val_2'],
                         self.conf.get_multiple('option_4',
                                                default=['val_1', 'val_2']))