summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzyman <devnull@localhost>2009-11-22 20:57:42 +0000
committerfuzzyman <devnull@localhost>2009-11-22 20:57:42 +0000
commit2bf6e775318876cf005daff71b4412e1d95e9761 (patch)
tree64e5fa3e4f4310361310ecc0415dc4488da99eca
parent6d08538dd474a918a5ff09f66ba2b5b291519fcb (diff)
downloadconfigobj-2bf6e775318876cf005daff71b4412e1d95e9761.tar.gz
Test additions.
-rw-r--r--configobj.py33
-rw-r--r--docs/configobj.txt15
-rw-r--r--functionaltests/__init__.py0
-rw-r--r--functionaltests/conf.ini10
-rw-r--r--functionaltests/conf.spec13
-rw-r--r--functionaltests/test_validate_errors.py51
6 files changed, 111 insertions, 11 deletions
diff --git a/configobj.py b/configobj.py
index 7377cc9..10f4759 100644
--- a/configobj.py
+++ b/configobj.py
@@ -1180,21 +1180,44 @@ class ConfigObj(Section):
}
- def __init__(self, infile=None, options=None, _inspec=False, **kwargs):
+ def __init__(self, infile=None, options=None, configspec=None, encoding=None,
+ interpolation=True, raise_errors=False, list_values=True,
+ create_empty=False, file_error=False, stringify=True,
+ indent_type=None, default_encoding=None, unrepr=False,
+ write_empty_values=False, _inspec=False):
"""
Parse a config file or create a config file object.
- ``ConfigObj(infile=None, options=None, **kwargs)``
+ ``ConfigObj(infile=None, configspec=None, encoding=None,
+ interpolation=True, raise_errors=False, list_values=True,
+ create_empty=False, file_error=False, stringify=True,
+ indent_type=None, default_encoding=None, unrepr=False,
+ write_empty_values=False, _inspec=False)``
"""
self._inspec = _inspec
# init the superclass
Section.__init__(self, self, 0, self)
infile = infile or []
+ if options is not None:
+ import warnings
+ warnings.warn('Passing in an options dictionary to ConfigObj() is ',
+ 'deprecated. Use **options instead.',
+ DeprecationWarning, stacklevel=2)
+
+ _options = {'configspec': configspec,
+ 'encoding': encoding, 'interpolation': interpolation,
+ 'raise_errors': raise_errors, 'list_values': list_values,
+ 'create_empty': create_empty, 'file_error': file_error,
+ 'stringify': stringify, 'indent_type': indent_type,
+ 'default_encoding': default_encoding, 'unrepr': unrepr,
+ 'write_empty_values': write_empty_values}
+
options = dict(options or {})
-
- # keyword arguments take precedence over an options dictionary
- options.update(kwargs)
+ options.update(_options)
+
+ # XXXX this ignores an explicit list_values = True in combination
+ # with _inspec. The user should *never* do that anyway, but still...
if _inspec:
options['list_values'] = False
diff --git a/docs/configobj.txt b/docs/configobj.txt
index 86bb889..0d1ee75 100644
--- a/docs/configobj.txt
+++ b/docs/configobj.txt
@@ -2289,17 +2289,20 @@ From version 4 it lists all releases and changes.
* Minimum supported version of Python is now 2.3
* ~25% performance improvement thanks to Christian Heimes
-* String interpolation now works in list values
+* String interpolation now works in list value members
* After validation any additional entries not in the configspec are listed in
- the 'extra_values' section member
+ the ``extra_values`` section member
+* Deprecated the use of the ``options`` dictionary in the ConfigObj constructor
+ and added explicit keyword arguments instead
* BUGFIX: Checks that failed validation would not populate 'default_values' and
'restore_default_value' wouldn't work for those entries
* BUGFIX: clear() clears 'defaults'
* BUGFIX: empty values in list values were accidentally valid syntax. They now
- raise a ParseError. e.g. "value = 1, , 2"
-* If a section specified in a configspec is missing, or all the values in a
- section are missing, will have False for all the values in the result
- returned by by ``ConfigObj.validate``
+ raise a ``ParseError``. e.g. "value = 1, , 2"
+* BUGFIX: Change to the result of a call to ``validate`` when ``preserve_errors``
+ is True. Previously sections where *all* values failed validation would
+ return False for the section rather than preserving the errors. False will
+ now only be returned for a section if it is missing
* Distribution includes version 1.0.1 of validate.py
* Removed __revision__ and __docformat__
diff --git a/functionaltests/__init__.py b/functionaltests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/functionaltests/__init__.py
diff --git a/functionaltests/conf.ini b/functionaltests/conf.ini
new file mode 100644
index 0000000..aa429ff
--- /dev/null
+++ b/functionaltests/conf.ini
@@ -0,0 +1,10 @@
+
+extra = 3
+
+[extra-section]
+
+[section]
+ [[sub-section]]
+ extra = 3
+ [[extra-sub-section]]
+ extra = 3
diff --git a/functionaltests/conf.spec b/functionaltests/conf.spec
new file mode 100644
index 0000000..3af70ac
--- /dev/null
+++ b/functionaltests/conf.spec
@@ -0,0 +1,13 @@
+
+value = integer
+
+[section]
+ value = integer
+
+ [[sub-section]]
+ value = integer
+ [[missing-subsection]]
+ value = integer
+
+[missing-section]
+ value = integer
diff --git a/functionaltests/test_validate_errors.py b/functionaltests/test_validate_errors.py
new file mode 100644
index 0000000..06f855b
--- /dev/null
+++ b/functionaltests/test_validate_errors.py
@@ -0,0 +1,51 @@
+import os
+import unittest
+from configobj import ConfigObj
+from validate import Validator
+
+thisdir = os.path.dirname(os.path.join(os.getcwd(), __file__))
+inipath = os.path.join(thisdir, 'conf.ini')
+specpath = os.path.join(thisdir, 'conf.spec')
+
+
+class TestValidateErrors(unittest.TestCase):
+
+ def test_validate_no_valid_entries(self):
+ conf = ConfigObj(inipath, configspec=specpath)
+
+ validator = Validator()
+ result = conf.validate(validator)
+ self.assertFalse(result)
+
+
+ def test_validate_preserve_errors(self):
+ conf = ConfigObj(inipath, configspec=specpath)
+
+ validator = Validator()
+ result = conf.validate(validator, preserve_errors=True)
+
+ self.assertFalse(result['value'])
+ self.assertFalse(result['missing-section'])
+
+ section = result['section']
+ self.assertFalse(section['value'])
+ self.assertFalse(section['sub-section']['value'])
+ self.assertFalse(section['missing-subsection'])
+
+
+ def test_validate_extra_values(self):
+ conf = ConfigObj(inipath, configspec=specpath)
+ conf.validate(Validator(), preserve_errors=True)
+
+ self.assertEqual(conf.extra_values, ['extra', 'extra-section'])
+
+ self.assertEqual(conf['section'].extra_values, ['extra-sub-section'])
+ self.assertEqual(conf['section']['sub-section'].extra_values,
+ ['extra'])
+
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()