From 6855512301eb04ecef4e39d65ba838a53c3f0dcb Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 27 Dec 2023 23:52:19 -0800 Subject: gc tests: replace `find()` with DB query (#41876) Per https://github.com/spack/spack/pull/41731#discussion_r1434827924, This cleans up the tests for `spack gc` by replacing ```python assert in find() ``` with the more precise ```python assert mutable_database.query_local() ``` --- lib/spack/spack/test/cmd/gc.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/spack/spack/test/cmd/gc.py b/lib/spack/spack/test/cmd/gc.py index 9defb9d99c..1e4ca684e9 100644 --- a/lib/spack/spack/test/cmd/gc.py +++ b/lib/spack/spack/test/cmd/gc.py @@ -13,7 +13,6 @@ import spack.spec gc = spack.main.SpackCommand("gc") add = spack.main.SpackCommand("add") install = spack.main.SpackCommand("install") -find = spack.main.SpackCommand("find") pytestmark = pytest.mark.not_on_windows("does not run on windows") @@ -50,7 +49,7 @@ def test_gc_with_environment(config, mutable_database, mutable_mock_env_path): with e: add("cmake") install() - assert "cmake" in find() + assert mutable_database.query_local("cmake") output = gc("-y") assert "Restricting garbage collection" in output assert "There are no unused specs" in output @@ -66,13 +65,13 @@ def test_gc_with_build_dependency_in_environment(config, mutable_database, mutab with e: add("simple-inheritance") install() - assert "simple-inheritance" in find() + assert mutable_database.query_local("simple-inheritance") output = gc("-yb") assert "Restricting garbage collection" in output assert "There are no unused specs" in output with e: - assert "simple-inheritance" in find() + assert mutable_database.query_local("simple-inheritance") output = gc("-y") assert "Restricting garbage collection" in output assert "Successfully uninstalled cmake" in output @@ -84,23 +83,23 @@ def test_gc_except_any_environments(config, mutable_database, mutable_mock_env_p s.concretize() s.package.do_install(fake=True, explicit=True) - assert "zmpi" in find() + assert mutable_database.query_local("zmpi") e = ev.create("test_gc") with e: add("simple-inheritance") install() - assert "simple-inheritance" in find() + assert mutable_database.query_local("simple-inheritance") output = gc("-yE") assert "Restricting garbage collection" not in output assert "Successfully uninstalled zmpi" in output - assert "zmpi" not in find() + assert not mutable_database.query_local("zmpi") with e: output = gc("-yE") assert "Restricting garbage collection" not in output - assert "There are no unused specs" not in find() + assert "There are no unused specs" not in output @pytest.mark.db @@ -109,18 +108,18 @@ def test_gc_except_specific_environments(config, mutable_database, mutable_mock_ s.concretize() s.package.do_install(fake=True, explicit=True) - assert "zmpi" in find() + assert mutable_database.query_local("zmpi") e = ev.create("test_gc") with e: add("simple-inheritance") install() - assert "simple-inheritance" in find() + assert mutable_database.query_local("simple-inheritance") output = gc("-ye", "test_gc") assert "Restricting garbage collection" not in output assert "Successfully uninstalled zmpi" in output - assert "zmpi" not in find() + assert not mutable_database.query_local("zmpi") @pytest.mark.db @@ -136,15 +135,15 @@ def test_gc_except_specific_dir_env(config, mutable_database, mutable_mock_env_p s.concretize() s.package.do_install(fake=True, explicit=True) - assert "zmpi" in find() + assert mutable_database.query_local("zmpi") e = ev.create_in_dir(tmpdir.strpath) with e: add("simple-inheritance") install() - assert "simple-inheritance" in find() + assert mutable_database.query_local("simple-inheritance") output = gc("-ye", tmpdir.strpath) assert "Restricting garbage collection" not in output assert "Successfully uninstalled zmpi" in output - assert "zmpi" not in find() + assert not mutable_database.query_local("zmpi") -- cgit v1.2.3-70-g09d2