diff options
author | fuzzyman <devnull@localhost> | 2009-11-22 00:26:51 +0000 |
---|---|---|
committer | fuzzyman <devnull@localhost> | 2009-11-22 00:26:51 +0000 |
commit | d9b3ecc236db2554482a88bc9502d95d983c6765 (patch) | |
tree | d9a801bf206c548ef0db41b7b546db84ddc928e5 | |
parent | b59bb23a1c50862cb8e299f5afec2bf2068e8ce4 (diff) | |
download | configobj-d9b3ecc236db2554482a88bc9502d95d983c6765.tar.gz |
Fixed problem with missing sections and preserve_errors with validation.
-rw-r--r-- | configobj.py | 30 | ||||
-rw-r--r-- | test_configobj.py | 27 |
2 files changed, 30 insertions, 27 deletions
diff --git a/configobj.py b/configobj.py index 91f6594..90ad469 100644 --- a/configobj.py +++ b/configobj.py @@ -2245,10 +2245,11 @@ class ConfigObj(Section): ret_true = False section.extra_values = unvalidated - if preserve_errors and section._created: - print 'b00m!' + if preserve_errors and not section._created: ret_false = False # + if ret_false and preserve_errors and out: + ret_false = not any(out.values()) if ret_true: return True elif ret_false: @@ -2394,21 +2395,22 @@ def flatten_errors(cfg, res, levels=None, results=None): >>> for entry in flatten_errors(cfg, res): ... section_list, key, error = entry ... section_list.insert(0, '[root]') - ... section_list.append(key) + ... if key is not None: + ... section_list.append(key) ... section_string = ', '.join(section_list) - ... errors.append((section_string, ' = ', error or 'missing')) + ... errors.append('%s%s%s' % (section_string, ' = ', error or 'missing')) >>> errors.sort() >>> for entry in errors: - ... print entry[0], entry[1], entry[2] - [root], option2 = missing - [root], option3 = the value "Bad_value" is of the wrong type. - [root], section1, option2 = missing - [root], section1, option3 = the value "Bad_value" is of the wrong type. - [root], section2, another_option = the value "Probably" is of the wrong type. - [root], section3, section3b, section3b-sub, value = missing - [root], section3, section3b, value2 = the value "a" is of the wrong type. - [root], section3, section3b, value3 = the value "11" is too big. - [root], section4, another_option = missing + ... print entry + [root], option2 = missing + [root], option3 = the value "Bad_value" is of the wrong type. + [root], section1, option2 = missing + [root], section1, option3 = the value "Bad_value" is of the wrong type. + [root], section2, another_option = the value "Probably" is of the wrong type. + [root], section3, section3b, section3b-sub = missing + [root], section3, section3b, value2 = the value "a" is of the wrong type. + [root], section3, section3b, value3 = the value "11" is too big. + [root], section4 = missing """ if levels is None: # first time called diff --git a/test_configobj.py b/test_configobj.py index dbdc712..7331aa8 100644 --- a/test_configobj.py +++ b/test_configobj.py @@ -1535,21 +1535,22 @@ def _test_validate(): >>> for entry in flatten_errors(cfg, res): ... section_list, key, error = entry ... section_list.insert(0, '[root]') - ... section_list.append(key) + ... if key is not None: + ... section_list.append(key) ... section_string = ', '.join(section_list) - ... errors.append((section_string, ' = ', error or 'missing')) + ... errors.append('%s%s%s' % (section_string, ' = ', error or 'missing')) >>> errors.sort() >>> for entry in errors: - ... print entry[0], entry[1], entry[2] - [root], option2 = missing - [root], option3 = the value "Bad_value" is of the wrong type. - [root], section1, option2 = missing - [root], section1, option3 = the value "Bad_value" is of the wrong type. - [root], section2, another_option = the value "Probably" is of the wrong type. - [root], section3, section3b, section3b-sub, value = missing - [root], section3, section3b, value2 = the value "a" is of the wrong type. - [root], section3, section3b, value3 = the value "11" is too big. - [root], section4, another_option = missing + ... print entry + [root], option2 = missing + [root], option3 = the value "Bad_value" is of the wrong type. + [root], section1, option2 = missing + [root], section1, option3 = the value "Bad_value" is of the wrong type. + [root], section2, another_option = the value "Probably" is of the wrong type. + [root], section3, section3b, section3b-sub = missing + [root], section3, section3b, value2 = the value "a" is of the wrong type. + [root], section3, section3b, value3 = the value "11" is too big. + [root], section4 = missing """ @@ -2110,7 +2111,7 @@ def _test_validation_with_preserve_errors(): >>> spec = ['[section]', 'foo = integer'] >>> c = ConfigObj(configspec=spec) >>> c.validate(v, preserve_errors=True) - False + {'section': False} >>> c = ConfigObj(['[section]'], configspec=spec) >>> c.validate(v) False |