How to use the confuse.ConfigSource function in confuse

To help you get started, we’ve selected a few confuse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buluba89 / Yatcobot / tests / config / test_templates.py View on Github external
def test_number_keywords_template(self):
        data = confuse.ConfigSource.of({1: ["test"], 2: 'test'})
        view = confuse.RootView([data])
        view.set(data)
        r = view.get(NumberKeywordsTemplate())

        self.assertDictEqual(r, {1: ["test"], 2: ["test"]})

        self.assertEqual(str(NumberKeywordsTemplate()), 'NumberKeywordsTemplate()')

        view.set(confuse.ConfigSource.of({'not_int': ["test"], 2: 'test'}))
        with self.assertRaises(confuse.ConfigTypeError):
            r = view.get(NumberKeywordsTemplate())
github beetbox / confuse / test / test_valid.py View on Github external
def test_filename_with_file_source(self):
        source = confuse.ConfigSource({'foo': 'foo/bar'},
                                      filename='/baz/config.yaml')
        config = _root(source)
        config.config_dir = lambda: '/config/path'
        valid = config['foo'].get(confuse.Filename())
        self.assertEqual(valid, os.path.realpath('/config/path/foo/bar'))
github beetbox / confuse / test / test_validation.py View on Github external
def test_as_filename_with_default_source(self):
        source = confuse.ConfigSource({'foo': 'foo/bar'},
                                      filename='/baz/config.yaml',
                                      default=True)
        config = _root(source)
        config.config_dir = lambda: '/config/path'
        value = config['foo'].as_filename()
        self.assertEqual(value, os.path.realpath('/config/path/foo/bar'))
github beetbox / confuse / test / test_validation.py View on Github external
def test_as_filename_with_file_source(self):
        source = confuse.ConfigSource({'foo': 'foo/bar'},
                                      filename='/baz/config.yaml')
        config = _root(source)
        config.config_dir = lambda: '/config/path'
        value = config['foo'].as_filename()
        self.assertEqual(value, os.path.realpath('/config/path/foo/bar'))
github buluba89 / Yatcobot / tests / config / test_templates.py View on Github external
def test_number_keywords_template(self):
        data = confuse.ConfigSource.of({1: ["test"], 2: 'test'})
        view = confuse.RootView([data])
        view.set(data)
        r = view.get(NumberKeywordsTemplate())

        self.assertDictEqual(r, {1: ["test"], 2: ["test"]})

        self.assertEqual(str(NumberKeywordsTemplate()), 'NumberKeywordsTemplate()')

        view.set(confuse.ConfigSource.of({'not_int': ["test"], 2: 'test'}))
        with self.assertRaises(confuse.ConfigTypeError):
            r = view.get(NumberKeywordsTemplate())
github beetbox / confuse / test / __init__.py View on Github external
def _root(*sources):
    return confuse.RootView([confuse.ConfigSource.of(s) for s in sources])
github beetbox / confuse / test / test_valid.py View on Github external
def test_filename_with_default_source(self):
        source = confuse.ConfigSource({'foo': 'foo/bar'},
                                      filename='/baz/config.yaml',
                                      default=True)
        config = _root(source)
        config.config_dir = lambda: '/config/path'
        valid = config['foo'].get(confuse.Filename())
        self.assertEqual(valid, os.path.realpath('/config/path/foo/bar'))
github buluba89 / Yatcobot / yatcobot / config / __init__.py View on Github external
def load(filename=None):
        """
        Loads a file and imports the settings
        :param filename: the file to import
        """
        config = confuse.LazyConfig('Yatcobot', __name__)

        # Add default config when in egg (using this way because egg is breaking the default way)
        if len(config.sources) == 0:
            default_config_text = pkg_resources.resource_string("yatcobot.config", "config_default.yaml")
            default_config = confuse.ConfigSource(yaml.load(default_config_text, Loader=confuse.Loader),
                                                  'pkg/config/config_default.yaml',
                                                  True)
            config.add(default_config)

        # Add user specified config
        if filename is not None and os.path.isfile(filename):
            config.set_file(filename)

        logger.info('Loading config files (From highest priority to lowest):')
        config.resolve()
        for i, config_source in enumerate(config.sources):
            logger.info('{}: Path: {}'.format(i, config_source.filename))

        # Update template from plugins
        template = Config.get_template()
        Config._valid = config.get(template)