def _conf_dict_to_config(conf_dict: dict) -> Config:
    """Convert config dict to a Config object"""
    config = Config(sections=[
        ConfigSection(name=section,
                      options=[
                          ConfigOption(key=key, value=value)
                          for key, value in options.items()
                      ]) for section, options in conf_dict.items()
    ])
    return config
Esempio n. 2
0
 def test_serialize(self):
     config = Config(sections=[
         ConfigSection(
             name='sec1',
             options=[
                 ConfigOption(key='apache', value='airflow'),
                 ConfigOption(key='hello', value='world'),
             ],
         ),
         ConfigSection(name='sec2',
                       options=[
                           ConfigOption(key='foo', value='bar'),
                       ]),
     ])
     result = config_schema.dump(config)
     expected = {
         'sections': [
             {
                 'name':
                 'sec1',
                 'options': [
                     {
                         'key': 'apache',
                         'value': 'airflow'
                     },
                     {
                         'key': 'hello',
                         'value': 'world'
                     },
                 ],
             },
             {
                 'name': 'sec2',
                 'options': [
                     {
                         'key': 'foo',
                         'value': 'bar'
                     },
                 ]
             },
         ]
     }
     assert result == expected