From 2104f1273a32669472316a59a33b6ec4bb2d6d70 Mon Sep 17 00:00:00 2001 From: Nathan Hanford <8302958+nhanford@users.noreply.github.com> Date: Mon, 22 Nov 2021 20:49:41 -0800 Subject: bugfix: Allow legacy tests to be read after hash break (#26078) * added a test case Co-authored-by: Nathan Hanford --- lib/spack/spack/install_test.py | 5 ++++- lib/spack/spack/test/cmd/test.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/spack/spack/install_test.py b/lib/spack/spack/install_test.py index 07644f5cc5..a8fe0f4024 100644 --- a/lib/spack/spack/install_test.py +++ b/lib/spack/spack/install_test.py @@ -287,7 +287,10 @@ class TestSuite(object): 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)) diff --git a/lib/spack/spack/test/cmd/test.py b/lib/spack/spack/test/cmd/test.py index 9ee117b281..f82f767bc8 100644 --- a/lib/spack/spack/test/cmd/test.py +++ b/lib/spack/spack/test/cmd/test.py @@ -11,6 +11,7 @@ import pytest 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 -- cgit v1.2.3-60-g2f50