# 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 . 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()