summaryrefslogtreecommitdiff
path: root/functionaltests/test_configobj.py
blob: 73ecf25d4b397784b8cc661f1dd580622e51acd1 (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
from __future__ import with_statement

import os
import unittest
from configobj import ConfigObj

from warnings import catch_warnings


class TestConfigObj(unittest.TestCase):
    
    def test_order_preserved(self):
        c = ConfigObj()
        c['a'] = 1
        c['b'] = 2
        c['c'] = 3
        c['section'] = {}
        c['section']['a'] = 1
        c['section']['b'] = 2
        c['section']['c'] = 3
        c['section']['section'] = {}
        c['section']['section2'] = {}
        c['section']['section3'] = {}
        c['section2'] = {}
        c['section3'] = {}
        
        c2 = ConfigObj(c)
        self.assertEqual(c2.scalars, ['a', 'b', 'c'])
        self.assertEqual(c2.sections, ['section', 'section2', 'section3'])
        self.assertEqual(c2['section'].scalars, ['a', 'b', 'c'])
        self.assertEqual(c2['section'].sections, ['section', 'section2', 'section3'])
        
        self.assertFalse(c['section'] is c2['section'])
        self.assertFalse(c['section']['section'] is c2['section']['section'])
    
    def test_options_deprecation(self):
        with catch_warnings(record=True) as log:
            ConfigObj(options={})
        
        # unpack the only member of log
        warning, = log
        self.assertEqual(warning.category, DeprecationWarning)
    
    def test_list_members(self):
        c = ConfigObj()
        c['a'] = []
        c['a'].append('foo')
        self.assertEqual(c['a'], ['foo'])
    
    def test_list_interpolation_with_pop(self):
        c = ConfigObj()
        c['a'] = []
        c['a'].append('%(b)s')
        c['b'] = 'bar'
        self.assertEqual(c.pop('a'), ['bar'])