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 <string> in find()
```

with the more precise

```python
assert mutable_database.query_local(<string>)
```
This commit is contained in:
Todd Gamblin 2023-12-27 23:52:19 -08:00 committed by GitHub
parent f721d4c625
commit 6855512301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,6 @@
gc = spack.main.SpackCommand("gc") gc = spack.main.SpackCommand("gc")
add = spack.main.SpackCommand("add") add = spack.main.SpackCommand("add")
install = spack.main.SpackCommand("install") install = spack.main.SpackCommand("install")
find = spack.main.SpackCommand("find")
pytestmark = pytest.mark.not_on_windows("does not run on windows") 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: with e:
add("cmake") add("cmake")
install() install()
assert "cmake" in find() assert mutable_database.query_local("cmake")
output = gc("-y") output = gc("-y")
assert "Restricting garbage collection" in output assert "Restricting garbage collection" in output
assert "There are no unused specs" 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: with e:
add("simple-inheritance") add("simple-inheritance")
install() install()
assert "simple-inheritance" in find() assert mutable_database.query_local("simple-inheritance")
output = gc("-yb") output = gc("-yb")
assert "Restricting garbage collection" in output assert "Restricting garbage collection" in output
assert "There are no unused specs" in output assert "There are no unused specs" in output
with e: with e:
assert "simple-inheritance" in find() assert mutable_database.query_local("simple-inheritance")
output = gc("-y") output = gc("-y")
assert "Restricting garbage collection" in output assert "Restricting garbage collection" in output
assert "Successfully uninstalled cmake" 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.concretize()
s.package.do_install(fake=True, explicit=True) s.package.do_install(fake=True, explicit=True)
assert "zmpi" in find() assert mutable_database.query_local("zmpi")
e = ev.create("test_gc") e = ev.create("test_gc")
with e: with e:
add("simple-inheritance") add("simple-inheritance")
install() install()
assert "simple-inheritance" in find() assert mutable_database.query_local("simple-inheritance")
output = gc("-yE") output = gc("-yE")
assert "Restricting garbage collection" not in output assert "Restricting garbage collection" not in output
assert "Successfully uninstalled zmpi" in output assert "Successfully uninstalled zmpi" in output
assert "zmpi" not in find() assert not mutable_database.query_local("zmpi")
with e: with e:
output = gc("-yE") output = gc("-yE")
assert "Restricting garbage collection" not in output 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 @pytest.mark.db
@ -109,18 +108,18 @@ def test_gc_except_specific_environments(config, mutable_database, mutable_mock_
s.concretize() s.concretize()
s.package.do_install(fake=True, explicit=True) s.package.do_install(fake=True, explicit=True)
assert "zmpi" in find() assert mutable_database.query_local("zmpi")
e = ev.create("test_gc") e = ev.create("test_gc")
with e: with e:
add("simple-inheritance") add("simple-inheritance")
install() install()
assert "simple-inheritance" in find() assert mutable_database.query_local("simple-inheritance")
output = gc("-ye", "test_gc") output = gc("-ye", "test_gc")
assert "Restricting garbage collection" not in output assert "Restricting garbage collection" not in output
assert "Successfully uninstalled zmpi" in output assert "Successfully uninstalled zmpi" in output
assert "zmpi" not in find() assert not mutable_database.query_local("zmpi")
@pytest.mark.db @pytest.mark.db
@ -136,15 +135,15 @@ def test_gc_except_specific_dir_env(config, mutable_database, mutable_mock_env_p
s.concretize() s.concretize()
s.package.do_install(fake=True, explicit=True) 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) e = ev.create_in_dir(tmpdir.strpath)
with e: with e:
add("simple-inheritance") add("simple-inheritance")
install() install()
assert "simple-inheritance" in find() assert mutable_database.query_local("simple-inheritance")
output = gc("-ye", tmpdir.strpath) output = gc("-ye", tmpdir.strpath)
assert "Restricting garbage collection" not in output assert "Restricting garbage collection" not in output
assert "Successfully uninstalled zmpi" in output assert "Successfully uninstalled zmpi" in output
assert "zmpi" not in find() assert not mutable_database.query_local("zmpi")