summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/test/conftest.py10
-rw-r--r--lib/spack/spack/test/spec_semantics.py52
-rw-r--r--lib/spack/spack/test/spec_syntax.py8
3 files changed, 46 insertions, 24 deletions
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index 543cfb4b2f..f25cf42e6c 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -55,6 +55,7 @@ import spack.util.git
import spack.util.gpg
import spack.util.spack_yaml as syaml
import spack.util.url as url_util
+import spack.version
from spack.fetch_strategy import URLFetchStrategy
from spack.util.pattern import Bunch
@@ -1440,6 +1441,15 @@ def mock_git_repository(git, tmpdir_factory):
yield t
+@pytest.fixture(scope="function")
+def mock_git_test_package(mock_git_repository, mutable_mock_repo, monkeypatch):
+ # install a fake git version in the package class
+ pkg_class = spack.repo.PATH.get_pkg_class("git-test")
+ monkeypatch.delattr(pkg_class, "git")
+ monkeypatch.setitem(pkg_class.versions, spack.version.Version("git"), mock_git_repository.url)
+ return pkg_class
+
+
@pytest.fixture(scope="session")
def mock_hg_repository(tmpdir_factory):
"""Creates a very simple hg repository with two commits."""
diff --git a/lib/spack/spack/test/spec_semantics.py b/lib/spack/spack/test/spec_semantics.py
index 7a075b3710..2f4e7f43a4 100644
--- a/lib/spack/spack/test/spec_semantics.py
+++ b/lib/spack/spack/test/spec_semantics.py
@@ -1096,22 +1096,22 @@ class TestSpecSemantics:
@pytest.mark.parametrize(
"spec_str,format_str,expected",
[
- ("zlib@git.foo/bar", "{name}-{version}", str(pathlib.Path("zlib-git.foo_bar"))),
- ("zlib@git.foo/bar", "{name}-{version}-{/hash}", None),
- ("zlib@git.foo/bar", "{name}/{version}", str(pathlib.Path("zlib", "git.foo_bar"))),
+ ("git-test@git.foo/bar", "{name}-{version}", str(pathlib.Path("git-test-git.foo_bar"))),
+ ("git-test@git.foo/bar", "{name}-{version}-{/hash}", None),
+ ("git-test@git.foo/bar", "{name}/{version}", str(pathlib.Path("git-test", "git.foo_bar"))),
(
- "zlib@{0}=1.0%gcc".format("a" * 40),
+ "git-test@{0}=1.0%gcc".format("a" * 40),
"{name}/{version}/{compiler}",
- str(pathlib.Path("zlib", "{0}_1.0".format("a" * 40), "gcc")),
+ str(pathlib.Path("git-test", "{0}_1.0".format("a" * 40), "gcc")),
),
(
- "zlib@git.foo/bar=1.0%gcc",
+ "git-test@git.foo/bar=1.0%gcc",
"{name}/{version}/{compiler}",
- str(pathlib.Path("zlib", "git.foo_bar_1.0", "gcc")),
+ str(pathlib.Path("git-test", "git.foo_bar_1.0", "gcc")),
),
],
)
-def test_spec_format_path(spec_str, format_str, expected):
+def test_spec_format_path(spec_str, format_str, expected, mock_git_test_package):
_check_spec_format_path(spec_str, format_str, expected)
@@ -1129,45 +1129,57 @@ def _check_spec_format_path(spec_str, format_str, expected, path_ctor=None):
"spec_str,format_str,expected",
[
(
- "zlib@git.foo/bar",
+ "git-test@git.foo/bar",
r"C:\\installroot\{name}\{version}",
- r"C:\installroot\zlib\git.foo_bar",
+ r"C:\installroot\git-test\git.foo_bar",
),
(
- "zlib@git.foo/bar",
+ "git-test@git.foo/bar",
r"\\hostname\sharename\{name}\{version}",
- r"\\hostname\sharename\zlib\git.foo_bar",
+ r"\\hostname\sharename\git-test\git.foo_bar",
),
# Windows doesn't attribute any significance to a leading
# "/" so it is discarded
- ("zlib@git.foo/bar", r"/installroot/{name}/{version}", r"installroot\zlib\git.foo_bar"),
+ (
+ "git-test@git.foo/bar",
+ r"/installroot/{name}/{version}",
+ r"installroot\git-test\git.foo_bar",
+ ),
],
)
-def test_spec_format_path_windows(spec_str, format_str, expected):
+def test_spec_format_path_windows(spec_str, format_str, expected, mock_git_test_package):
_check_spec_format_path(spec_str, format_str, expected, path_ctor=pathlib.PureWindowsPath)
@pytest.mark.parametrize(
"spec_str,format_str,expected",
[
- ("zlib@git.foo/bar", r"/installroot/{name}/{version}", "/installroot/zlib/git.foo_bar"),
- ("zlib@git.foo/bar", r"//installroot/{name}/{version}", "//installroot/zlib/git.foo_bar"),
+ (
+ "git-test@git.foo/bar",
+ r"/installroot/{name}/{version}",
+ "/installroot/git-test/git.foo_bar",
+ ),
+ (
+ "git-test@git.foo/bar",
+ r"//installroot/{name}/{version}",
+ "//installroot/git-test/git.foo_bar",
+ ),
# This is likely unintentional on Linux: Firstly, "\" is not a
# path separator for POSIX, so this is treated as a single path
# component (containing literal "\" characters); secondly,
# Spec.format treats "\" as an escape character, so is
# discarded (unless directly following another "\")
(
- "zlib@git.foo/bar",
+ "git-test@git.foo/bar",
r"C:\\installroot\package-{name}-{version}",
- r"C__installrootpackage-zlib-git.foo_bar",
+ r"C__installrootpackage-git-test-git.foo_bar",
),
# "\" is not a POSIX separator, and Spec.format treats "\{" as a literal
# "{", which means that the resulting format string is invalid
- ("zlib@git.foo/bar", r"package\{name}\{version}", None),
+ ("git-test@git.foo/bar", r"package\{name}\{version}", None),
],
)
-def test_spec_format_path_posix(spec_str, format_str, expected):
+def test_spec_format_path_posix(spec_str, format_str, expected, mock_git_test_package):
_check_spec_format_path(spec_str, format_str, expected, path_ctor=pathlib.PurePosixPath)
diff --git a/lib/spack/spack/test/spec_syntax.py b/lib/spack/spack/test/spec_syntax.py
index 49f6de3b65..2e6f4b4fba 100644
--- a/lib/spack/spack/test/spec_syntax.py
+++ b/lib/spack/spack/test/spec_syntax.py
@@ -551,12 +551,12 @@ def specfile_for(default_mock_concretization):
"^[deptypes=build,link] zlib",
),
(
- "zlib@git.foo/bar",
+ "git-test@git.foo/bar",
[
- Token(TokenType.UNQUALIFIED_PACKAGE_NAME, "zlib"),
+ Token(TokenType.UNQUALIFIED_PACKAGE_NAME, "git-test"),
Token(TokenType.GIT_VERSION, "@git.foo/bar"),
],
- "zlib@git.foo/bar",
+ "git-test@git.foo/bar",
),
# Variant propagation
(
@@ -585,7 +585,7 @@ def specfile_for(default_mock_concretization):
),
],
)
-def test_parse_single_spec(spec_str, tokens, expected_roundtrip):
+def test_parse_single_spec(spec_str, tokens, expected_roundtrip, mock_git_test_package):
parser = SpecParser(spec_str)
assert tokens == parser.tokens()
assert expected_roundtrip == str(parser.next_spec())