summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Josef Scheibel <scheibel1@llnl.gov>2019-01-04 11:48:28 -0800
committerPeter Scheibel <scheibel1@llnl.gov>2019-01-04 17:04:28 -0800
commit64deda1b0c9abd402de27d53f9b121b003b7e146 (patch)
tree6cf39d6032d750fab41d751a2de3925cd0f382e9
parent41ef02ee1009a86d040314433a3823ca3dd13a02 (diff)
downloadspack-64deda1b0c9abd402de27d53f9b121b003b7e146.tar.gz
spack-64deda1b0c9abd402de27d53f9b121b003b7e146.tar.bz2
spack-64deda1b0c9abd402de27d53f9b121b003b7e146.tar.xz
spack-64deda1b0c9abd402de27d53f9b121b003b7e146.zip
Add tests for expanding/non-expanding resources
-rw-r--r--lib/spack/spack/test/stage.py95
1 files changed, 92 insertions, 3 deletions
diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py
index 3e8b4a6db0..3499364d5f 100644
--- a/lib/spack/spack/test/stage.py
+++ b/lib/spack/spack/test/stage.py
@@ -14,7 +14,9 @@ from llnl.util.filesystem import working_dir
import spack.paths
import spack.stage
import spack.util.executable
-from spack.stage import Stage
+
+from spack.resource import Resource
+from spack.stage import Stage, StageComposite, ResourceStage
def check_expand_archive(stage, stage_name, mock_archive):
@@ -92,7 +94,7 @@ def get_stage_path(stage, stage_name):
@pytest.fixture()
-def tmpdir_for_stage(mock_archive, mutable_config):
+def tmpdir_for_stage(mock_archive):
"""Uses a temporary directory for staging"""
current = spack.paths.stage_path
spack.config.set(
@@ -104,7 +106,7 @@ def tmpdir_for_stage(mock_archive, mutable_config):
@pytest.fixture()
-def mock_archive(tmpdir, monkeypatch, mutable_config):
+def mock_archive(tmpdir, monkeypatch):
"""Creates a mock archive with the structure expected by the tests"""
# Mock up a stage area that looks like this:
#
@@ -148,6 +150,52 @@ def mock_archive(tmpdir, monkeypatch, mutable_config):
@pytest.fixture()
+def mock_noexpand_resource(tmpdir):
+ test_resource = tmpdir.join('resource-no-expand.sh')
+ test_resource.write("an example resource")
+ return str(test_resource)
+
+
+@pytest.fixture()
+def mock_expand_resource(tmpdir):
+ resource_dir = tmpdir.join('resource-expand')
+ archive_name = 'resource.tar.gz'
+ archive = tmpdir.join(archive_name)
+ archive_url = 'file://' + str(archive)
+ test_file = resource_dir.join('resource-file.txt')
+ resource_dir.ensure(dir=True)
+ test_file.write('test content\n')
+ current = tmpdir.chdir()
+ tar = spack.util.executable.which('tar', required=True)
+ tar('czf', str(archive_name), 'resource-expand')
+ current.chdir()
+
+ MockResource = collections.namedtuple(
+ 'MockResource', ['url', 'files'])
+
+ return MockResource(archive_url, ['resource-file.txt'])
+
+
+@pytest.fixture()
+def composite_stage_with_expanding_resource(
+ mock_archive, mock_expand_resource):
+ composite_stage = StageComposite()
+ root_stage = Stage(mock_archive.url)
+ composite_stage.append(root_stage)
+
+ test_resource_fetcher = spack.fetch_strategy.from_kwargs(
+ url=mock_expand_resource.url)
+ # Specify that the resource files are to be placed in the 'resource-dir'
+ # directory
+ test_resource = Resource(
+ 'test_resource', test_resource_fetcher, '', 'resource-dir')
+ resource_stage = ResourceStage(
+ test_resource_fetcher, root_stage, test_resource)
+ composite_stage.append(resource_stage)
+ return composite_stage, root_stage, resource_stage
+
+
+@pytest.fixture()
def failing_search_fn():
"""Returns a search function that fails! Always!"""
def _mock():
@@ -202,6 +250,47 @@ class TestStage(object):
check_setup(stage, None, mock_archive)
check_destroy(stage, None)
+ @pytest.mark.disable_clean_stage_check
+ @pytest.mark.usefixtures('tmpdir_for_stage')
+ def test_composite_stage_with_noexpand_resource(
+ self, mock_archive, mock_noexpand_resource):
+ composite_stage = StageComposite()
+ root_stage = Stage(mock_archive.url)
+ composite_stage.append(root_stage)
+
+ resource_dst_name = 'resource-dst-name.sh'
+ test_resource_fetcher = spack.fetch_strategy.from_kwargs(
+ url='file://' + mock_noexpand_resource, expand=False)
+ test_resource = Resource(
+ 'test_resource', test_resource_fetcher, resource_dst_name, None)
+ resource_stage = ResourceStage(
+ test_resource_fetcher, root_stage, test_resource)
+ composite_stage.append(resource_stage)
+
+ composite_stage.create()
+ composite_stage.fetch()
+ composite_stage.expand_archive()
+ assert os.path.exists(
+ os.path.join(composite_stage.source_path, resource_dst_name))
+
+ @pytest.mark.disable_clean_stage_check
+ @pytest.mark.usefixtures('tmpdir_for_stage')
+ def test_composite_stage_with_expand_resource(
+ self, mock_archive, mock_expand_resource,
+ composite_stage_with_expanding_resource):
+
+ composite_stage, root_stage, resource_stage = (
+ composite_stage_with_expanding_resource)
+
+ composite_stage.create()
+ composite_stage.fetch()
+ composite_stage.expand_archive()
+
+ for fname in mock_expand_resource.files:
+ file_path = os.path.join(
+ root_stage.source_path, 'resource-dir', fname)
+ assert os.path.exists(file_path)
+
def test_setup_and_destroy_no_name_without_tmp(self, mock_archive):
with Stage(mock_archive.url) as stage:
check_setup(stage, None, mock_archive)