test/package_sanity.py: ported to pytest (#3474)

This commit is contained in:
Massimiliano Culpo 2017-03-31 22:42:04 +02:00 committed by Todd Gamblin
parent ee7753a597
commit 0c44dd28bb

View File

@ -22,49 +22,48 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
"""\
This test does sanity checks on Spack's builtin package database.
"""
import unittest
"""This test does sanity checks on Spack's builtin package database."""
import re
import spack
from spack.repository import RepoPath
class PackageSanityTest(unittest.TestCase):
def check_db():
"""Get all packages in a DB to make sure they work."""
for name in spack.repo.all_package_names():
spack.repo.get(name)
def check_db(self):
"""Get all packages in a DB to make sure they work."""
for name in spack.repo.all_package_names():
spack.repo.get(name)
def test_get_all_packages(self):
"""Get all packages once and make sure that works."""
self.check_db()
def test_get_all_packages():
"""Get all packages once and make sure that works."""
check_db()
def test_get_all_mock_packages(self):
"""Get the mock packages once each too."""
db = RepoPath(spack.mock_packages_path)
spack.repo.swap(db)
self.check_db()
spack.repo.swap(db)
def test_url_versions(self):
"""Check URLs for regular packages, if they are explicitly defined."""
for pkg in spack.repo.all_packages():
for v, vattrs in pkg.versions.items():
if 'url' in vattrs:
# If there is a url for the version check it.
v_url = pkg.url_for_version(v)
self.assertEqual(vattrs['url'], v_url)
def test_get_all_mock_packages():
"""Get the mock packages once each too."""
db = RepoPath(spack.mock_packages_path)
spack.repo.swap(db)
check_db()
spack.repo.swap(db)
def test_all_versions_are_lowercase(self):
"""Spack package names must be lowercase, and use `-` instead of `_`.
"""
errors = []
for name in spack.repo.all_package_names():
if re.search(r'[_A-Z]', name):
errors.append(name)
self.assertEqual([], errors)
def test_url_versions():
"""Check URLs for regular packages, if they are explicitly defined."""
for pkg in spack.repo.all_packages():
for v, vattrs in pkg.versions.items():
if 'url' in vattrs:
# If there is a url for the version check it.
v_url = pkg.url_for_version(v)
assert vattrs['url'] == v_url
def test_all_versions_are_lowercase():
"""Spack package names must be lowercase, and use `-` instead of `_`."""
errors = []
for name in spack.repo.all_package_names():
if re.search(r'[_A-Z]', name):
errors.append(name)
assert len(errors) == 0