Skip to content
Snippets Groups Projects
Commit 289f9709 authored by Nicolas Dandrimont's avatar Nicolas Dandrimont
Browse files

Replace manual pytest.raises mangling with the match argument

parent b78406dc
No related branches found
No related tags found
1 merge request!74Deprecate the `args` argument to get_objstorage in favor of kwargs
......@@ -35,38 +35,30 @@ def prepare_config_file(tmpdir, content, name="config.yml"):
def test_load_and_check_config_no_configuration():
"""Inexistent configuration files raises"""
with pytest.raises(EnvironmentError) as e:
with pytest.raises(EnvironmentError, match="Configuration file must be defined"):
load_and_check_config(None)
assert e.value.args[0] == "Configuration file must be defined"
config_path = "/indexer/inexistent/config.yml"
with pytest.raises(FileNotFoundError) as e:
with pytest.raises(FileNotFoundError, match=f"{config_path} does not exist"):
load_and_check_config(config_path)
assert e.value.args[0] == "Configuration file %s does not exist" % (config_path,)
def test_load_and_check_config_invalid_configuration_toplevel(tmpdir):
"""Invalid configuration raises"""
config = {"something": "useless"}
config_path = prepare_config_file(tmpdir, content=config)
with pytest.raises(KeyError) as e:
with pytest.raises(KeyError, match="missing objstorage config entry"):
load_and_check_config(config_path)
assert e.value.args[0] == "Invalid configuration; missing objstorage config entry"
def test_load_and_check_config_invalid_configuration(tmpdir):
"""Invalid configuration raises"""
config_path = prepare_config_file(
tmpdir, content={"objstorage": {"something": "useless"}}
)
with pytest.raises(KeyError) as e:
with pytest.raises(KeyError, match="missing cls config entry"):
load_and_check_config(config_path)
assert "missing cls config entry" in e.value.args[0]
def test_load_and_check_config_invalid_configuration_level2(tmpdir):
"""Invalid configuration at 2nd level raises"""
......@@ -81,11 +73,9 @@ def test_load_and_check_config_invalid_configuration_level2(tmpdir):
c = copy.deepcopy(config)
c["objstorage"]["args"].pop(key)
config_path = prepare_config_file(tmpdir, c)
with pytest.raises(KeyError) as e:
with pytest.raises(KeyError, match=f"missing {key} config entry"):
load_and_check_config(config_path)
assert "missing %s config entry" % key in e.value.args[0]
def test_load_and_check_config_fine(tmpdir):
"""pathslicing configuration fine loads ok"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment