def test_obtain_file(self): """Test obtain_file method.""" toy_tarball = 'toy-0.0.tar.gz' testdir = os.path.abspath(os.path.dirname(__file__)) sandbox_sources = os.path.join(testdir, 'sandbox', 'sources') toy_tarball_path = os.path.join(sandbox_sources, 'toy', toy_tarball) tmpdir = tempfile.mkdtemp() tmpdir_subdir = os.path.join(tmpdir, 'testing') mkdir(tmpdir_subdir, parents=True) del os.environ['EASYBUILD_SOURCEPATH'] # defined by setUp ec = process_easyconfig(os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb'))[0] eb = EasyBlock(ec['ec']) # 'downloading' a file to (first) sourcepath works init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (tmpdir, testdir)]) shutil.copy2(toy_tarball_path, tmpdir_subdir) res = eb.obtain_file(toy_tarball, urls=['file://%s' % tmpdir_subdir]) self.assertEqual(res, os.path.join(tmpdir, 't', 'toy', toy_tarball)) # finding a file in sourcepath works init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (sandbox_sources, tmpdir)]) res = eb.obtain_file(toy_tarball) self.assertEqual(res, toy_tarball_path) # sourcepath has preference over downloading res = eb.obtain_file(toy_tarball, urls=['file://%s' % tmpdir_subdir]) self.assertEqual(res, toy_tarball_path) # obtain_file yields error for non-existing files fn = 'thisisclearlyanonexistingfile' error_regex = "Couldn't find file %s anywhere, and downloading it didn't work either" % fn self.assertErrorRegex(EasyBuildError, error_regex, eb.obtain_file, fn, urls=['file://%s' % tmpdir_subdir]) # file specifications via URL also work, are downloaded to (first) sourcepath init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (tmpdir, sandbox_sources)]) urls = ["http://hpcugent.github.io/easybuild/index.html", "https://hpcugent.github.io/easybuild/index.html"] for file_url in urls: fn = os.path.basename(file_url) res = None try: res = eb.obtain_file(file_url) except EasyBuildError, err: # if this fails, it should be because there's no online access download_fail_regex = re.compile('socket error') self.assertTrue(download_fail_regex.search(str(err))) # result may be None during offline testing if res is not None: loc = os.path.join(tmpdir, 't', 'toy', fn) self.assertEqual(res, loc) self.assertTrue(os.path.exists(loc), "%s file is found at %s" % (fn, loc)) txt = open(loc, 'r').read() eb_regex = re.compile("EasyBuild: building software with ease") self.assertTrue(eb_regex.search(txt)) else: print "ignoring failure to download %s in test_obtain_file, testing offline?" % file_url
def test_obtain_file(self): """Test obtain_file method.""" toy_tarball = 'toy-0.0.tar.gz' testdir = os.path.abspath(os.path.dirname(__file__)) sandbox_sources = os.path.join(testdir, 'sandbox', 'sources') toy_tarball_path = os.path.join(sandbox_sources, 'toy', toy_tarball) tmpdir = tempfile.mkdtemp() tmpdir_subdir = os.path.join(tmpdir, 'testing') mkdir(tmpdir_subdir, parents=True) del os.environ['EASYBUILD_SOURCEPATH'] # defined by setUp ec = process_easyconfig(os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb'))[0] eb = EasyBlock(ec['ec']) # 'downloading' a file to (first) sourcepath works init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (tmpdir, testdir)]) shutil.copy2(toy_tarball_path, tmpdir_subdir) res = eb.obtain_file(toy_tarball, urls=['file://%s' % tmpdir_subdir]) self.assertEqual(res, os.path.join(tmpdir, 't', 'toy', toy_tarball)) # finding a file in sourcepath works init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (sandbox_sources, tmpdir)]) res = eb.obtain_file(toy_tarball) self.assertEqual(res, toy_tarball_path) # sourcepath has preference over downloading res = eb.obtain_file(toy_tarball, urls=['file://%s' % tmpdir_subdir]) self.assertEqual(res, toy_tarball_path) # obtain_file yields error for non-existing files fn = 'thisisclearlyanonexistingfile' error_regex = "Couldn't find file %s anywhere, and downloading it didn't work either" % fn self.assertErrorRegex(EasyBuildError, error_regex, eb.obtain_file, fn, urls=['file://%s' % tmpdir_subdir]) # file specifications via URL also work, are downloaded to (first) sourcepath init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (tmpdir, sandbox_sources)]) file_url = "http://hpcugent.github.io/easybuild/index.html" fn = os.path.basename(file_url) res = None try: res = eb.obtain_file(file_url) except EasyBuildError, err: # if this fails, it should be because there's no online access download_fail_regex = re.compile('socket error') self.assertTrue(download_fail_regex.search(str(err)))
def test_obtain_file(self): """Test obtain_file method.""" toy_tarball = 'toy-0.0.tar.gz' testdir = os.path.abspath(os.path.dirname(__file__)) sandbox_sources = os.path.join(testdir, 'sandbox', 'sources') toy_tarball_path = os.path.join(sandbox_sources, 'toy', toy_tarball) tmpdir = tempfile.mkdtemp() tmpdir_subdir = os.path.join(tmpdir, 'testing') mkdir(tmpdir_subdir, parents=True) del os.environ['EASYBUILD_SOURCEPATH'] # defined by setUp ec = process_easyconfig( os.path.join(testdir, 'easyconfigs', 'toy-0.0.eb'))[0] eb = EasyBlock(ec['ec']) # 'downloading' a file to (first) sourcepath works init_config( args=["--sourcepath=%s:/no/such/dir:%s" % (tmpdir, testdir)]) shutil.copy2(toy_tarball_path, tmpdir_subdir) res = eb.obtain_file(toy_tarball, urls=[os.path.join('file://', tmpdir_subdir)]) self.assertEqual(res, os.path.join(tmpdir, 't', 'toy', toy_tarball)) # finding a file in sourcepath works init_config(args=[ "--sourcepath=%s:/no/such/dir:%s" % (sandbox_sources, tmpdir) ]) res = eb.obtain_file(toy_tarball) self.assertEqual(res, toy_tarball_path) # sourcepath has preference over downloading res = eb.obtain_file(toy_tarball, urls=[os.path.join('file://', tmpdir_subdir)]) self.assertEqual(res, toy_tarball_path) # obtain_file yields error for non-existing files fn = 'thisisclearlyanonexistingfile' try: eb.obtain_file(fn, urls=[os.path.join('file://', tmpdir_subdir)]) except EasyBuildError, err: fail_regex = re.compile( "Couldn't find file %s anywhere, and downloading it didn't work either" % fn) self.assertTrue(fail_regex.search(str(err)))
def test_obtain_file(self): """Test obtain_file method.""" toy_tarball = 'toy-0.0.tar.gz' testdir = os.path.abspath(os.path.dirname(__file__)) sandbox_sources = os.path.join(testdir, 'sandbox', 'sources') toy_tarball_path = os.path.join(sandbox_sources, 'toy', toy_tarball) tmpdir = tempfile.mkdtemp() tmpdir_subdir = os.path.join(tmpdir, 'testing') mkdir(tmpdir_subdir, parents=True) del os.environ['EASYBUILD_SOURCEPATH'] # defined by setUp ec = process_easyconfig(os.path.join(testdir, 'easyconfigs', 'toy-0.0.eb'))[0] eb = EasyBlock(ec['ec']) # 'downloading' a file to (first) sourcepath works init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (tmpdir, testdir)]) shutil.copy2(toy_tarball_path, tmpdir_subdir) res = eb.obtain_file(toy_tarball, urls=[os.path.join('file://', tmpdir_subdir)]) self.assertEqual(res, os.path.join(tmpdir, 't', 'toy', toy_tarball)) # finding a file in sourcepath works init_config(args=["--sourcepath=%s:/no/such/dir:%s" % (sandbox_sources, tmpdir)]) res = eb.obtain_file(toy_tarball) self.assertEqual(res, toy_tarball_path) # sourcepath has preference over downloading res = eb.obtain_file(toy_tarball, urls=[os.path.join('file://', tmpdir_subdir)]) self.assertEqual(res, toy_tarball_path) # obtain_file yields error for non-existing files fn = 'thisisclearlyanonexistingfile' try: eb.obtain_file(fn, urls=[os.path.join('file://', tmpdir_subdir)]) except EasyBuildError, err: fail_regex = re.compile("Couldn't find file %s anywhere, and downloading it didn't work either" % fn) self.assertTrue(fail_regex.search(str(err)))