uninstall : added unit tests
This commit is contained in:
parent
dd1c667d8d
commit
4f6320a7eb
5 changed files with 119 additions and 81 deletions
|
@ -67,7 +67,8 @@
|
|||
'namespace_trie',
|
||||
'yaml',
|
||||
'sbang',
|
||||
'environment']
|
||||
'environment',
|
||||
'cmd.uninstall']
|
||||
|
||||
|
||||
def list_tests():
|
||||
|
|
0
lib/spack/spack/test/cmd/__init__.py
Normal file
0
lib/spack/spack/test/cmd/__init__.py
Normal file
37
lib/spack/spack/test/cmd/uninstall.py
Normal file
37
lib/spack/spack/test/cmd/uninstall.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import spack.test.mock_database
|
||||
|
||||
from spack.cmd.uninstall import uninstall
|
||||
|
||||
|
||||
class MockArgs(object):
|
||||
def __init__(self, packages, all=False, force=False, recursive=False):
|
||||
self.packages = packages
|
||||
self.all = all
|
||||
self.force = force
|
||||
self.recursive = recursive
|
||||
self.yes_to_all = True
|
||||
|
||||
|
||||
class TestUninstall(spack.test.mock_database.MockDatabase):
|
||||
def test_uninstall(self):
|
||||
parser = None
|
||||
# Multiple matches
|
||||
args = MockArgs(['mpileaks'])
|
||||
self.assertRaises(SystemExit, uninstall, parser, args)
|
||||
# Installed dependents
|
||||
args = MockArgs(['libelf'])
|
||||
self.assertRaises(SystemExit, uninstall, parser, args)
|
||||
# Recursive uninstall
|
||||
args = MockArgs(['callpath'], all=True, recursive=True)
|
||||
uninstall(parser, args)
|
||||
|
||||
all_specs = spack.install_layout.all_specs()
|
||||
self.assertEqual(len(all_specs), 7)
|
||||
# query specs with multiple configurations
|
||||
mpileaks_specs = [s for s in all_specs if s.satisfies('mpileaks')]
|
||||
callpath_specs = [s for s in all_specs if s.satisfies('callpath')]
|
||||
mpi_specs = [s for s in all_specs if s.satisfies('mpi')]
|
||||
|
||||
self.assertEqual(len(mpileaks_specs), 0)
|
||||
self.assertEqual(len(callpath_specs), 0)
|
||||
self.assertEqual(len(mpi_specs), 3)
|
|
@ -28,16 +28,12 @@
|
|||
"""
|
||||
import os.path
|
||||
import multiprocessing
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import spack
|
||||
from llnl.util.filesystem import join_path
|
||||
from llnl.util.lock import *
|
||||
from llnl.util.tty.colify import colify
|
||||
from spack.database import Database
|
||||
from spack.directory_layout import YamlDirectoryLayout
|
||||
from spack.test.mock_packages_test import *
|
||||
from spack.test.mock_database import MockDatabase
|
||||
|
||||
|
||||
def _print_ref_counts():
|
||||
|
@ -75,80 +71,7 @@ def add_rec(spec):
|
|||
colify(recs, cols=3)
|
||||
|
||||
|
||||
class DatabaseTest(MockPackagesTest):
|
||||
|
||||
def _mock_install(self, spec):
|
||||
s = Spec(spec)
|
||||
s.concretize()
|
||||
pkg = spack.repo.get(s)
|
||||
pkg.do_install(fake=True)
|
||||
|
||||
|
||||
def _mock_remove(self, spec):
|
||||
specs = spack.installed_db.query(spec)
|
||||
assert(len(specs) == 1)
|
||||
spec = specs[0]
|
||||
spec.package.do_uninstall(spec)
|
||||
|
||||
|
||||
def setUp(self):
|
||||
super(DatabaseTest, self).setUp()
|
||||
#
|
||||
# TODO: make the mockup below easier.
|
||||
#
|
||||
|
||||
# Make a fake install directory
|
||||
self.install_path = tempfile.mkdtemp()
|
||||
self.spack_install_path = spack.install_path
|
||||
spack.install_path = self.install_path
|
||||
|
||||
self.install_layout = YamlDirectoryLayout(self.install_path)
|
||||
self.spack_install_layout = spack.install_layout
|
||||
spack.install_layout = self.install_layout
|
||||
|
||||
# Make fake database and fake install directory.
|
||||
self.installed_db = Database(self.install_path)
|
||||
self.spack_installed_db = spack.installed_db
|
||||
spack.installed_db = self.installed_db
|
||||
|
||||
# make a mock database with some packages installed note that
|
||||
# the ref count for dyninst here will be 3, as it's recycled
|
||||
# across each install.
|
||||
#
|
||||
# Here is what the mock DB looks like:
|
||||
#
|
||||
# o mpileaks o mpileaks' o mpileaks''
|
||||
# |\ |\ |\
|
||||
# | o callpath | o callpath' | o callpath''
|
||||
# |/| |/| |/|
|
||||
# o | mpich o | mpich2 o | zmpi
|
||||
# | | o | fake
|
||||
# | | |
|
||||
# | |______________/
|
||||
# | .____________/
|
||||
# |/
|
||||
# o dyninst
|
||||
# |\
|
||||
# | o libdwarf
|
||||
# |/
|
||||
# o libelf
|
||||
#
|
||||
|
||||
# Transaction used to avoid repeated writes.
|
||||
with spack.installed_db.write_transaction():
|
||||
self._mock_install('mpileaks ^mpich')
|
||||
self._mock_install('mpileaks ^mpich2')
|
||||
self._mock_install('mpileaks ^zmpi')
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
super(DatabaseTest, self).tearDown()
|
||||
shutil.rmtree(self.install_path)
|
||||
spack.install_path = self.spack_install_path
|
||||
spack.install_layout = self.spack_install_layout
|
||||
spack.installed_db = self.spack_installed_db
|
||||
|
||||
|
||||
class DatabaseTest(MockDatabase):
|
||||
def test_005_db_exists(self):
|
||||
"""Make sure db cache file exists after creating."""
|
||||
index_file = join_path(self.install_path, '.spack-db', 'index.yaml')
|
||||
|
@ -157,7 +80,6 @@ def test_005_db_exists(self):
|
|||
self.assertTrue(os.path.exists(index_file))
|
||||
self.assertTrue(os.path.exists(lock_file))
|
||||
|
||||
|
||||
def test_010_all_install_sanity(self):
|
||||
"""Ensure that the install layout reflects what we think it does."""
|
||||
all_specs = spack.install_layout.all_specs()
|
||||
|
|
78
lib/spack/spack/test/mock_database.py
Normal file
78
lib/spack/spack/test/mock_database.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
import shutil
|
||||
import tempfile
|
||||
|
||||
import spack
|
||||
from spack.spec import Spec
|
||||
from spack.database import Database
|
||||
from spack.directory_layout import YamlDirectoryLayout
|
||||
from spack.test.mock_packages_test import MockPackagesTest
|
||||
|
||||
|
||||
class MockDatabase(MockPackagesTest):
|
||||
def _mock_install(self, spec):
|
||||
s = Spec(spec)
|
||||
s.concretize()
|
||||
pkg = spack.repo.get(s)
|
||||
pkg.do_install(fake=True)
|
||||
|
||||
def _mock_remove(self, spec):
|
||||
specs = spack.installed_db.query(spec)
|
||||
assert(len(specs) == 1)
|
||||
spec = specs[0]
|
||||
spec.package.do_uninstall(spec)
|
||||
|
||||
def setUp(self):
|
||||
super(MockDatabase, self).setUp()
|
||||
#
|
||||
# TODO: make the mockup below easier.
|
||||
#
|
||||
|
||||
# Make a fake install directory
|
||||
self.install_path = tempfile.mkdtemp()
|
||||
self.spack_install_path = spack.install_path
|
||||
spack.install_path = self.install_path
|
||||
|
||||
self.install_layout = YamlDirectoryLayout(self.install_path)
|
||||
self.spack_install_layout = spack.install_layout
|
||||
spack.install_layout = self.install_layout
|
||||
|
||||
# Make fake database and fake install directory.
|
||||
self.installed_db = Database(self.install_path)
|
||||
self.spack_installed_db = spack.installed_db
|
||||
spack.installed_db = self.installed_db
|
||||
|
||||
# make a mock database with some packages installed note that
|
||||
# the ref count for dyninst here will be 3, as it's recycled
|
||||
# across each install.
|
||||
#
|
||||
# Here is what the mock DB looks like:
|
||||
#
|
||||
# o mpileaks o mpileaks' o mpileaks''
|
||||
# |\ |\ |\
|
||||
# | o callpath | o callpath' | o callpath''
|
||||
# |/| |/| |/|
|
||||
# o | mpich o | mpich2 o | zmpi
|
||||
# | | o | fake
|
||||
# | | |
|
||||
# | |______________/
|
||||
# | .____________/
|
||||
# |/
|
||||
# o dyninst
|
||||
# |\
|
||||
# | o libdwarf
|
||||
# |/
|
||||
# o libelf
|
||||
#
|
||||
|
||||
# Transaction used to avoid repeated writes.
|
||||
with spack.installed_db.write_transaction():
|
||||
self._mock_install('mpileaks ^mpich')
|
||||
self._mock_install('mpileaks ^mpich2')
|
||||
self._mock_install('mpileaks ^zmpi')
|
||||
|
||||
def tearDown(self):
|
||||
super(MockDatabase, self).tearDown()
|
||||
shutil.rmtree(self.install_path)
|
||||
spack.install_path = self.spack_install_path
|
||||
spack.install_layout = self.spack_install_layout
|
||||
spack.installed_db = self.spack_installed_db
|
Loading…
Reference in a new issue