Beispiel #1
0
def test_read():
    '''Test yaml !read tag'''
    with tempfile() as fh:
        fh.write('/usr/local/lib')
        fh.flush()
        assert {'libpath': '/usr/local/lib'} == Config('libpath: !read {}'.
            format(fh.name))
Beispiel #2
0
def test_extra_config_and_config_file(f):
    with tempfile() as fh:
        fh.write(f.conf)
        fh.flush()
        c = Config(args=[f.prog, f.host, '-C="{}"'.format(fh.name),
            '-E="system_path: /tmp/systest"'])
    assert '/tmp/systest' == c.system_path
Beispiel #3
0
def test_include_unknown_key(f):
    '''Test include with a key'''
    conf = 'field: [magnetic, electric]'
    with tempfile() as fh:
        fh.write(conf)
        fh.flush()
        c = Config('photon: !include {}:properties'.format(fh.name))
        assert Odict("photon: ''") == c
Beispiel #4
0
def test_include_tag(f):
    '''Test include with a key'''
    conf = 'field: [magnetic, electric]'
    with tempfile() as fh:
        fh.write(conf)
        fh.flush()
        c = Config('photon: !include {}:field'.format(fh.name))
        assert Odict('photon: [magnetic, electric]') == c
Beispiel #5
0
def test_include_config(f):
    '''Test yaml !include tag loads config'''
    conf = 'field: magnetic'
    with tempfile() as fh:
        fh.write(conf)
        fh.flush()
        c = Config('photon: !include {}'.format(fh.name))
    assert Odict('field: magnetic') == c.photon
Beispiel #6
0
def test_include_config_wont_empty_subkey_lists():
    '''Ensure including a file, even an empty one, will parse lists properly'''
    with tempfile() as fh:  # Create an empty file
        c = Config('''\
                _: !include {}
                test:
                    list: [1, 2]
                '''.format(fh.name))
    assert '{test: {list: [1, 2]}}' == repr(c)
Beispiel #7
0
def test_unexistent_include_config():
    '''Test yaml !include tag ignore unxexistent file'''
    with tempfile() as fh:
        tmpfile = fh.name
    c = Config('''\
            _: !include {}
            test: hi
            '''.format(tmpfile))
    assert '{test: hi}' == repr(c)
Beispiel #8
0
def test_verprog_from_options(f):
    with tempfile() as fh, exc(SystemExit) as e:
        fh.write(f.conf)
        fh.flush()
        Config(types={basename}, args=[f.prog, '-v',
            '-E="prog: {}"'.format(f.prog),
            '-C="{}"'.format(fh.name),
            '-E="version: {}"'.format(f.version)])
    assert '{} {}'.format(f.prog, f.version) == e().args[0]
Beispiel #9
0
def test_unexistent_include__config_wont_empty_subkey_lists():
    '''Ensure including a nonexistent file will parse lists properly'''
    with tempfile() as fh:  # Create a non-existent reference filename
        pass
    c = Config('''\
            _: !include {}
            test:
                list: [1, 2]
            '''.format(fh.name))
    assert '{test: {list: [1, 2]}}' == repr(c)
def test_from_directory(c):
    '''Functional test Config from directory (default on config.conf)'''
    host = 'leon'
    # Place conf in a temporary directory and run test
    with tempfile() as fh:
        fh.write(c.conf)
        fh.flush()
        cmd = '{} -C="{}" {}'.format(c.loadconfig_cmd, fh.name, host)
        ret = run(cmd)
    assert 'export SYSTEM_PATH="/data/salt/system"' in ret.stdout
    assert 'export HOST="{}"'.format(host) in ret.stdout
def test_from_directory(c):
    '''Functional test Config from directory (default on config.conf)'''
    host = 'leon'
    # Place conf in a temporary directory and run test
    with tempfile() as fh:
        fh.write(c.conf)
        fh.flush()
        cmd = '{} -C="{}" {}'.format(c.loadconfig_cmd, fh.name, host)
        ret = run(cmd)
    assert 'export SYSTEM_PATH="/data/salt/system"' in ret.stdout
    assert 'export HOST="{}"'.format(host) in ret.stdout
Beispiel #12
0
def test_expand_unknown_key(f):
    conf = '''\
        properties:
          field:
            - magnetic
            - electric'''
    with tempfile() as fh:
        fh.write(conf)
        fh.flush()
        c = Config('''\
            _: !include {}:&
            photon: !expand properties:viscosity'''.format(fh.name))
        assert Odict("photon: ''") == c
Beispiel #13
0
def test_expand_tag(f):
    conf = '''\
        properties:
          field:
            - magnetic
            - electric'''
    with tempfile() as fh:
        fh.write(conf)
        fh.flush()
        c = Config('''\
            _: !include {}:&
            photon: !expand properties:field'''.format(fh.name))
        assert Odict('photon: [magnetic, electric]') == c
Beispiel #14
0
def test_empty_include_config():
    '''Test yaml !include tag ignore empty file'''
    with tempfile() as fh:
        c = Config('_: !include {}'.format(fh.name))
    assert '{}' == repr(c)