Replace spec-related install_test asserts with exceptions; added unit tests (#25982)
This commit is contained in:
parent
c58cd83e38
commit
7aedeca764
2 changed files with 57 additions and 6 deletions
|
@ -113,8 +113,11 @@ def __call__(self, *args, **kwargs):
|
|||
|
||||
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 @@ def __call__(self, *args, **kwargs):
|
|||
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 @@ def test_dir_for_spec(self, spec):
|
|||
|
||||
@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 @@ def __init__(self, num_failures):
|
|||
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."""
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue