updated readconf test

This commit is contained in:
John Dickinson 2010-10-08 14:47:40 -05:00
parent 4111a16189
commit 8ee2cbaeee

View File

@ -252,26 +252,29 @@ class TestUtils(unittest.TestCase):
foo = bar
[section2]
log_name = yarr
'''
result = utils.readconf(StringIO(conf))
log_name = yarr'''
f = open('/tmp/test', 'wb')
f.write(conf)
f.close()
result = utils.readconf('/tmp/test')
expected = {'section1': {'foo': 'bar'}, 'section2': {'log_name': 'yarr'}}
self.assertEquals(result, expected)
result = utils.readconf(StringIO(conf), 'section1')
result = utils.readconf('/tmp/test', 'section1')
expected = {'foo': 'bar'}
self.assertEquals(result, expected)
result = utils.readconf(StringIO(conf), 'section2').get('log_name')
result = utils.readconf('/tmp/test', 'section2').get('log_name')
expected = 'yarr'
self.assertEquals(result, expected)
result = utils.readconf(StringIO(conf), 'section1').get('log_name')
result = utils.readconf('/tmp/test', 'section1').get('log_name')
expected = 'section1'
self.assertEquals(result, expected)
result = utils.readconf(StringIO(conf), 'section1', log_name='foo').get('log_name')
result = utils.readconf('/tmp/test', 'section1', log_name='foo').get('log_name')
expected = 'foo'
self.assertEquals(result, expected)
result = utils.readconf(StringIO(conf), 'section1', defaults={'bar': 'baz'})
result = utils.readconf('/tmp/test', 'section1', defaults={'bar': 'baz'})
expected = {'foo': 'bar', 'bar': 'baz'}
self.assertEquals(result, expected)
os.unlink('/tmp/test')
if __name__ == '__main__':
unittest.main()