spack style: improve tests for failure cases

This fixes the bad bootstrap test for spack style, and it refines the
asserrtions on other failure cases.
This commit is contained in:
Todd Gamblin 2021-07-27 14:47:44 -07:00 committed by Massimiliano Culpo
parent 507d3c841c
commit 693c4d8f3a

View File

@ -129,14 +129,15 @@ def test_changed_files_all_files(flake8_package):
@pytest.mark.skipif(sys.version_info >= (3, 6), reason="doesn't apply to newer python")
def test_fail_on_old_python():
"""Ensure that `spack style` runs but fails with older python."""
style(fail_on_error=False)
assert style.returncode != 0
output = style(fail_on_error=False)
assert "spack style requires Python 3.6" in output
@skip_old_python
def test_bad_root(tmpdir):
"""Ensure that `spack style` doesn't run on non-spack directories."""
style("--root", str(tmpdir), fail_on_error=False)
output = style("--root", str(tmpdir), fail_on_error=False)
assert "This does not look like a valid spack root" in output
assert style.returncode != 0
@ -156,10 +157,12 @@ def test_style_is_package(tmpdir):
def test_bad_bootstrap(monkeypatch):
"""Ensure we fail gracefully when we can't bootstrap spack style."""
monkeypatch.setattr(spack.cmd.style, "tool_order", [
("foobartool", "foobartool"), # bad package to force concretization failure
("isort", "py-isort@4.3:4.0"), # bad spec to force concretization failure
])
style(fail_on_error=False)
assert style.returncode != 0
# zero out path to ensure we don't find isort
with pytest.raises(spack.error.SpackError) as e:
style(env={"PATH": ""})
assert "Couldn't bootstrap isort" in str(e)
@pytest.fixture