aboutsummaryrefslogtreecommitdiffstats
path: root/confparser/confparser_test.py
blob: d5044f26c32e59154e5c4573726a1514a8775a7a (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
#!python3

import tempfile
import confparser

def parse_test():
    msg = '''\
# comment with ":" and "=" in it: :=
a= Test

  # another comment with space and := tada
b = "Test of a long string"

# third comment
c=What do YOU want ? ''
d = value with a squote at the end '
e = value with a dquote at the end "
f = "value with a \\" inside"
x.y.z = there you can have a full tree of parameters
'''
    with tempfile.NamedTemporaryFile(mode='w', encoding='utf8') as f:
        f.write(msg)
        print('Following lines have been written to the file:')
        print('-'*40)
        print(msg)
        print('-'*40)
        f.flush()
        dic = confparser.read_conf(f.name)
    print('read dic:', dic)
    dictest = {
        'a': 'Test',
        'b': 'Test of a long string',
        'c': "What do YOU want ? ''",
        'd': 'value with a squote at the end \'',
        'e': 'value with a dquote at the end "',
        'f': 'value with a " inside',
        'x.y.z': 'there you can have a full tree of parameters',
    }
    if dic != dictest:
        a = set(dictest.keys())
        b = set(dic.keys())
        if a != b:
            diff = a.difference(b).union(b.difference(a))
            raise Exception('not same keys between two dicts:', diff)
        a = set(dictest.values())
        b = set(dic.values())
        if a != b:
            diff = a.difference(b).union(b.difference(a))
            raise Exception('differences between two set of values:', diff)