summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-06-09 20:00:23 +0200
committerGitHub <noreply@github.com>2020-06-09 11:00:23 -0700
commit25a837bf796eb94d78740e21147d8cfd9d942241 (patch)
tree2c8328f11c10752fd741a56ff809f1395223df7f /lib
parent2421d903b034c92660fbe999b7d486e6f21a7417 (diff)
downloadspack-25a837bf796eb94d78740e21147d8cfd9d942241.tar.gz
spack-25a837bf796eb94d78740e21147d8cfd9d942241.tar.bz2
spack-25a837bf796eb94d78740e21147d8cfd9d942241.tar.xz
spack-25a837bf796eb94d78740e21147d8cfd9d942241.zip
Testing: create mock executable fixture (#16999)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/conftest.py17
-rw-r--r--lib/spack/spack/test/relocate.py11
2 files changed, 19 insertions, 9 deletions
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index ae8fa80ab7..bac5bcebf6 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -1099,3 +1099,20 @@ def clear_directive_functions():
# proceeding with subsequent tests that may depend on the original
# functions.
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
diff --git a/lib/spack/spack/test/relocate.py b/lib/spack/spack/test/relocate.py
index 6669b25eb4..551f1596f7 100644
--- a/lib/spack/spack/test/relocate.py
+++ b/lib/spack/spack/test/relocate.py
@@ -107,16 +107,9 @@ def expected_patchelf_path(request, mutable_database, monkeypatch):
@pytest.fixture()
-def mock_patchelf(tmpdir):
- import jinja2
-
+def mock_patchelf(tmpdir, mock_executable):
def _factory(output):
- f = tmpdir.mkdir('bin').join('patchelf')
- t = jinja2.Template('#!/bin/bash\n{{ output }}\n')
- f.write(t.render(output=output))
- f.chmod(0o755)
- return str(f)
-
+ return mock_executable('patchelf', output=output)
return _factory