def test_load_from_mapping(self): config = Config() config.from_mapping({'PORT': 5000}) assert config.PORT == 5000
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import import os from easyconfig import Config, yaml_mapping # Initialize config config = Config({ 'COMMANDS_PATH': '', 'ENTRY_POINT': 'main', }) # Override config yaml_filename = os.environ.get('CMDR_CONFIG_YAML') if yaml_filename: config.from_mapping(yaml_mapping(yaml_filename)) # Validate config if not config.COMMANDS_PATH: raise RuntimeError('Configuration `COMMANDS_PATH` is empty') if not config.ENTRY_POINT: raise RuntimeError('Configuration `ENTRY_POINT` is empty')
from django.conf import settings as django_settings from easyconfig import Config default_settings = { 'PAGE_LOADER': 'confpages.loaders.DefaultLoader', 'TOKEN_EXPIRES': 600 # in seconds } settings = Config(default_settings) # Get the global settings for the confpages app global_settings = getattr(django_settings, 'CONFPAGES', {}) # Validate the global settings assert isinstance(global_settings, dict), \ 'The `CONFPAGES` setting must be a dictionary' difference = set(global_settings.keys()) - set(default_settings.keys()) assert not len(difference), ('The keys %r in the `CONFPAGES` setting are ' 'not supported' % tuple(difference)) # Override the default settings by global ones settings.from_mapping(global_settings)