summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/install_test.py25
-rw-r--r--lib/spack/spack/test/test_suite.py38
2 files changed, 57 insertions, 6 deletions
diff --git a/lib/spack/spack/install_test.py b/lib/spack/spack/install_test.py
index 8217d2f538..6d068d5bcd 100644
--- a/lib/spack/spack/install_test.py
+++ b/lib/spack/spack/install_test.py
@@ -113,8 +113,11 @@ class TestSuite(object):
for spec in self.specs:
try:
- msg = "A package object cannot run in two test suites at once"
- assert not spec.package.test_suite, msg
+ if spec.package.test_suite:
+ raise TestSuiteSpecError(
+ "Package {0} cannot be run in two test suites at once"
+ .format(spec.package.name)
+ )
# Set up the test suite to know which test is running
spec.package.test_suite = self
@@ -138,7 +141,7 @@ class TestSuite(object):
self.write_test_result(spec, 'PASSED')
except BaseException as exc:
self.fails += 1
- if isinstance(exc, SyntaxError):
+ if isinstance(exc, (SyntaxError, TestSuiteSpecError)):
# Create the test log file and report the error.
self.ensure_stage()
msg = 'Testing package {0}\n{1}'\
@@ -193,14 +196,22 @@ class TestSuite(object):
@property
def current_test_cache_dir(self):
- assert self.current_test_spec and self.current_base_spec
+ if not (self.current_test_spec and self.current_base_spec):
+ raise TestSuiteSpecError(
+ "Unknown test cache directory: no specs being tested"
+ )
+
test_spec = self.current_test_spec
base_spec = self.current_base_spec
return self.test_dir_for_spec(base_spec).cache.join(test_spec.name)
@property
def current_test_data_dir(self):
- assert self.current_test_spec and self.current_base_spec
+ if not (self.current_test_spec and self.current_base_spec):
+ raise TestSuiteSpecError(
+ "Unknown test data directory: no specs being tested"
+ )
+
test_spec = self.current_test_spec
base_spec = self.current_base_spec
return self.test_dir_for_spec(base_spec).data.join(test_spec.name)
@@ -283,3 +294,7 @@ class TestSuiteFailure(spack.error.SpackError):
msg = "%d test(s) in the suite failed.\n" % num_failures
super(TestSuiteFailure, self).__init__(msg)
+
+
+class TestSuiteSpecError(spack.error.SpackError):
+ """Raised when there is an issue associated with the spec being tested."""
diff --git a/lib/spack/spack/test/test_suite.py b/lib/spack/spack/test/test_suite.py
index 3a11d6ab39..c71a063c50 100644
--- a/lib/spack/spack/test/test_suite.py
+++ b/lib/spack/spack/test/test_suite.py
@@ -4,6 +4,8 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
+import pytest
+
import llnl.util.filesystem as fs
import spack.install_test
@@ -56,7 +58,7 @@ def test_write_test_result(mock_packages, mock_test_stage):
assert spec.name in msg
-def test_do_test(mock_packages, mock_test_stage, install_mockery):
+def test_do_test(mock_packages, install_mockery, mock_test_stage):
"""Perform a stand-alone test with files to copy."""
spec = spack.spec.Spec('trivial-smoke-test').concretized()
test_name = 'test_do_test'
@@ -83,3 +85,37 @@ def test_do_test(mock_packages, mock_test_stage, install_mockery):
assert os.path.exists(cached_filename)
assert os.path.exists(data_filename)
+
+
+def test_test_stage_caches(mock_packages, install_mockery, mock_test_stage):
+ def ensure_current_cache_fail(test_suite):
+ with pytest.raises(spack.install_test.TestSuiteSpecError):
+ _ = test_suite.current_test_cache_dir
+
+ with pytest.raises(spack.install_test.TestSuiteSpecError):
+ _ = test_suite.current_test_data_dir
+
+ spec = spack.spec.Spec('libelf').concretized()
+ test_suite = spack.install_test.TestSuite([spec], 'test-cache')
+
+ # Check no current specs yield failure
+ ensure_current_cache_fail(test_suite)
+
+ # Check no current base spec yields failure
+ test_suite.current_base_spec = None
+ test_suite.current_test_spec = spec
+ ensure_current_cache_fail(test_suite)
+
+ # Check no current test spec yields failure
+ test_suite.current_base_spec = spec
+ test_suite.current_test_spec = None
+ ensure_current_cache_fail(test_suite)
+
+
+def test_test_spec_run_once(mock_packages, install_mockery, mock_test_stage):
+ spec = spack.spec.Spec('libelf').concretized()
+ test_suite = spack.install_test.TestSuite([spec], 'test-dups')
+ (test_suite.specs[0]).package.test_suite = test_suite
+
+ with pytest.raises(spack.install_test.TestSuiteFailure):
+ test_suite()