def test_read_config_return_config(yaml_config_text): cfg = config.parse_config(yaml_config_text, raise_errors=True) xyzzy = cfg.value_of('xyzzy') assert isinstance(xyzzy, attrdict) assert hasattr(xyzzy, 'value_of') assert xyzzy._raises with pytest.raises(KeyError): xyzzy.value_of('non.existent.key')
def test_read_config_properties(yaml_config_text): cfg = config.parse_config(yaml_config_text) assert 'host 2' == cfg.value_of('xyzzy.hosts.1') assert 'item 1' == cfg.value_of('general.3.subfeature.0') subfeature = cfg.value_of('general.3.subfeature') assert isinstance(subfeature, (list, tuple)) assert 'item 1' == subfeature[0] assert 'item 2' == subfeature[1]
def test_read_config_file(yaml_config_file): cfg = config.parse_config(stream=yaml_config_file) run_common_tests(cfg)
def test_read_config_text(yaml_config_text): cfg = config.parse_config(yaml_config_text) run_common_tests(cfg)
def test_read_config_convert_parse_json(yaml_config_text): cfg = config.parse_config(yaml_config_text) json_string = cfg.as_json(indent=2) assert isinstance(json_string, six.string_types) x_cfg = config.parse_config(json_string, as_json=True) assert x_cfg == DICT
def test_read_config_return_config_in_list_and_use(yaml_config_text): cfg = config.parse_config(yaml_config_text) general = cfg.value_of('general') subfeature = general[3].value_of('subfeature') assert subfeature == cfg.value_of('general.3.subfeature')
def test_read_config_return_config_in_list(yaml_config_text): cfg = config.parse_config(yaml_config_text) general = cfg.value_of('general') assert isinstance(general, list) assert isinstance(general[3], attrdict)
def test_read_config_non_existent_cfg_raises(yaml_config_text): cfg = config.parse_config(yaml_config_text, raise_errors=True) with pytest.raises(KeyError): cfg.value_of('non.existent.key')
def test_read_config_non_existent_key_with_default(yaml_config_text): cfg = config.parse_config(yaml_config_text) assert cfg.value_of('non.existent.key', default='foo') == 'foo'
def test_read_config_non_existent_key(yaml_config_text): cfg = config.parse_config(yaml_config_text) assert cfg.value_of('non.existent.key') is None
def test_read_config_errors(yaml_config_bad): with pytest.raises(config.YamlParseException): config.parse_config(yaml_config_bad)