diff --git a/services/config.py b/services/config.py index 59394e2..bf06ade 100644 --- a/services/config.py +++ b/services/config.py @@ -158,6 +158,8 @@ class Config(RawConfigParser): def _extend(self, filename): """Expand the config with another file.""" + if not os.path.isfile(filename): + raise IOError('No such file: %s' % filename) parser = RawConfigParser() parser.read([filename]) for section in parser.sections(): diff --git a/services/tests/test_config.py b/services/tests/test_config.py index f0b9791..cdbc1ff 100644 --- a/services/tests/test_config.py +++ b/services/tests/test_config.py @@ -68,6 +68,14 @@ two = "a" more = stuff """ +_FILE_THREE = """\ +[DEFAULT] +extends = no-no,no-no-no-no,no-no-no-no,theresnolimit + +[one] +foo = bar +""" + class ConfigTestCase(unittest.TestCase): @@ -79,6 +87,7 @@ class ConfigTestCase(unittest.TestCase): f.close() self.file_one = StringIO(_FILE_ONE % filename) self.file_two = filename + self.file_three = StringIO(_FILE_THREE) def tearDown(self): if '__STUFF__' in os.environ: @@ -108,3 +117,8 @@ class ConfigTestCase(unittest.TestCase): # extends self.assertEquals(config.get('three', 'more'), 'stuff') 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)