diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/test/cmd/reindex.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/spack/spack/test/cmd/reindex.py b/lib/spack/spack/test/cmd/reindex.py index 1aceeab197..6e48a3c21c 100644 --- a/lib/spack/spack/test/cmd/reindex.py +++ b/lib/spack/spack/test/cmd/reindex.py @@ -2,9 +2,10 @@ # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) -import os +import shutil import spack.store +from spack.database import Database from spack.main import SpackCommand install = SpackCommand("install") @@ -23,20 +24,31 @@ def test_reindex_basic(mock_packages, mock_archive, mock_fetch, install_mockery) assert spack.store.STORE.db.query() == all_installed -def test_reindex_db_deleted(mock_packages, mock_archive, mock_fetch, install_mockery): +def _clear_db(tmp_path): + empty_db = Database(str(tmp_path)) + with empty_db.write_transaction(): + pass + shutil.rmtree(spack.store.STORE.db.database_directory) + shutil.copytree(empty_db.database_directory, spack.store.STORE.db.database_directory) + # force a re-read of the database + assert len(spack.store.STORE.db.query()) == 0 + + +def test_reindex_db_deleted(mock_packages, mock_archive, mock_fetch, install_mockery, tmp_path): install("libelf@0.8.13") install("libelf@0.8.12") all_installed = spack.store.STORE.db.query() - os.remove(spack.store.STORE.db._index_path) + _clear_db(tmp_path) + reindex() assert spack.store.STORE.db.query() == all_installed def test_reindex_with_deprecated_packages( - mock_packages, mock_archive, mock_fetch, install_mockery + mock_packages, mock_archive, mock_fetch, install_mockery, tmp_path ): install("libelf@0.8.13") install("libelf@0.8.12") @@ -46,7 +58,8 @@ def test_reindex_with_deprecated_packages( all_installed = spack.store.STORE.db.query(installed=any) non_deprecated = spack.store.STORE.db.query(installed=True) - os.remove(spack.store.STORE.db._index_path) + _clear_db(tmp_path) + reindex() assert spack.store.STORE.db.query(installed=any) == all_installed |