bugfix: Allow legacy tests to be read after hash break (#26078)

* added a test case

Co-authored-by: Nathan Hanford <hanford1@llnl.gov>
This commit is contained in:
Nathan Hanford 2021-11-22 20:49:41 -08:00 committed by GitHub
parent feb66cba01
commit 2104f1273a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -287,7 +287,10 @@ def from_file(filename):
try:
with open(filename, 'r') as f:
data = sjson.load(f)
return TestSuite.from_dict(data)
test_suite = TestSuite.from_dict(data)
content_hash = os.path.basename(os.path.dirname(filename))
test_suite._hash = content_hash
return test_suite
except Exception as e:
tty.debug(e)
raise sjson.SpackJSONError("error parsing JSON TestSuite:", str(e))

View File

@ -11,6 +11,7 @@
import spack.cmd.install
import spack.config
import spack.package
import spack.store
from spack.cmd.test import has_test_method
from spack.main import SpackCommand
@ -231,3 +232,31 @@ def test_has_test_method_fails(capsys):
captured = capsys.readouterr()[1]
assert 'is not a class' in captured
def test_hash_change(mock_test_stage, mock_packages, mock_archive, mock_fetch,
install_mockery_mutable_config):
"""Ensure output printed from pkgs is captured by output redirection."""
install('printing-package')
spack_test('run', '--alias', 'printpkg', 'printing-package')
stage_files = os.listdir(mock_test_stage)
# Grab test stage directory contents
testdir = os.path.join(mock_test_stage, stage_files[0])
outfile = os.path.join(testdir, 'test_suite.lock')
with open(outfile, 'r') as f:
output = f.read()
changed_hash = output.replace(
spack.store.db.query('printing-package')[0].full_hash(),
'fakehash492ucwhwvzhxfbmcc45x49ha')
with open(outfile, 'w') as f:
f.write(changed_hash)
# The find command should show the contents
find_output = spack_test('find')
assert 'printpkg' in find_output
# The results should be obtainable
results_output = spack_test('results')
assert 'PASSED' in results_output