def test_config_update_nested_namespace(): conf = pyconfig.Config() conf.settings = {} ns = pyconfig.Namespace() ns.value = 'value' conf._update({'test': ns}, 'ns') eq_(conf.get('ns.test.value', None), 'value')
def test_config_update_sans_private(): conf = pyconfig.Config() conf.settings = {} conf._update({'_test_private': 'private', 'other': 'nonprivate'}, 'ns') eq_(conf.settings, {'ns.other': 'nonprivate'}) eq_(conf.get('ns.other', None), 'nonprivate') eq_(conf.get('ns._test_private', None), None)
def _parse_and_output(filename, args): """ Parse `filename` appropriately and then output calls according to the `args` specified. :param filename: A file or directory :param args: Command arguments :type filename: str """ relpath = os.path.dirname(filename) if os.path.isfile(filename): calls = _parse_file(filename, relpath) elif os.path.isdir(filename): calls = _parse_dir(filename, relpath) else: # XXX(shakefu): This is an error of some sort, maybe symlinks? # Probably need some thorough testing _error("Could not determine file type: %r", filename) if not calls: # XXX(shakefu): Probably want to change this to not be an error and # just be a normal fail (e.g. command runs, no output). _error("No pyconfig calls.") if args.load_configs: # We want to iterate over the configs and add any keys which haven't # already been found keys = set() for call in calls: keys.add(call.key) # Iterate the loaded keys and make _PyconfigCall instances conf = pyconfig.Config() for key, value in conf.settings.items(): if key in keys: continue calls.append(_PyconfigCall('set', key, value, [None] * 4)) _output(calls, args)
def test_config_get_no_default(): pyconfig.Config().get('get_no_default2', None, allow_default=False)
def test_config_update_callable(): conf = pyconfig.Config() conf.settings = {} call = lambda: 'value' conf._update({'test_callable': call}, 'ns') eq_(conf.get('ns.test_callable', None), 'value')
def test_config_update_skip_namespace_class(): conf = pyconfig.Config() conf.settings = {} conf._update({'Namespace': pyconfig.Namespace}) eq_(conf.settings, {})
def test_config_update(): conf = pyconfig.Config() conf.settings = {} conf._update({'test_config_update': 'test_value'}, 'ns') eq_(conf.settings, {'ns.test_config_update': 'test_value'}) eq_(conf.get('ns.test_config_update', None), 'test_value')
def test_autoloading_etcd_config_works(): pyconfig.Config().clear() pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2') pyconfig.reload() eq_(pyconfig.get('pyconfig.string'), 'Value') eq_(pyconfig.get('pyconfig.number'), 2)