Jelajahi Sumber

#11: Fixed parsing of punctuation in configuration file.

Dan Helfman 9 tahun lalu
induk
melakukan
f54acc9bbf

+ 4 - 0
NEWS

@@ -1,3 +1,7 @@
+0.1.7-dev
+
+ * #11: Fixed parsing of punctuation in configuration file.
+
 0.1.6
 0.1.6
 
 
  * #9: New configuration option for the encryption passphrase.
  * #9: New configuration option for the encryption passphrase.

+ 5 - 5
atticmatic/config.py

@@ -2,10 +2,10 @@ from collections import OrderedDict, namedtuple
 
 
 try:
 try:
     # Python 2
     # Python 2
-    from ConfigParser import ConfigParser
+    from ConfigParser import RawConfigParser
 except ImportError:
 except ImportError:
     # Python 3
     # Python 3
-    from configparser import ConfigParser
+    from configparser import RawConfigParser
 
 
 
 
 Section_format = namedtuple('Section_format', ('name', 'options'))
 Section_format = namedtuple('Section_format', ('name', 'options'))
@@ -22,7 +22,7 @@ def option(name, value_type=str, required=True):
 
 
 def validate_configuration_format(parser, config_format):
 def validate_configuration_format(parser, config_format):
     '''
     '''
-    Given an open ConfigParser and an expected config file format, validate that the parsed
+    Given an open RawConfigParser and an expected config file format, validate that the parsed
     configuration file has the expected sections, that any required options are present in those
     configuration file has the expected sections, that any required options are present in those
     sections, and that there aren't any unexpected options.
     sections, and that there aren't any unexpected options.
 
 
@@ -83,7 +83,7 @@ def validate_configuration_format(parser, config_format):
 
 
 def parse_section_options(parser, section_format):
 def parse_section_options(parser, section_format):
     '''
     '''
-    Given an open ConfigParser and an expected section format, return the option values from that
+    Given an open RawConfigParser and an expected section format, return the option values from that
     section as a dict mapping from option name to value. Omit those options that are not present in
     section as a dict mapping from option name to value. Omit those options that are not present in
     the parsed options.
     the parsed options.
 
 
@@ -108,7 +108,7 @@ 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 = ConfigParser()
+    parser = RawConfigParser()
     parser.read(config_filename)
     parser.read(config_filename)
 
 
     validate_configuration_format(parser, config_format)
     validate_configuration_format(parser, config_format)

+ 29 - 0
atticmatic/tests/integration/test_config.py

@@ -0,0 +1,29 @@
+try:
+    # Python 2
+    from cStringIO import StringIO
+except ImportError:
+    # Python 3
+    from io import StringIO
+
+from collections import OrderedDict
+import string
+
+from atticmatic import config as module
+
+
+def test_parse_section_options_with_punctuation_should_return_section_options():
+    parser = module.RawConfigParser()
+    parser.readfp(StringIO('[section]\nfoo: {}\n'.format(string.punctuation)))
+
+    section_format = module.Section_format(
+        'section',
+        (module.Config_option('foo', str, required=True),),
+    )
+
+    config = module.parse_section_options(parser, section_format)
+
+    assert config == OrderedDict(
+        (
+            ('foo', string.punctuation),
+        )
+    )

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

@@ -198,7 +198,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')
-    module.ConfigParser = lambda: parser
+    module.RawConfigParser = lambda: parser
 
 
     return parser
     return parser
 
 

+ 1 - 1
setup.py

@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 from setuptools import setup, find_packages
 
 
 
 
-VERSION = '0.1.6'
+VERSION = '0.1.7-dev'
 
 
 
 
 setup(
 setup(