def setUp(self): super(InstallTest, self).setUp() self.stage = Stage('not_a_real_url') archive_dir = join_path(self.stage.path, dir_name) dummy_configure = join_path(archive_dir, 'configure') mkdirp(archive_dir) with closing(open(dummy_configure, 'w')) as configure: configure.write("#!/bin/sh\n" "prefix=$(echo $1 | sed 's/--prefix=//')\n" "cat > Makefile <<EOF\n" "all:\n" "\techo Building...\n\n" "install:\n" "\tmkdir -p $prefix\n" "\ttouch $prefix/dummy_file\n" "EOF\n") os.chmod(dummy_configure, 0755) with working_dir(self.stage.path): tar = which('tar') tar('-czf', archive_name, dir_name) # We use a fake package, so skip the checksum. spack.do_checksum = False # Use a fake install directory to avoid conflicts bt/w # installed pkgs and mock packages. self.tmpdir = tempfile.mkdtemp() self.orig_layout = spack.install_layout spack.install_layout = SpecHashDirectoryLayout(self.tmpdir)
def setUp(self): super(InstallTest, self).setUp() # create a simple installable package directory and tarball self.repo = MockArchive() # We use a fake package, so skip the checksum. spack.do_checksum = False # Use a fake install directory to avoid conflicts bt/w # installed pkgs and mock packages. self.tmpdir = tempfile.mkdtemp() self.orig_layout = spack.install_layout spack.install_layout = SpecHashDirectoryLayout(self.tmpdir)
# # Paths to mock files for testing. # mock_packages_path = join_path(var_path, "mock_packages") mock_config_path = join_path(var_path, "mock_configs") mock_site_config = join_path(mock_config_path, "site_spackconfig") mock_user_config = join_path(mock_config_path, "user_spackconfig") # # This controls how spack lays out install prefixes and # stage directories. # from spack.directory_layout import SpecHashDirectoryLayout install_layout = SpecHashDirectoryLayout(install_path) # # This controls how things are concretized in spack. # Replace it with a subclass if you want different # policies. # from spack.concretize import DefaultConcretizer concretizer = DefaultConcretizer() # Version information from spack.version import Version spack_version = Version("0.8") # # Executables used by Spack
def setUp(self): self.tmpdir = tempfile.mkdtemp() self.layout = SpecHashDirectoryLayout(self.tmpdir)
class DirectoryLayoutTest(unittest.TestCase): """Tests that a directory layout works correctly and produces a consistent install path.""" def setUp(self): self.tmpdir = tempfile.mkdtemp() self.layout = SpecHashDirectoryLayout(self.tmpdir) def tearDown(self): shutil.rmtree(self.tmpdir, ignore_errors=True) self.layout = None def test_read_and_write_spec(self): """This goes through each package in spack and creates a directory for it. It then ensures that the spec for the directory's installed package can be read back in consistently, and finally that the directory can be removed by the directory layout. """ for pkg in spack.db.all_packages(): spec = pkg.spec # If a spec fails to concretize, just skip it. If it is a # real error, it will be caught by concretization tests. try: spec.concretize() except: continue self.layout.make_path_for_spec(spec) install_dir = self.layout.path_for_spec(spec) spec_path = self.layout.spec_file_path(spec) # Ensure directory has been created in right place. self.assertTrue(os.path.isdir(install_dir)) self.assertTrue(install_dir.startswith(self.tmpdir)) # Ensure spec file exists when directory is created self.assertTrue(os.path.isfile(spec_path)) self.assertTrue(spec_path.startswith(install_dir)) # Make sure spec file can be read back in to get the original spec spec_from_file = self.layout.read_spec(spec_path) self.assertEqual(spec, spec_from_file) self.assertTrue(spec.eq_dag, spec_from_file) self.assertTrue(spec_from_file.concrete) # Ensure that specs that come out "normal" are really normal. with closing(open(spec_path)) as spec_file: read_separately = Spec(spec_file.read()) read_separately.normalize() self.assertEqual(read_separately, spec_from_file) read_separately.concretize() self.assertEqual(read_separately, spec_from_file) # Make sure the dep hash of the read-in spec is the same self.assertEqual(spec.dep_hash(), spec_from_file.dep_hash()) # Ensure directories are properly removed self.layout.remove_path_for_spec(spec) self.assertFalse(os.path.isdir(install_dir)) self.assertFalse(os.path.exists(install_dir)) def test_handle_unknown_package(self): """This test ensures that spack can at least do *some* operations with packages that are installed but that it does not know about. This is actually not such an uncommon scenario with spack; it can happen when you switch from a git branch where you're working on a new package. This test ensures that the directory layout stores enough information about installed packages' specs to uninstall or query them again if the package goes away. """ mock_db = PackageDB(spack.mock_packages_path) not_in_mock = set(spack.db.all_package_names()).difference( set(mock_db.all_package_names())) # Create all the packages that are not in mock. installed_specs = {} for pkg_name in not_in_mock: spec = spack.db.get(pkg_name).spec # If a spec fails to concretize, just skip it. If it is a # real error, it will be caught by concretization tests. try: spec.concretize() except: continue self.layout.make_path_for_spec(spec) installed_specs[spec] = self.layout.path_for_spec(spec) tmp = spack.db spack.db = mock_db # Now check that even without the package files, we know # enough to read a spec from the spec file. for spec, path in installed_specs.items(): spec_from_file = self.layout.read_spec(join_path(path, '.spec')) # To satisfy these conditions, directory layouts need to # read in concrete specs from their install dirs somehow. self.assertEqual(path, self.layout.path_for_spec(spec_from_file)) self.assertEqual(spec, spec_from_file) self.assertEqual(spec.dep_hash(), spec_from_file.dep_hash()) spack.db = tmp