def test_handle_unknown_package( layout_and_dir, config, builtin_mock ): """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. """ layout, _ = layout_and_dir mock_db = RepoPath(spack.mock_packages_path) not_in_mock = set.difference( set(spack.repo.all_package_names()), set(mock_db.all_package_names())) packages = list(not_in_mock)[:max_packages] # Create all the packages that are not in mock. installed_specs = {} for pkg_name in packages: spec = spack.repo.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 Exception: continue layout.create_install_directory(spec) installed_specs[spec] = layout.path_for_spec(spec) spack.repo.swap(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 = layout.read_spec( join_path(path, '.spack', 'spec.yaml') ) # To satisfy these conditions, directory layouts need to # read in concrete specs from their install dirs somehow. assert path == layout.path_for_spec(spec_from_file) assert spec == spec_from_file assert spec.eq_dag(spec_from_file) assert spec.dag_hash() == spec_from_file.dag_hash() spack.repo.swap(mock_db)
def initmock(self): # Use the mock packages database for these tests. This allows # us to set up contrived packages that don't interfere with # real ones. self.db = RepoPath(spack.mock_packages_path) spack.repo.swap(self.db) # Mock up temporary configuration directories self.temp_config = tempfile.mkdtemp() self.mock_site_config = os.path.join(self.temp_config, 'site') self.mock_user_config = os.path.join(self.temp_config, 'user') mkdirp(self.mock_site_config) mkdirp(self.mock_user_config) for filename, data in mock_configs.items(): conf_yaml = os.path.join(self.mock_site_config, filename) with open(conf_yaml, 'w') as f: f.write(data) # TODO: Mocking this up is kind of brittle b/c ConfigScope # TODO: constructor modifies config_scopes. Make it cleaner. spack.config.clear_config_caches() self.real_scopes = spack.config.config_scopes spack.config.config_scopes = OrderedDict() spack.config.ConfigScope('site', self.mock_site_config) spack.config.ConfigScope('user', self.mock_user_config) # Keep tests from interfering with the actual module path. self.real_share_path = spack.share_path spack.share_path = tempfile.mkdtemp() # Store changes to the package's dependencies so we can # restore later. self.saved_deps = {}
def initmock(self): # Use the mock packages database for these tests. This allows # us to set up contrived packages that don't interfere with # real ones. self.db = RepoPath(spack.mock_packages_path) spack.repo.swap(self.db) spack.config.clear_config_caches() self.real_scopes = spack.config.config_scopes # Mock up temporary configuration directories self.temp_config = tempfile.mkdtemp() self.mock_site_config = os.path.join(self.temp_config, 'site') self.mock_user_config = os.path.join(self.temp_config, 'user') mkdirp(self.mock_site_config) mkdirp(self.mock_user_config) for confs in [('compilers.yaml', mock_compiler_config), ('packages.yaml', mock_packages_config)]: conf_yaml = os.path.join(self.mock_site_config, confs[0]) with open(conf_yaml, 'w') as f: f.write(confs[1]) # TODO: Mocking this up is kind of brittle b/c ConfigScope # TODO: constructor modifies config_scopes. Make it cleaner. spack.config.config_scopes = OrderedDict() spack.config.ConfigScope('site', self.mock_site_config) spack.config.ConfigScope('user', self.mock_user_config) # Store changes to the package's dependencies so we can # restore later. self.saved_deps = {}
def setup_main_options(args): """Configure spack globals based on the basic options.""" # Set up environment based on args. tty.set_verbose(args.verbose) tty.set_debug(args.debug) tty.set_stacktrace(args.stacktrace) spack.debug = args.debug if spack.debug: import spack.util.debug as debug debug.register_interrupt_handler() if args.mock: from spack.repository import RepoPath spack.repo.swap(RepoPath(spack.mock_packages_path)) # If the user asked for it, don't check ssl certs. if args.insecure: tty.warn("You asked for --insecure. Will NOT check SSL certificates.") spack.insecure = True
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)