RepoSplit/tests: update repo tests relying on builtin package repo to only use mock repos (#48926)

* RepoSplit/tests: update repo tests relying on builtin

* test_repo_last_mtime: skip on windows due to mtime issues in CI
This commit is contained in:
Tamara Dahlgren 2025-02-13 21:49:50 -08:00 committed by GitHub
parent 1a42bf043f
commit 236b8fc009
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -65,8 +65,8 @@ def test_repo_unknown_pkg(mutable_mock_repo):
mutable_mock_repo.get_pkg_class("builtin.mock.nonexistentpackage") mutable_mock_repo.get_pkg_class("builtin.mock.nonexistentpackage")
@pytest.mark.maybeslow @pytest.mark.not_on_windows("mtime granularity issues on windows")
def test_repo_last_mtime(): def test_repo_last_mtime(mock_packages):
latest_mtime = max( latest_mtime = max(
os.path.getmtime(p.module.__file__) for p in spack.repo.PATH.all_package_classes() os.path.getmtime(p.module.__file__) for p in spack.repo.PATH.all_package_classes()
) )
@ -91,13 +91,13 @@ def test_namespace_hasattr(attr_name, exists, mutable_mock_repo):
@pytest.mark.regression("24552") @pytest.mark.regression("24552")
def test_all_package_names_is_cached_correctly(): def test_all_package_names_is_cached_correctly(mock_packages):
assert "mpi" in spack.repo.all_package_names(include_virtuals=True) assert "mpi" in spack.repo.all_package_names(include_virtuals=True)
assert "mpi" not in spack.repo.all_package_names(include_virtuals=False) assert "mpi" not in spack.repo.all_package_names(include_virtuals=False)
@pytest.mark.regression("29203") @pytest.mark.regression("29203")
def test_use_repositories_doesnt_change_class(): def test_use_repositories_doesnt_change_class(mock_packages):
"""Test that we don't create the same package module and class multiple times """Test that we don't create the same package module and class multiple times
when swapping repositories. when swapping repositories.
""" """
@ -166,18 +166,25 @@ def test_repo_dump_virtuals(tmpdir, mutable_mock_repo, mock_packages, ensure_deb
assert "package.py" in os.listdir(tmpdir), "Expected the virtual's package to be copied" assert "package.py" in os.listdir(tmpdir), "Expected the virtual's package to be copied"
@pytest.mark.parametrize( @pytest.mark.parametrize("repos", [["mock"], ["extra"], ["mock", "extra"], ["extra", "mock"]])
"repo_paths,namespaces", def test_repository_construction_doesnt_use_globals(nullify_globals, tmp_path, repos):
[ def _repo_paths(repos):
([spack.paths.packages_path], ["builtin"]), repo_paths, namespaces = [], []
([spack.paths.mock_packages_path], ["builtin.mock"]), for entry in repos:
([spack.paths.packages_path, spack.paths.mock_packages_path], ["builtin", "builtin.mock"]), if entry == "mock":
([spack.paths.mock_packages_path, spack.paths.packages_path], ["builtin.mock", "builtin"]), repo_paths.append(spack.paths.mock_packages_path)
], namespaces.append("builtin.mock")
) if entry == "extra":
def test_repository_construction_doesnt_use_globals( name = "extra.mock"
nullify_globals, tmp_path, repo_paths, namespaces repo_dir = tmp_path / name
): repo_dir.mkdir()
_ = spack.repo.MockRepositoryBuilder(repo_dir, name)
repo_paths.append(str(repo_dir))
namespaces.append(name)
return repo_paths, namespaces
repo_paths, namespaces = _repo_paths(repos)
repo_cache = spack.util.file_cache.FileCache(str(tmp_path / "cache")) repo_cache = spack.util.file_cache.FileCache(str(tmp_path / "cache"))
repo_path = spack.repo.RepoPath(*repo_paths, cache=repo_cache) repo_path = spack.repo.RepoPath(*repo_paths, cache=repo_cache)
assert len(repo_path.repos) == len(namespaces) assert len(repo_path.repos) == len(namespaces)