summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@googlemail.com>2016-03-31 13:22:48 +0200
committerMassimiliano Culpo <massimiliano.culpo@googlemail.com>2016-03-31 13:22:48 +0200
commit4f6320a7eb14f7d09c1e31a92d224e54e32c3921 (patch)
tree188a6a5518251b36fa39664de3ca0df6b3bea195 /lib
parentdd1c667d8d5d260146f81b0b90ad52c41160208e (diff)
downloadspack-4f6320a7eb14f7d09c1e31a92d224e54e32c3921.tar.gz
spack-4f6320a7eb14f7d09c1e31a92d224e54e32c3921.tar.bz2
spack-4f6320a7eb14f7d09c1e31a92d224e54e32c3921.tar.xz
spack-4f6320a7eb14f7d09c1e31a92d224e54e32c3921.zip
uninstall : added unit tests
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/__init__.py3
-rw-r--r--lib/spack/spack/test/cmd/__init__.py0
-rw-r--r--lib/spack/spack/test/cmd/uninstall.py37
-rw-r--r--lib/spack/spack/test/database.py82
-rw-r--r--lib/spack/spack/test/mock_database.py78
5 files changed, 119 insertions, 81 deletions
diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py
index cd842561e6..175a49428c 100644
--- a/lib/spack/spack/test/__init__.py
+++ b/lib/spack/spack/test/__init__.py
@@ -67,7 +67,8 @@ test_names = ['versions',
'namespace_trie',
'yaml',
'sbang',
- 'environment']
+ 'environment',
+ 'cmd.uninstall']
def list_tests():
diff --git a/lib/spack/spack/test/cmd/__init__.py b/lib/spack/spack/test/cmd/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/lib/spack/spack/test/cmd/__init__.py
diff --git a/lib/spack/spack/test/cmd/uninstall.py b/lib/spack/spack/test/cmd/uninstall.py
new file mode 100644
index 0000000000..06a24e2958
--- /dev/null
+++ b/lib/spack/spack/test/cmd/uninstall.py
@@ -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)
diff --git a/lib/spack/spack/test/database.py b/lib/spack/spack/test/database.py
index ce6e8a0552..465263d057 100644
--- a/lib/spack/spack/test/database.py
+++ b/lib/spack/spack/test/database.py
@@ -28,16 +28,12 @@ both in memory and in its file
"""
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 _print_ref_counts():
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 @@ class DatabaseTest(MockPackagesTest):
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()
diff --git a/lib/spack/spack/test/mock_database.py b/lib/spack/spack/test/mock_database.py
new file mode 100644
index 0000000000..6fd05439bf
--- /dev/null
+++ b/lib/spack/spack/test/mock_database.py
@@ -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