def mock_fetch(mock_archive, monkeypatch): """Fake the URL for a package so it downloads from a file.""" mock_fetcher = FetchStrategyComposite() mock_fetcher.append(URLFetchStrategy(mock_archive.url)) monkeypatch.setattr( spack.package.PackageBase, 'fetcher', mock_fetcher)
def fetching_not_allowed(monkeypatch): class FetchingNotAllowed(spack.fetch_strategy.FetchStrategy): def mirror_id(self): return None def fetch(self): raise Exception("Sources are fetched but shouldn't have been") fetcher = FetchStrategyComposite() fetcher.append(FetchingNotAllowed()) monkeypatch.setattr(spack.package.PackageBase, 'fetcher', fetcher)
def mock_fetch(mock_archive): """Fake the URL for a package so it downloads from a file.""" fetcher = FetchStrategyComposite() fetcher.append(URLFetchStrategy(mock_archive.url)) @property def fake_fn(self): return fetcher orig_fn = PackageBase.fetcher PackageBase.fetcher = fake_fn yield PackageBase.fetcher = orig_fn
def mock_download(): """Mock a failing download strategy.""" class FailedDownloadStrategy(spack.fetch_strategy.FetchStrategy): def mirror_id(self): return None def fetch(self): raise spack.fetch_strategy.FailedDownloadError( "<non-existent URL>", "This FetchStrategy always fails") fetcher = FetchStrategyComposite() fetcher.append(FailedDownloadStrategy()) @property def fake_fn(self): return fetcher orig_fn = spack.package.PackageBase.fetcher spack.package.PackageBase.fetcher = fake_fn yield spack.package.PackageBase.fetcher = orig_fn
def fake_fetchify(url, pkg): """Fake the URL for a package so it downloads from a file.""" fetcher = FetchStrategyComposite() fetcher.append(URLFetchStrategy(url)) pkg.fetcher = fetcher