فهرست منبع

Better error message when configuration file is missing.

Dan Helfman 9 سال پیش
والد
کامیت
0da1c6ec7b
3فایلهای تغییر یافته به همراه12 افزوده شده و 2 حذف شده
  1. 1 0
      NEWS
  2. 2 1
      atticmatic/config.py
  3. 9 1
      atticmatic/tests/unit/test_config.py

+ 1 - 0
NEWS

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

+ 2 - 1
atticmatic/config.py

@@ -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.
     '''
     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)
 

+ 9 - 1
atticmatic/tests/unit/test_config.py

@@ -197,7 +197,7 @@ def test_parse_section_options_for_missing_section_should_return_empty_dict():
 
 def insert_mock_parser():
     parser = flexmock()
-    parser.should_receive('read')
+    parser.should_receive('read').and_return([flexmock()])
     module.RawConfigParser = lambda: parser
 
     return parser
@@ -220,3 +220,11 @@ def test_parse_configuration_should_return_section_configs():
     parsed_config = module.parse_configuration('filename', config_format)
 
     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())