Home | Trees | Indices | Help |
---|
|
1 # Elisa - Home multimedia server 2 # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 3 # All rights reserved. 4 # 5 # This file is available under one of two license agreements. 6 # 7 # This file is licensed under the GPL version 3. 8 # See "LICENSE.GPL" in the root of this distribution including a special 9 # exception to use Elisa with Fluendo's plugins. 10 # 11 # The GPL part of Elisa is also available under a commercial licensing 12 # agreement from Fluendo. 13 # See "LICENSE.Elisa" in the root directory of this distribution package 14 # for details on that license. 15 16 from twisted.trial import unittest 17 from elisa.core.tests.elisa_test_case import ElisaTestCase 18 19 import os 20 from elisa.core import config 21 from elisa.core import log 2224 25 test_conf = "test.conf" 26 27 test_section_dict = {'test_list':['some','list'], 28 'test_int': 0, 'test_bool_t': True, 29 'test_bool_f': False, 30 'test_str': 'foobar'} 31 37 43 4714449 """ Fill a 'tests' section in the config 50 """ 51 c.set_section('tests') 52 c.set_option('test_list',['some','list'], section='tests') 53 c.set_option('test_int', 0, section='tests') 54 c.set_option('test_bool_t', True, section='tests') 55 c.set_option('test_bool_f', False, section='tests') 56 c.set_option('test_str', 'foobar', section='tests')5759 """ Create a dumb config file containing formatting errors and 60 check errors are reported. 61 """ 62 data="""\ 63 [general] 64 65 foo=['bar' 66 """ 67 f = open('malformed.conf','w') 68 f.write(data) 69 f.close() 70 71 self.assertRaises(Exception, config.Config, 'malformed.conf') 72 os.unlink('malformed.conf')7375 """ Load test config, write it, load dumped config and compare 76 the two instances. 77 """ 78 c1 = self.load_config() 79 self.set_test_section(c1) 80 c1.write() 81 82 c2 = self.load_config() 83 self.assertEqual(c1.as_dict(), c2.as_dict())8486 """ Test tuple and list option types 87 """ 88 c = self.load_config() 89 90 self.assertEqual(c.get_option('resolution'), None) 91 92 self.set_test_section(c) 93 self.assertEqual(c.get_option('test_list', section='tests'), 94 ['some','list']) 95 c.write()9698 """ Test integer option type 99 """ 100 c = self.load_config() 101 self.set_test_section(c) 102 self.assertEqual(c.get_option('test_int', section='tests'), 0)103105 c = self.load_config() 106 self.set_test_section(c) 107 self.assertEqual(c.get_option('test_bool_t', section='tests'), True) 108 self.assertEqual(c.get_option('test_bool_f', section='tests'), False)109 110112 """ Test string option type 113 """ 114 c = self.load_config() 115 self.set_test_section(c) 116 self.assertEqual(c.get_option('test_str', section='tests'), 'foobar')117119 """ Check the whole tests section dumped as a dictionnary 120 """ 121 c = self.load_config() 122 self.set_test_section(c) 123 self.assertEqual(c.get_section('tests'), 124 self.test_section_dict)125127 """ Test section removal 128 """ 129 c = self.load_config() 130 self.set_test_section(c) 131 132 c.del_section('tests') 133 self.assert_('tests' not in c.as_dict().keys())134136 """ Test option removal 137 """ 138 c = self.load_config() 139 self.set_test_section(c) 140 141 for opt_name in self.test_section_dict.keys(): 142 c.del_option(opt_name,'tests') 143 self.assertEqual(c.get_option(opt_name,'tests'), None)
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Wed Jan 16 19:10:30 2008 | http://epydoc.sourceforge.net |