Skip to content

Commit

Permalink
url_substitution: ported to pytest (spack#4032)
Browse files Browse the repository at this point in the history
  • Loading branch information
alalazo authored and tgamblin committed May 1, 2017
1 parent 9f46bc8 commit b3ce04c
Showing 1 changed file with 34 additions and 54 deletions.
88 changes: 34 additions & 54 deletions lib/spack/spack/test/url_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b3ce04c

Please sign in to comment.