Пример #1
0
    def test_generate_include_all(self):
        config = {
            "section": {
                "optiona": {
                    "required": True,
                    "default": 'DA',
                    "value": 'VA'
                },
                "optionb": {
                    "default": 'DB'
                }
            }
        }

        config_parser = generator.generate_config_parser(config)
        options = config_parser.options('section')
        self.assertNotIn('optionb', options)

        config_parser = generator.generate_config_parser(config,
                                                         include_all=True)
        options = config_parser.options('section')
        self.assertIn('optionb', options)

        value = config_parser.get('section', 'optionb')
        self.assertEqual(value, 'DB')
Пример #2
0
 def test_required_default(self):
     config = {"section":
                  {"option":
                      {"required": True, "default": 12}
                  }
              }
     config_parser = generator.generate_config_parser(config)
     value = config_parser.get('section', 'option')
     self.assertEqual(value, '12')
Пример #3
0
    def test_required(self):
        config = {"section": {"option": {"required": True}}}
        config_parser = generator.generate_config_parser(config)
        options = config_parser.options('section')
        self.assertIn('option', options)
        self.assertIn('# required', options)

        value = config_parser.get('section', 'option')
        self.assertEqual(value, 'TO FILL')
Пример #4
0
def migrate(schema_file, config_file):
    '''Migrates a configuration file using a confirm schema.'''

    schema = load_schema_file(open(schema_file, 'r'))
    config = load_config_file(config_file, open(config_file, 'r').read())

    config = append_existing_values(schema, config)

    migrated_config = generate_config_parser(config)
    migrated_config.write(sys.stdout)
Пример #5
0
    def test_generate_include_all(self):
        config = {"section":
                     {"optiona":
                         {"required": True, "default": 'DA',  "value": 'VA'},
                      "optionb":
                         {"default": 'DB'}
                     }
                 }

        config_parser = generator.generate_config_parser(config)
        options = config_parser.options('section')
        self.assertNotIn('optionb', options)

        config_parser = generator.generate_config_parser(config, include_all=True)
        options = config_parser.options('section')
        self.assertIn('optionb', options)

        value = config_parser.get('section', 'optionb')
        self.assertEqual(value, 'DB')
Пример #6
0
def migrate(schema_file, config_file):
    '''Migrates a configuration file using a confirm schema.'''

    schema = load_schema_file(open(schema_file, 'r'))
    config = load_config_file(config_file, open(config_file, 'r').read())

    config = append_existing_values(schema, config)

    migrated_config = generate_config_parser(config)
    migrated_config.write(sys.stdout)
Пример #7
0
    def test_required_default(self):
        config = {"section":
                     {"option":
                         {"required": True, "default": 12, "value": 25}
                     }
                 }
        config_parser = generator.generate_config_parser(config)
        options = config_parser.options('section')
        self.assertIn('option', options)
        self.assertIn('# required', options)

        value = config_parser.get('section', 'option')
        self.assertEqual(value, '25', "We should use the existing value instead of the default!")
Пример #8
0
    def test_required(self):
        config = {"section":
                     {"option":
                         {"required": True}
                     }
                 }
        config_parser = generator.generate_config_parser(config)
        options = config_parser.options('section')
        self.assertIn('option', options)
        self.assertIn('# required', options)

        value = config_parser.get('section', 'option')
        self.assertEqual(value, 'TO FILL')
Пример #9
0
    def test_required_default(self):
        config = {
            "section": {
                "option": {
                    "required": True,
                    "default": 12,
                    "value": 25
                }
            }
        }
        config_parser = generator.generate_config_parser(config)
        options = config_parser.options('section')
        self.assertIn('option', options)
        self.assertIn('# required', options)

        value = config_parser.get('section', 'option')
        self.assertEqual(
            value, '25',
            "We should use the existing value instead of the default!")
Пример #10
0
def generate(schema_file, all_options):
    '''Generates a template configuration file from a confirm schema.'''
    schema = load_schema_file(open(schema_file, 'r'))
    config_parser = generate_config_parser(schema, include_all=all_options)
    config_parser.write(sys.stdout)
Пример #11
0
 def test_empty_config(self):
     config_parser = generator.generate_config_parser({})
     self.assertFalse(len(config_parser.sections()))
Пример #12
0
 def test_required_default(self):
     config = {"section": {"option": {"required": True, "default": 12}}}
     config_parser = generator.generate_config_parser(config)
     value = config_parser.get('section', 'option')
     self.assertEqual(value, '12')
Пример #13
0
 def test_empty_config(self):
     config_parser = generator.generate_config_parser({})
     self.assertFalse(len(config_parser.sections()))
Пример #14
0
def generate(schema_file, all_options):
    '''Generates a template configuration file from a confirm schema.'''
    schema = load_schema_file(open(schema_file, 'r'))
    config_parser = generate_config_parser(schema, include_all=all_options)
    config_parser.write(sys.stdout)