summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGregory Becker <becker33@llnl.gov>2015-09-17 11:29:27 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2015-09-27 17:54:24 -0700
commit5fda7daf57e2362c803d4f2152da93ed270818d9 (patch)
tree2817f4f21b96a98fa8c15e9654ca25a084477a46 /lib
parentd0e22b22406c8fb064031dbd4ac887b7a9abbc95 (diff)
downloadspack-5fda7daf57e2362c803d4f2152da93ed270818d9.tar.gz
spack-5fda7daf57e2362c803d4f2152da93ed270818d9.tar.bz2
spack-5fda7daf57e2362c803d4f2152da93ed270818d9.tar.xz
spack-5fda7daf57e2362c803d4f2152da93ed270818d9.zip
an ordered database test
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/__init__.py3
-rw-r--r--lib/spack/spack/test/database.py104
2 files changed, 106 insertions, 1 deletions
diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py
index 6b3715be6f..c3b39b76f8 100644
--- a/lib/spack/spack/test/__init__.py
+++ b/lib/spack/spack/test/__init__.py
@@ -56,7 +56,8 @@ test_names = ['versions',
'spec_yaml',
'optional_deps',
'make_executable',
- 'configure_guess']
+ 'configure_guess',
+ 'database']
def list_tests():
diff --git a/lib/spack/spack/test/database.py b/lib/spack/spack/test/database.py
new file mode 100644
index 0000000000..a3386bad99
--- /dev/null
+++ b/lib/spack/spack/test/database.py
@@ -0,0 +1,104 @@
+##############################################################################
+# Copyright (c) 2013, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://scalability-llnl.github.io/spack
+# Please also see the LICENSE file for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License (as published by
+# the Free Software Foundation) version 2.1 dated February 1999.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
+# conditions of the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+"""
+These tests check the database is functioning properly,
+both in memory and in its file
+"""
+import unittest
+
+from llnl.util.lock import *
+from llnl.util.filesystem import join_path
+
+import spack
+from spack.database import Database
+
+
+class DatabaseTest(unittest.TestCase):
+ def setUp(self):
+ self.original_db = spack.installed_db
+ spack.installed_db = Database(self.original_db._root,"_test_index.yaml")
+ self.file_path = join_path(self.original_db._root,"_test_index.yaml")
+ if os.path.exists(self.file_path):
+ os.remove(self.file_path)
+
+ def tearDown(self):
+ spack.installed_db = self.original_db
+ os.remove(self.file_path)
+
+ def _test_read_from_install_tree(self):
+ specs = spack.install_layout.all_specs()
+ spack.installed_db.read_database()
+ spack.installed_db.write()
+ for sph in spack.installed_db._data:
+ self.assertTrue(sph['spec'] in specs)
+ self.assertEqual(len(specs),len(spack.installed_db._data))
+
+ def _test_remove_and_add(self):
+ specs = spack.install_layout.all_specs()
+ spack.installed_db.remove(specs[len(specs)-1])
+ for sph in spack.installed_db._data:
+ self.assertTrue(sph['spec'] in specs[:len(specs)-1])
+ self.assertEqual(len(specs)-1,len(spack.installed_db._data))
+
+ spack.installed_db.add(specs[len(specs)-1],"")
+ for sph in spack.installed_db._data:
+ self.assertTrue(sph['spec'] in specs)
+ self.assertEqual(len(specs),len(spack.installed_db._data))
+
+ def _test_read_from_file(self):
+ spack.installed_db.read_database()
+ size = len(spack.installed_db._data)
+ spack.installed_db._data = spack.installed_db._data[1:]
+ os.utime(spack.installed_db._file_path,None)
+ spack.installed_db.read_database()
+ self.assertEqual(size,len(spack.installed_db._data))
+
+ specs = spack.install_layout.all_specs()
+ self.assertEqual(size,len(specs))
+ for sph in spack.installed_db._data:
+ self.assertTrue(sph['spec'] in specs)
+
+
+ def _test_write_to_file(self):
+ spack.installed_db.read_database()
+ size = len(spack.installed_db._data)
+ real_data = spack.installed_db._data
+ spack.installed_db._data = real_data[:size-1]
+ spack.installed_db.write()
+ spack.installed_db._data = real_data
+ os.utime(spack.installed_db._file_path,None)
+ spack.installed_db.read_database()
+ self.assertEqual(size-1,len(spack.installed_db._data))
+
+ specs = spack.install_layout.all_specs()
+ self.assertEqual(size,len(specs))
+ for sph in spack.installed_db._data:
+ self.assertTrue(sph['spec'] in specs[:size-1])
+
+ def test_ordered_test(self):
+ self._test_read_from_install_tree()
+ self._test_remove_and_add()
+ self._test_read_from_file()
+ self._test_write_to_file()