summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@googlemail.com>2017-05-01 10:41:48 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2017-05-01 01:41:48 -0700
commitb3ce04cba3262865a1a2242f69c7f11d75e6c595 (patch)
treed0a73d92615c423c5fbfcbdea553c8b60282e207 /lib
parent9f46bc89975c3bf24439ac58b6aeace973bc838f (diff)
downloadspack-b3ce04cba3262865a1a2242f69c7f11d75e6c595.tar.gz
spack-b3ce04cba3262865a1a2242f69c7f11d75e6c595.tar.bz2
spack-b3ce04cba3262865a1a2242f69c7f11d75e6c595.tar.xz
spack-b3ce04cba3262865a1a2242f69c7f11d75e6c595.zip
url_substitution: ported to pytest (#4032)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/url_substitution.py88
1 files changed, 34 insertions, 54 deletions
diff --git a/lib/spack/spack/test/url_substitution.py b/lib/spack/spack/test/url_substitution.py
index 449a3b29bf..61bd178db8 100644
--- a/lib/spack/spack/test/url_substitution.py
+++ b/lib/spack/spack/test/url_substitution.py
@@ -25,61 +25,41 @@
"""Tests Spack's ability to substitute a different version into a URL."""
import os
-import unittest
-from spack.url import substitute_version
+import pytest
+import spack.url
-class UrlSubstitutionTest(unittest.TestCase):
- def check(self, base, version, new_url):
- self.assertEqual(substitute_version(base, version), new_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())),
- def test_same_version(self):
- # Ensures that substituting the same version results in the same URL
- self.check(
- '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')
-
- def test_different_version(self):
- # Test a completely different version syntax
- self.check(
- 'http://www.prevanders.net/libdwarf-20130729.tar.gz', '8.12',
- 'http://www.prevanders.net/libdwarf-8.12.tar.gz')
-
- def test_double_version(self):
- # Test a URL where the version appears twice
- # It should get substituted both times
- self.check(
- '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')
-
- def test_partial_version_prefix(self):
- # 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
- self.check(
- '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')
- self.check(
- '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')
-
- def test_no_separator(self):
- # No separator between the name and version of the package
- self.check(
- 'file://{0}/turbolinux702.tar.gz'.format(os.getcwd()), '703',
- 'file://{0}/turbolinux703.tar.gz'.format(os.getcwd()))
-
- def test_github_raw(self):
- self.check(
- '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')
- self.check(
- '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')
-
- def test_regex(self):
- # Package name contains regex characters
- self.check(
- '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')
+ ('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