示例#1
0
    def test_cant_dump_custom_types(self):
        # The reason for this is safety.
        class X:
            pass
        conf = Config({ 'x': X() })

        with self.assertRaises(yaml.representer.RepresenterError):
            conf.dump(StringIO())
示例#2
0
    def test_can_save_and_load(self):
        with TestDir() as test_dir:
            schema_low = SchemaBuilder() \
                .add('options', dict) \
                .build()
            schema_mid = SchemaBuilder() \
                .add('desc', lambda: Config(schema=schema_low)) \
                .build()
            schema_top = SchemaBuilder() \
                .add('container', lambda: DictConfig(
                    lambda v: Config(v, schema=schema_mid))) \
                .build()

            source = Config({
                'container': {
                    'elem': {
                        'desc': {
                            'options': {
                                'k': (1, 2, 3),
                                'd': 'asfd',
                            }
                        }
                    }
                }
            }, schema=schema_top)
            p = osp.join(test_dir, 'f.yaml')

            source.dump(p)

            loaded = Config.parse(p, schema=schema_top)

            self.assertTrue(isinstance(
                loaded.container['elem'].desc.options['k'], list))
            loaded.container['elem'].desc.options['k'] = \
                tuple(loaded.container['elem'].desc.options['k'])
            self.assertEqual(source, loaded)