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))
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
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
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
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
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)
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)
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]
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_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
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
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)