File: test_config.py

package info (click to toggle)
python-easydev 0.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 504 kB
  • sloc: python: 2,130; javascript: 49; makefile: 13
file content (138 lines) | stat: -rw-r--r-- 2,818 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from easydev.config_tools import ConfigExample, DynamicConfigParser, load_configfile

from easydev import CustomConfig
import os




def test_config_custom():
    c = CustomConfig('dummy')
    c.init()
    c.user_config_dir
    c.remove()


def test_configExample():
    c = ConfigExample().config
    assert 'General' in c.sections()
    assert 'GA' in c.sections()
    print(c)
    c.remove_section('General')


def test_ordered_dict_attribute():
    # disabled because incompatible with python 3
    c = DynamicConfigParser()
    c.add_section("GA")
    c.GA.test = 2 # this is an attribute only, not  yet a key
    c.add_option("GA", "test", 1)
    c.GA.test = 2
    c['GA']['test'] = 4
    del c['GA']['test']


def test_DynamicConfig():
    c = ConfigExample()
    dc = DynamicConfigParser(c.config)
    dc.save('test.ini')
    dc = DynamicConfigParser('test.ini')
    #dc = DynamicConfigParser(c.config)
    dc._replace_config(c.config)
    dc.GA
    dc.add_option("GA", "bool", 'True')
    dc.get_options("GA")

    os.remove('test.ini')

    dc.remove_section('GA')
    assert 'GA' not in dc.sections()
    print(dc)

    # try something stupid
    try:
        dc = DynamicConfigParser(234)
        assert False
    except TypeError:
        assert True

    dc = DynamicConfigParser()
    try:
        dc.read("test_dummy")
        assert False
    except:
        assert True

def test_DynamicConfigDelete():
    from easydev import ConfigExample
    dcp = DynamicConfigParser(ConfigExample().config)
    try:
        del(dcp["GA"])
        assert dcp.sections() == ['General']
    except:
        pass



def test_DynamicConfig_setter():

    dc = DynamicConfigParser()
    dc.add_section("GA")
    dc.add_option("GA", "test", 1)
    dc.save("test.ini")

    dc2 = DynamicConfigParser("test.ini")
    assert dc == dc2
    dc2.GA.test == 1

    dc.GA.test = 10
    dc.save("test.ini")
    dc2 = DynamicConfigParser("test.ini")
    assert dc == dc2

    assert dc2.GA.test == '10'

    os.remove('test.ini')


def test_section2dict():
    dc = DynamicConfigParser()
    dc.add_section("GA")
    dc.add_option("GA", "test", 1)


def test_compare():

    dc = DynamicConfigParser()
    dc.add_section("GA")
    dc.add_option("GA", "test", 1)

    dc2 = DynamicConfigParser()
    dc2.add_section("GA2")
    dc2.add_option("GA2", "test", 1)

    assert (dc==dc2) == False


    dc = DynamicConfigParser()
    dc.add_section("GA")
    dc.add_option("GA", "test", 1)

    dc2 = DynamicConfigParser()
    dc2.add_section("GA")
    dc2.add_option("GA", "test", 2)

    assert (dc==dc2) == False

    dc = DynamicConfigParser()
    dc.add_section("GA")
    dc.add_option("GA", "test", 1)

    dc2 = DynamicConfigParser()
    dc2.add_section("GA")
    dc2.add_option("GA", "test", 1)

    assert (dc==dc2) == True