aboutsummaryrefslogtreecommitdiff
path: root/test/test_config/test_sections.py
blob: 2ca7e4fcf86489688e7a35fc9df813471ae50dce (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
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
# Copyright (C) 2010  Leonard Thomas
#
# This file is part of Dodai.
#
# Dodai is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Dodai is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Dodai.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os
import unittest
path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.append(path)
from dodai.config.sections import ConfigSections
from dodai.tools.himo import Himo
from dodai.tools.himo import String2Himo
from dodai.tools.odict import OrderedDict
from dodai.tools import Section

class Parser(object):

    DATA = OrderedDict()
    DATA['sec_a'] = OrderedDict()
    DATA['sec_a']['opt_a'] = 'foo'
    DATA['sec_a']['opt_b'] = 'bar'
    DATA['sec_a']['opt_c'] = '1'
    DATA['sec_a']['opt_d'] = '22'

    DATA['sec_b'] = OrderedDict()
    DATA['sec_b']['opt_a'] = 'lt'
    DATA['sec_b']['opt_b'] = 'el'
    DATA['sec_b']['opt_c'] = 'mg'
    DATA['sec_b']['opt_d'] = 'ds'

    def sections(self):
        return self.DATA.keys()

    def options(self, section):
        return self.DATA[section].keys()

    def get(self, section, option):
        return self.DATA[section][option]


class TestSections(unittest.TestCase):

    def setUp(self):
        s2h = String2Himo()
        self.obj = ConfigSections(OrderedDict, Section, s2h)
        self.parser = Parser()

    def test_call(self):
        self.obj(self.parser)

    def test_two(self):
        self.obj(self.parser)
        key = String2Himo('sec_a')
        self.obj.__getitem__('sec_a')
        self.obj.sec_a

    def test_results_one(self):
        self.obj(self.parser)
        for section in self.obj.keys():
            self.assertTrue(section in self.parser.sections())

    def test_results_two(self):
        self.obj(self.parser)
        for section, data in self.obj.items():
            for key in data.keys():
                self.assertTrue(key in self.parser.options(section))

    def test_results_three(self):
        self.obj(self.parser)
        for section, data in self.obj.items():
            for option, val in data.items():
                self.assertTrue(val, self.parser.get(section, option))

    def test_results_four(self):
        self.obj(self.parser)
        for section in self.parser.sections():
            self.assertTrue(section in self.obj)

    def test_results_five(self):
        self.obj(self.parser)
        for section in self.parser.sections():
            for option in self.parser.options(section):
                self.assertTrue(option in self.obj[section])

    def test_results_six(self):
        self.obj(self.parser)
        for section in self.parser.sections():
            for option in self.parser.options(section):
                val = self.parser.get(section, option)
                self.assertEquals(val, self.obj[section][option])



if __name__ == '__main__':
    unittest.main()