Bug 634728 - refuse to start if "extends" parameter references invalid filename - r=jrconlin

This commit is contained in:
Tarek Ziade 2011-02-18 18:13:09 +01:00
Родитель 9abefe8e08
Коммит f8f59bac67
2 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -158,6 +158,8 @@ class Config(RawConfigParser):
def _extend(self, filename): def _extend(self, filename):
"""Expand the config with another file.""" """Expand the config with another file."""
if not os.path.isfile(filename):
raise IOError('No such file: %s' % filename)
parser = RawConfigParser() parser = RawConfigParser()
parser.read([filename]) parser.read([filename])
for section in parser.sections(): for section in parser.sections():

Просмотреть файл

@ -68,6 +68,14 @@ two = "a"
more = stuff more = stuff
""" """
_FILE_THREE = """\
[DEFAULT]
extends = no-no,no-no-no-no,no-no-no-no,theresnolimit
[one]
foo = bar
"""
class ConfigTestCase(unittest.TestCase): class ConfigTestCase(unittest.TestCase):
@ -79,6 +87,7 @@ class ConfigTestCase(unittest.TestCase):
f.close() f.close()
self.file_one = StringIO(_FILE_ONE % filename) self.file_one = StringIO(_FILE_ONE % filename)
self.file_two = filename self.file_two = filename
self.file_three = StringIO(_FILE_THREE)
def tearDown(self): def tearDown(self):
if '__STUFF__' in os.environ: if '__STUFF__' in os.environ:
@ -108,3 +117,8 @@ class ConfigTestCase(unittest.TestCase):
# extends # extends
self.assertEquals(config.get('three', 'more'), 'stuff') self.assertEquals(config.get('three', 'more'), 'stuff')
self.assertEquals(config.get('one', 'two'), 'a') self.assertEquals(config.get('one', 'two'), 'a')
def test_nofile(self):
# if a user tries to use an inexistant file in extensios,
# pops an error
self.assertRaises(IOError, Config, self.file_three)