2

I have a problem with python configobj. Why is "parameter" (named parameter) from cs added to config during config.validate(validator, preserve_errors=True)?

    def test_MissingSectionError(self):
        cfg = '''
[general]
    name = TestInteractionExample 1

[this_is_not_para_meter]
    [[frequency]]
        default_value = 900
        description = Description of parameter1
'''
        cs = '''
[general]
    name = string
[parameter]
    [[__many__]]
        default_value =
        description =
'''
        cfg_io = StringIO(cfg)
        cs_io = StringIO(cs)
        config = self.parser._get_configobj(cfg_io, cs_io, self.script)
        print 'Before validation: {}'.format(config)            
        validator = Validator()
        results = config.validate(validator, preserve_errors=True)
        print 'After validation: {}'.format(config)
        print 'result: {}'.format(results)

 #       self.assertRaises(MissingSectionError, self.parser._validate_config, config, self.script)

print gives:

Before validation: {u'general': {u'name': u'TestInteractionExample 1'}, u'this_is_not_para_meter': {u'frequency': {u'default_value': u'900', u'description': u'Description of parameter1'}}} After validation: {u'general': {u'name': u'TestInteractionExample 1'}, u'this_is_not_para_meter': {u'frequency': {u'default_value': u'900', u'description': u'Description of parameter1'}}, 'parameter': {}} result: True

Strange that this validates to true, since "parameter" is missing in config. But again if it's added to config in config.validate(validator, preserve_errors=True) then it also becoms true. Maybe there some option that copies missing values from cs to config.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262

0 Answers0