fix various tests
This commit is contained in:
parent
93e0d99553
commit
1c05b1dd1b
@ -15,7 +15,7 @@
|
||||
|
||||
@pytest.fixture()
|
||||
def builder_test_repository(config):
|
||||
builder_test_path = os.path.join(spack.paths.test_repos_path, "builder_test")
|
||||
builder_test_path = os.path.join(spack.paths.test_repos_path, "spack_repo", "builder_test")
|
||||
with spack.repo.use_repositories(builder_test_path) as mock_repo:
|
||||
yield mock_repo
|
||||
|
||||
|
@ -143,8 +143,8 @@ def test_list_count():
|
||||
|
||||
def test_list_repos():
|
||||
with spack.repo.use_repositories(
|
||||
os.path.join(spack.paths.test_repos_path, "builtin_mock"),
|
||||
os.path.join(spack.paths.test_repos_path, "builder_test"),
|
||||
os.path.join(spack.paths.test_repos_path, "spack_repo", "builtin_mock"),
|
||||
os.path.join(spack.paths.test_repos_path, "spack_repo", "builder_test"),
|
||||
):
|
||||
total_pkgs = len(list().strip().split())
|
||||
mock_pkgs = len(list("-r", "builtin_mock").strip().split())
|
||||
|
@ -39,7 +39,9 @@ def install(self, spec, prefix):
|
||||
def mock_pkg_git_repo(git, tmp_path_factory):
|
||||
"""Copy the builtin_mock repo and make a mutable git repo inside it."""
|
||||
root_dir = tmp_path_factory.mktemp("mock_pkg_git_repo")
|
||||
repo_dir = root_dir / "builtin_mock"
|
||||
# create spack_repo subdir
|
||||
(root_dir / "spack_repo").mkdir()
|
||||
repo_dir = root_dir / "spack_repo" / "builtin_mock"
|
||||
shutil.copytree(spack.paths.mock_packages_path, str(repo_dir))
|
||||
|
||||
repo_cache = spack.util.file_cache.FileCache(root_dir / "cache")
|
||||
@ -57,25 +59,25 @@ def mock_pkg_git_repo(git, tmp_path_factory):
|
||||
git("-c", "commit.gpgsign=false", "commit", "-m", "initial mock repo commit")
|
||||
|
||||
# add commit with mockpkg-a, mockpkg-b, mockpkg-c packages
|
||||
mkdirp("mockpkg-a", "mockpkg-b", "mockpkg-c")
|
||||
with open("mockpkg-a/package.py", "w", encoding="utf-8") as f:
|
||||
mkdirp("mockpkg_a", "mockpkg_b", "mockpkg_c")
|
||||
with open("mockpkg_a/package.py", "w", encoding="utf-8") as f:
|
||||
f.write(pkg_template.format(name="PkgA"))
|
||||
with open("mockpkg-b/package.py", "w", encoding="utf-8") as f:
|
||||
with open("mockpkg_b/package.py", "w", encoding="utf-8") as f:
|
||||
f.write(pkg_template.format(name="PkgB"))
|
||||
with open("mockpkg-c/package.py", "w", encoding="utf-8") as f:
|
||||
with open("mockpkg_c/package.py", "w", encoding="utf-8") as f:
|
||||
f.write(pkg_template.format(name="PkgC"))
|
||||
git("add", "mockpkg-a", "mockpkg-b", "mockpkg-c")
|
||||
git("add", "mockpkg_a", "mockpkg_b", "mockpkg_c")
|
||||
git("-c", "commit.gpgsign=false", "commit", "-m", "add mockpkg-a, mockpkg-b, mockpkg-c")
|
||||
|
||||
# remove mockpkg-c, add mockpkg-d
|
||||
with open("mockpkg-b/package.py", "a", encoding="utf-8") as f:
|
||||
with open("mockpkg_b/package.py", "a", encoding="utf-8") as f:
|
||||
f.write("\n# change mockpkg-b")
|
||||
git("add", "mockpkg-b")
|
||||
mkdirp("mockpkg-d")
|
||||
with open("mockpkg-d/package.py", "w", encoding="utf-8") as f:
|
||||
git("add", "mockpkg_b")
|
||||
mkdirp("mockpkg_d")
|
||||
with open("mockpkg_d/package.py", "w", encoding="utf-8") as f:
|
||||
f.write(pkg_template.format(name="PkgD"))
|
||||
git("add", "mockpkg-d")
|
||||
git("rm", "-rf", "mockpkg-c")
|
||||
git("add", "mockpkg_d")
|
||||
git("rm", "-rf", "mockpkg_c")
|
||||
git(
|
||||
"-c",
|
||||
"commit.gpgsign=false",
|
||||
@ -121,17 +123,17 @@ def test_mock_builtin_repo(mock_packages):
|
||||
|
||||
def test_pkg_add(git, mock_pkg_git_repo):
|
||||
with working_dir(mock_pkg_git_repo):
|
||||
mkdirp("mockpkg-e")
|
||||
with open("mockpkg-e/package.py", "w", encoding="utf-8") as f:
|
||||
mkdirp("mockpkg_e")
|
||||
with open("mockpkg_e/package.py", "w", encoding="utf-8") as f:
|
||||
f.write(pkg_template.format(name="PkgE"))
|
||||
|
||||
pkg("add", "mockpkg-e")
|
||||
|
||||
with working_dir(mock_pkg_git_repo):
|
||||
try:
|
||||
assert "A mockpkg-e/package.py" in git("status", "--short", output=str)
|
||||
assert "A mockpkg_e/package.py" in git("status", "--short", output=str)
|
||||
finally:
|
||||
shutil.rmtree("mockpkg-e")
|
||||
shutil.rmtree("mockpkg_e")
|
||||
# Removing a package mid-run disrupts Spack's caching
|
||||
if spack.repo.PATH.repos[0]._fast_package_checker:
|
||||
spack.repo.PATH.repos[0]._fast_package_checker.invalidate()
|
||||
|
@ -48,7 +48,9 @@ def test_resource_list(mock_packages, capfd):
|
||||
assert "path:" in out
|
||||
|
||||
assert (
|
||||
os.path.join("repos", "builtin_mock", "packages", "patch-a-dependency", "libelf.patch")
|
||||
os.path.join(
|
||||
"spack_repo", "builtin_mock", "packages", "patch_a_dependency", "libelf.patch"
|
||||
)
|
||||
in out
|
||||
)
|
||||
assert "applies to: builtin_mock.libelf" in out
|
||||
@ -74,7 +76,9 @@ def test_resource_show(mock_packages, capfd):
|
||||
|
||||
assert out.startswith(test_hash)
|
||||
assert (
|
||||
os.path.join("repos", "builtin_mock", "packages", "patch-a-dependency", "libelf.patch")
|
||||
os.path.join(
|
||||
"spack_repo", "builtin_mock", "packages", "patch_a_dependency", "libelf.patch"
|
||||
)
|
||||
in out
|
||||
)
|
||||
assert "applies to: builtin_mock.libelf" in out
|
||||
|
@ -36,7 +36,7 @@ def test_remote_versions_only():
|
||||
@pytest.mark.usefixtures("mock_packages")
|
||||
def test_new_versions_only(monkeypatch):
|
||||
"""Test a package for which new versions should be available."""
|
||||
from spack.pkg.builtin_mock.brillig import Brillig # type: ignore[import]
|
||||
from spack_repo.builtin_mock.packages.brillig.package import Brillig # type: ignore[import]
|
||||
|
||||
def mock_fetch_remote_versions(*args, **kwargs):
|
||||
mock_remote_versions = {
|
||||
|
@ -29,7 +29,7 @@ def _concretize_with_reuse(*, root_str, reused_str):
|
||||
|
||||
@pytest.fixture
|
||||
def runtime_repo(mutable_config):
|
||||
repo = os.path.join(spack.paths.test_repos_path, "compiler_runtime_test")
|
||||
repo = os.path.join(spack.paths.test_repos_path, "spack_repo", "compiler_runtime_test")
|
||||
with spack.repo.use_repositories(repo) as mock_repo:
|
||||
yield mock_repo
|
||||
|
||||
|
@ -2341,7 +2341,9 @@ def test_select_lower_priority_package_from_repository_stack(
|
||||
from cli.
|
||||
"""
|
||||
# 'builtin_mock" and "duplicates_test" share a 'gmake' package
|
||||
additional_repo = os.path.join(spack.paths.test_repos_path, "duplicates_test")
|
||||
additional_repo = os.path.join(
|
||||
spack.paths.test_repos_path, "spack_repo", "duplicates_test"
|
||||
)
|
||||
with spack.repo.use_repositories(additional_repo, override=False):
|
||||
s = spack.concretize.concretize_one(spec_str)
|
||||
|
||||
@ -2585,7 +2587,7 @@ def test_correct_external_is_selected_from_packages_yaml(self, mutable_config):
|
||||
|
||||
@pytest.fixture()
|
||||
def duplicates_test_repository():
|
||||
repository_path = os.path.join(spack.paths.test_repos_path, "duplicates_test")
|
||||
repository_path = os.path.join(spack.paths.test_repos_path, "spack_repo", "duplicates_test")
|
||||
with spack.repo.use_repositories(repository_path) as mock_repo:
|
||||
yield mock_repo
|
||||
|
||||
@ -2820,7 +2822,7 @@ def test_adding_specs(self, input_specs, default_mock_concretization):
|
||||
|
||||
@pytest.fixture()
|
||||
def edges_test_repository():
|
||||
repository_path = os.path.join(spack.paths.test_repos_path, "edges_test")
|
||||
repository_path = os.path.join(spack.paths.test_repos_path, "spack_repo", "edges_test")
|
||||
with spack.repo.use_repositories(repository_path) as mock_repo:
|
||||
yield mock_repo
|
||||
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
@pytest.fixture
|
||||
def test_repo(mutable_config, monkeypatch, mock_stage):
|
||||
repo_dir = pathlib.Path(spack.paths.test_repos_path) / "flags_test"
|
||||
repo_dir = pathlib.Path(spack.paths.test_repos_path) / "spack_repo" / "flags_test"
|
||||
with spack.repo.use_repositories(str(repo_dir)) as mock_repo_path:
|
||||
yield mock_repo_path
|
||||
|
||||
|
@ -28,7 +28,7 @@ def update_packages_config(conf_str):
|
||||
|
||||
@pytest.fixture
|
||||
def test_repo(mutable_config, monkeypatch, mock_stage):
|
||||
repo_dir = pathlib.Path(spack.paths.test_repos_path) / "requirements_test"
|
||||
repo_dir = pathlib.Path(spack.paths.test_repos_path) / "spack_repo" / "requirements_test"
|
||||
with spack.repo.use_repositories(str(repo_dir)) as mock_repo_path:
|
||||
yield mock_repo_path
|
||||
|
||||
@ -766,21 +766,21 @@ def test_skip_requirement_when_default_requirement_condition_cannot_be_met(
|
||||
|
||||
def test_requires_directive(mock_packages, config):
|
||||
# This package requires either clang or gcc
|
||||
s = spack.concretize.concretize_one("requires_clang_or_gcc")
|
||||
s = spack.concretize.concretize_one("requires-clang-or-gcc")
|
||||
assert s.satisfies("%gcc")
|
||||
s = spack.concretize.concretize_one("requires_clang_or_gcc %gcc")
|
||||
s = spack.concretize.concretize_one("requires-clang-or-gcc %gcc")
|
||||
assert s.satisfies("%gcc")
|
||||
s = spack.concretize.concretize_one("requires_clang_or_gcc %clang")
|
||||
s = spack.concretize.concretize_one("requires-clang-or-gcc %clang")
|
||||
# Test both the real package (llvm) and its alias (clang)
|
||||
assert s.satisfies("%llvm") and s.satisfies("%clang")
|
||||
|
||||
# This package can only be compiled with clang
|
||||
s = spack.concretize.concretize_one("requires_clang")
|
||||
s = spack.concretize.concretize_one("requires-clang")
|
||||
assert s.satisfies("%llvm")
|
||||
s = spack.concretize.concretize_one("requires_clang %clang")
|
||||
s = spack.concretize.concretize_one("requires-clang %clang")
|
||||
assert s.satisfies("%llvm")
|
||||
with pytest.raises(spack.error.SpackError, match="can only be compiled with Clang"):
|
||||
spack.concretize.concretize_one("requires_clang %gcc")
|
||||
spack.concretize.concretize_one("requires-clang %gcc")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -2,7 +2,10 @@
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
import importlib
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
@ -43,7 +46,7 @@ def test_nonexisting_package_filename(self):
|
||||
repo = spack.repo.from_path(mock_packages_path)
|
||||
filename = repo.filename_for_package_name("some-nonexisting-package")
|
||||
assert filename == os.path.join(
|
||||
mock_packages_path, "packages", "some-nonexisting-package", "package.py"
|
||||
mock_packages_path, "packages", "some_nonexisting_package", "package.py"
|
||||
)
|
||||
|
||||
def test_package_class_names(self):
|
||||
@ -57,16 +60,19 @@ def test_package_class_names(self):
|
||||
assert "_None" == pkg_name_to_class_name("none") # reserved keyword
|
||||
assert "Finally" == pkg_name_to_class_name("finally") # `Finally` is not reserved
|
||||
|
||||
# Below tests target direct imports of spack packages from the
|
||||
# spack.pkg namespace
|
||||
def test_import_package(self):
|
||||
import spack.pkg.builtin_mock.mpich # type: ignore[import] # noqa: F401
|
||||
# Below tests target direct imports of spack packages from the spack.pkg namespace
|
||||
def test_import_package(self, tmp_path: pathlib.Path):
|
||||
root, _ = spack.repo.create_repo(str(tmp_path), "testing_repo", package_api=(1, 0))
|
||||
pkg_path = pathlib.Path(root) / "packages" / "mpich" / "package.py"
|
||||
pkg_path.parent.mkdir(parents=True)
|
||||
pkg_path.write_text("foo = 1")
|
||||
|
||||
def test_import_package_as(self):
|
||||
import spack.pkg.builtin_mock # noqa: F401
|
||||
import spack.pkg.builtin_mock as m # noqa: F401
|
||||
import spack.pkg.builtin_mock.mpich as mp # noqa: F401
|
||||
from spack.pkg.builtin import mock # noqa: F401
|
||||
with spack.repo.use_repositories(root):
|
||||
importlib.import_module("spack.pkg.testing_repo")
|
||||
assert importlib.import_module("spack.pkg.testing_repo.mpich").foo == 1
|
||||
|
||||
del sys.modules["spack.pkg.testing_repo"]
|
||||
del sys.modules["spack.pkg.testing_repo.mpich"]
|
||||
|
||||
def test_inheritance_of_directives(self):
|
||||
pkg_cls = spack.repo.PATH.get_pkg_class("simple-inheritance")
|
||||
@ -97,28 +103,11 @@ def test_inheritance_of_patches(self):
|
||||
# Will error if inheritor package cannot find inherited patch files
|
||||
_ = spack.concretize.concretize_one("patch-inheritance")
|
||||
|
||||
def test_import_class_from_package(self):
|
||||
from spack.pkg.builtin_mock.mpich import Mpich # noqa: F401
|
||||
|
||||
def test_import_module_from_package(self):
|
||||
from spack.pkg.builtin_mock import mpich # noqa: F401
|
||||
|
||||
def test_import_namespace_container_modules(self):
|
||||
import spack.pkg # noqa: F401
|
||||
import spack.pkg as p # noqa: F401
|
||||
import spack.pkg.builtin # noqa: F401
|
||||
import spack.pkg.builtin as b # noqa: F401
|
||||
import spack.pkg.builtin_mock # noqa: F401
|
||||
import spack.pkg.builtin_mock as m # noqa: F401
|
||||
from spack import pkg # noqa: F401
|
||||
from spack.pkg import builtin # noqa: F401
|
||||
from spack.pkg.builtin import mock # noqa: F401
|
||||
|
||||
|
||||
@pytest.mark.regression("2737")
|
||||
def test_urls_for_versions(mock_packages, config):
|
||||
"""Version directive without a 'url' argument should use default url."""
|
||||
for spec_str in ("url_override@0.9.0", "url_override@1.0.0"):
|
||||
for spec_str in ("url-override@0.9.0", "url-override@1.0.0"):
|
||||
s = spack.concretize.concretize_one(spec_str)
|
||||
url = s.package.url_for_version("0.9.0")
|
||||
assert url == "http://www.anothersite.org/uo-0.9.0.tgz"
|
||||
|
@ -93,15 +93,6 @@ def test_repo_invisibles(mutable_mock_repo, extra_repo):
|
||||
extra_repo[0].all_package_names()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("attr_name,exists", [("cmake", True), ("__sphinx_mock__", False)])
|
||||
@pytest.mark.regression("20661")
|
||||
def test_namespace_hasattr(attr_name, exists, mutable_mock_repo):
|
||||
# Check that we don't fail on 'hasattr' checks because
|
||||
# of a custom __getattr__ implementation
|
||||
nms = spack.repo.SpackNamespace("spack.pkg.builtin_mock")
|
||||
assert hasattr(nms, attr_name) == exists
|
||||
|
||||
|
||||
@pytest.mark.regression("24552")
|
||||
def test_all_package_names_is_cached_correctly(mock_packages):
|
||||
assert "mpi" in spack.repo.all_package_names(include_virtuals=True)
|
||||
@ -120,25 +111,20 @@ def test_use_repositories_doesnt_change_class(mock_packages):
|
||||
assert id(zlib_cls_inner) == id(zlib_cls_outer)
|
||||
|
||||
|
||||
def test_import_repo_prefixes_as_python_modules(mock_packages):
|
||||
import spack.pkg.builtin_mock
|
||||
|
||||
assert isinstance(spack.pkg, spack.repo.SpackNamespace)
|
||||
assert isinstance(spack.pkg.builtin, spack.repo.SpackNamespace)
|
||||
assert isinstance(spack.pkg.builtin_mock, spack.repo.SpackNamespace)
|
||||
|
||||
|
||||
def test_absolute_import_spack_packages_as_python_modules(mock_packages):
|
||||
import spack.pkg.builtin_mock.mpileaks
|
||||
import spack_repo.builtin_mock.packages.mpileaks.package # type: ignore[import]
|
||||
|
||||
assert hasattr(spack.pkg.builtin_mock, "mpileaks")
|
||||
assert hasattr(spack.pkg.builtin_mock.mpileaks, "Mpileaks")
|
||||
assert isinstance(spack.pkg.builtin_mock.mpileaks.Mpileaks, spack.package_base.PackageMeta)
|
||||
assert issubclass(spack.pkg.builtin_mock.mpileaks.Mpileaks, spack.package_base.PackageBase)
|
||||
assert hasattr(spack_repo.builtin_mock.packages.mpileaks.package, "Mpileaks")
|
||||
assert isinstance(
|
||||
spack_repo.builtin_mock.packages.mpileaks.package.Mpileaks, spack.package_base.PackageMeta
|
||||
)
|
||||
assert issubclass(
|
||||
spack_repo.builtin_mock.packages.mpileaks.package.Mpileaks, spack.package_base.PackageBase
|
||||
)
|
||||
|
||||
|
||||
def test_relative_import_spack_packages_as_python_modules(mock_packages):
|
||||
from spack.pkg.builtin_mock.mpileaks import Mpileaks
|
||||
from spack_repo.builtin_mock.packages.mpileaks.package import Mpileaks
|
||||
|
||||
assert isinstance(Mpileaks, spack.package_base.PackageMeta)
|
||||
assert issubclass(Mpileaks, spack.package_base.PackageBase)
|
||||
@ -220,11 +206,11 @@ def test_use_repositories_and_import():
|
||||
import spack.paths
|
||||
|
||||
repo_dir = pathlib.Path(spack.paths.test_repos_path)
|
||||
with spack.repo.use_repositories(str(repo_dir / "compiler_runtime_test")):
|
||||
import spack.pkg.compiler_runtime_test.gcc_runtime
|
||||
with spack.repo.use_repositories(str(repo_dir / "spack_repo" / "compiler_runtime_test")):
|
||||
import spack_repo.compiler_runtime_test.packages.gcc_runtime.package # type: ignore[import] # noqa: E501
|
||||
|
||||
with spack.repo.use_repositories(str(repo_dir / "builtin_mock")):
|
||||
import spack.pkg.builtin_mock.cmake
|
||||
with spack.repo.use_repositories(str(repo_dir / "spack_repo" / "builtin_mock")):
|
||||
import spack_repo.builtin_mock.packages.cmake.package # type: ignore[import] # noqa: F401
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("nullify_globals")
|
||||
@ -248,7 +234,7 @@ def test_is_virtual(self, repo_cls, name, expected, mock_test_cache):
|
||||
assert repo.is_virtual_safe(name) is expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"module_name,expected",
|
||||
"module_name,pkg_name",
|
||||
[
|
||||
("dla_future", "dla-future"),
|
||||
("num7zip", "7zip"),
|
||||
@ -256,12 +242,18 @@ def test_is_virtual(self, repo_cls, name, expected, mock_test_cache):
|
||||
("unknown", None),
|
||||
],
|
||||
)
|
||||
def test_real_name(self, module_name, expected, mock_test_cache):
|
||||
def test_real_name(self, module_name, pkg_name, mock_test_cache, tmp_path):
|
||||
"""Test that we can correctly compute the 'real' name of a package, from the one
|
||||
used to import the Python module.
|
||||
"""
|
||||
repo = spack.repo.Repo(spack.paths.mock_packages_path, cache=mock_test_cache)
|
||||
assert repo.real_name(module_name) == expected
|
||||
path, _ = spack.repo.create_repo(str(tmp_path), package_api=(1, 0))
|
||||
pkg_path = pathlib.Path(path) / "packages" / pkg_name / "package.py"
|
||||
pkg_path.parent.mkdir(parents=True)
|
||||
pkg_path.write_text("")
|
||||
repo = spack.repo.Repo(
|
||||
path, cache=spack.util.file_cache.FileCache(str(tmp_path / "cache"))
|
||||
)
|
||||
assert repo.real_name(module_name) == pkg_name
|
||||
|
||||
@pytest.mark.parametrize("name", ["mpileaks", "7zip", "dla-future"])
|
||||
def test_get(self, name, mock_test_cache):
|
||||
|
Loading…
Reference in New Issue
Block a user