示例#1
0
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')
示例#2
0
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)
示例#3
0
文件: scripts.py 项目: Dcoldei/TFG
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)
示例#4
0
def test_config_get_no_default():
    pyconfig.Config().get('get_no_default2', None, allow_default=False)
示例#5
0
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')
示例#6
0
def test_config_update_skip_namespace_class():
    conf = pyconfig.Config()
    conf.settings = {}
    conf._update({'Namespace': pyconfig.Namespace})
    eq_(conf.settings, {})
示例#7
0
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')
示例#8
0
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)