Testing: create mock executable fixture (#16999)
This commit is contained in:
parent
2421d903b0
commit
25a837bf79
@ -1099,3 +1099,20 @@ def clear_directive_functions():
|
|||||||
# proceeding with subsequent tests that may depend on the original
|
# proceeding with subsequent tests that may depend on the original
|
||||||
# functions.
|
# functions.
|
||||||
spack.directives.DirectiveMeta._directives_to_be_executed = []
|
spack.directives.DirectiveMeta._directives_to_be_executed = []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_executable(tmpdir):
|
||||||
|
"""Factory to create a mock executable in a temporary directory that
|
||||||
|
output a custom string when run.
|
||||||
|
"""
|
||||||
|
import jinja2
|
||||||
|
|
||||||
|
def _factory(name, output, subdir=('bin',)):
|
||||||
|
f = tmpdir.mkdir(*subdir).join(name)
|
||||||
|
t = jinja2.Template('#!/bin/bash\n{{ output }}\n')
|
||||||
|
f.write(t.render(output=output))
|
||||||
|
f.chmod(0o755)
|
||||||
|
return str(f)
|
||||||
|
|
||||||
|
return _factory
|
||||||
|
@ -107,16 +107,9 @@ def do_install_mock(self, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def mock_patchelf(tmpdir):
|
def mock_patchelf(tmpdir, mock_executable):
|
||||||
import jinja2
|
|
||||||
|
|
||||||
def _factory(output):
|
def _factory(output):
|
||||||
f = tmpdir.mkdir('bin').join('patchelf')
|
return mock_executable('patchelf', output=output)
|
||||||
t = jinja2.Template('#!/bin/bash\n{{ output }}\n')
|
|
||||||
f.write(t.render(output=output))
|
|
||||||
f.chmod(0o755)
|
|
||||||
return str(f)
|
|
||||||
|
|
||||||
return _factory
|
return _factory
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user