def test_s3fetchstrategy_bad_url(tmpdir, _fetch_method): """Ensure fetch with bad URL fails as expected.""" testpath = str(tmpdir) with spack_config.override('config:url_fetch_method', _fetch_method): fetcher = spack_fs.S3FetchStrategy(url='file:///does-not-exist') assert fetcher is not None with spack_stage.Stage(fetcher, path=testpath) as stage: assert stage is not None assert fetcher.archive_file is None with pytest.raises(spack_fs.FetchError): fetcher.fetch()
def tmp_scope(): """Creates a temporary configuration scope""" base_name = 'internal-testing-scope' current_overrides = set( x.name for x in cfg.config.matching_scopes(r'^{0}'.format(base_name))) num_overrides = 0 scope_name = base_name while scope_name in current_overrides: scope_name = '{0}{1}'.format(base_name, num_overrides) num_overrides += 1 with cfg.override(cfg.InternalConfigScope(scope_name)): yield scope_name
def test_s3fetchstrategy_downloaded(tmpdir, _fetch_method): """Ensure fetch with archive file already downloaded is a noop.""" testpath = str(tmpdir) archive = os.path.join(testpath, 's3.tar.gz') with spack_config.override('config:url_fetch_method', _fetch_method): class Archived_S3FS(spack_fs.S3FetchStrategy): @property def archive_file(self): return archive url = 's3:///{0}'.format(archive) fetcher = Archived_S3FS(url=url) with spack_stage.Stage(fetcher, path=testpath): fetcher.fetch()
def test_s3fetchstrategy_sans_url(_fetch_method): """Ensure constructor with no URL fails.""" with spack_config.override('config:url_fetch_method', _fetch_method): with pytest.raises(ValueError): spack_fs.S3FetchStrategy(None)