Better error message when configuration file is missing.

This commit is contained in:
Dan Helfman 2015-09-06 15:55:14 -07:00
parent f54acc9bbf
commit 0da1c6ec7b
3 changed files with 12 additions and 2 deletions

1
NEWS
View File

@ -1,6 +1,7 @@
0.1.7-dev 0.1.7-dev
* #11: Fixed parsing of punctuation in configuration file. * #11: Fixed parsing of punctuation in configuration file.
* Better error message when configuration file is missing.
0.1.6 0.1.6

View File

@ -109,7 +109,8 @@ def parse_configuration(config_filename, config_format):
Raise IOError if the file cannot be read, or ValueError if the format is not as expected. Raise IOError if the file cannot be read, or ValueError if the format is not as expected.
''' '''
parser = RawConfigParser() parser = RawConfigParser()
parser.read(config_filename) if not parser.read(config_filename):
raise ValueError('Configuration file cannot be opened: {}'.format(config_filename))
validate_configuration_format(parser, config_format) validate_configuration_format(parser, config_format)

View File

@ -197,7 +197,7 @@ def test_parse_section_options_for_missing_section_should_return_empty_dict():
def insert_mock_parser(): def insert_mock_parser():
parser = flexmock() parser = flexmock()
parser.should_receive('read') parser.should_receive('read').and_return([flexmock()])
module.RawConfigParser = lambda: parser module.RawConfigParser = lambda: parser
return parser return parser
@ -220,3 +220,11 @@ def test_parse_configuration_should_return_section_configs():
parsed_config = module.parse_configuration('filename', config_format) parsed_config = module.parse_configuration('filename', config_format)
assert parsed_config == type(parsed_config)(*mock_section_configs) assert parsed_config == type(parsed_config)(*mock_section_configs)
def test_parse_configuration_with_file_open_error_should_raise():
parser = insert_mock_parser()
parser.should_receive('read').and_return([])
with assert_raises(ValueError):
module.parse_configuration('filename', config_format=flexmock())