summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/url_substitution.py
blob: 863afad2ea4dd4249c448dce80f7a1bb5615a970 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

"""Tests Spack's ability to substitute a different version into a URL."""

import os

import pytest

import spack.url


@pytest.mark.parametrize(
    "base_url,version,expected",
    [
        # Ensures that substituting the same version results in the same URL
        (
            "http://www.mr511.de/software/libelf-0.8.13.tar.gz",
            "0.8.13",
            "http://www.mr511.de/software/libelf-0.8.13.tar.gz",
        ),
        # Test a completely different version syntax
        (
            "http://www.prevanders.net/libdwarf-20130729.tar.gz",
            "8.12",
            "http://www.prevanders.net/libdwarf-8.12.tar.gz",
        ),
        # Test a URL where the version appears twice
        # It should get substituted both times
        (
            "https://github.com/hpc/mpileaks/releases/download/v1.0/mpileaks-1.0.tar.gz",
            "2.1.3",
            "https://github.com/hpc/mpileaks/releases/download/v2.1.3/mpileaks-2.1.3.tar.gz",
        ),
        # Test now with a partial prefix earlier in the URL
        # This is hard to figure out so Spack only substitutes
        # the last instance of the version
        (
            "https://www.open-mpi.org/software/ompi/v2.1/downloads/openmpi-2.1.0.tar.bz2",
            "2.2.0",
            "https://www.open-mpi.org/software/ompi/v2.1/downloads/openmpi-2.2.0.tar.bz2",
        ),
        (
            "https://www.open-mpi.org/software/ompi/v2.1/downloads/openmpi-2.1.0.tar.bz2",
            "2.2",
            "https://www.open-mpi.org/software/ompi/v2.1/downloads/openmpi-2.2.tar.bz2",
        ),
        # No separator between the name and version of the package
        (
            "file://{0}/turbolinux702.tar.gz".format(os.getcwd()),
            "703",
            "file://{0}/turbolinux703.tar.gz".format(os.getcwd()),
        ),
        (
            "https://github.com/losalamos/CLAMR/blob/packages/PowerParser_v2.0.7.tgz?raw=true",
            "2.0.7",
            "https://github.com/losalamos/CLAMR/blob/packages/PowerParser_v2.0.7.tgz?raw=true",
        ),
        (
            "https://github.com/losalamos/CLAMR/blob/packages/PowerParser_v2.0.7.tgz?raw=true",
            "4.7",
            "https://github.com/losalamos/CLAMR/blob/packages/PowerParser_v4.7.tgz?raw=true",
        ),
        # Package name contains regex characters
        (
            "http://math.lbl.gov/voro++/download/dir/voro++-0.4.6.tar.gz",
            "1.2.3",
            "http://math.lbl.gov/voro++/download/dir/voro++-1.2.3.tar.gz",
        ),
    ],
)
def test_url_substitution(base_url, version, expected):
    computed = spack.url.substitute_version(base_url, version)
    assert computed == expected