class FileCacheTest(unittest.TestCase): """Ensure that a file cache can properly write to a file and recover its contents.""" def setUp(self): self.scratch_dir = tempfile.mkdtemp() self.cache = FileCache(self.scratch_dir) def tearDown(self): shutil.rmtree(self.scratch_dir) def test_write_and_read_cache_file(self): """Test writing then reading a cached file.""" with self.cache.write_transaction('test.yaml') as (old, new): self.assertTrue(old is None) self.assertTrue(new is not None) new.write("foobar\n") with self.cache.read_transaction('test.yaml') as stream: text = stream.read() self.assertEqual("foobar\n", text) def test_remove(self): """Test removing an entry from the cache.""" self.test_write_and_write_cache_file() self.cache.remove('test.yaml') self.assertFalse(os.path.exists(self.cache.cache_path('test.yaml'))) self.assertFalse(os.path.exists(self.cache._lock_path('test.yaml'))) def test_write_and_write_cache_file(self): """Test two write transactions on a cached file.""" with self.cache.write_transaction('test.yaml') as (old, new): self.assertTrue(old is None) self.assertTrue(new is not None) new.write("foobar\n") with self.cache.write_transaction('test.yaml') as (old, new): self.assertTrue(old is not None) text = old.read() self.assertEqual("foobar\n", text) self.assertTrue(new is not None) new.write("barbaz\n") with self.cache.read_transaction('test.yaml') as stream: text = stream.read() self.assertEqual("barbaz\n", text)
def file_cache(tmpdir): """Returns a properly initialized FileCache instance""" return FileCache(str(tmpdir))
concretizer = DefaultConcretizer() #----------------------------------------------------------------------------- # config.yaml options #----------------------------------------------------------------------------- _config = spack.config.get_config('config') # Path where downloaded source code is cached cache_path = canonicalize_path( _config.get('source_cache', join_path(var_path, "cache"))) fetch_cache = spack.fetch_strategy.FsCache(cache_path) # cache for miscellaneous stuff. misc_cache_path = canonicalize_path( _config.get('misc_cache', join_path(user_config_path, 'cache'))) misc_cache = FileCache(misc_cache_path) # If this is enabled, tools that use SSL should not verify # certifiates. e.g., curl should use the -k option. insecure = not _config.get('verify_ssl', True) # Whether spack should allow installation of unsafe versions of software. # "Unsafe" versions are ones it doesn't have a checksum for. do_checksum = _config.get('checksum', True) # If this is True, spack will not clean the environment to remove # potentially harmful variables before builds. dirty = _config.get('dirty', False) #----------------------------------------------------------------------------- # When packages call 'from spack import *', this extra stuff is brought in.
def setUp(self): self.scratch_dir = tempfile.mkdtemp() self.cache = FileCache(self.scratch_dir)