def test_extract_with_filename_as_filter(self, local_archives): apath, files_hashes = local_archives out_files = extract(apath, files_hashes.keys()) for o_f in out_files: assert os.path.basename(o_f) in files_hashes.keys() assert get_hash_memory_optimized(o_f) == files_hashes[ os.path.basename(o_f)]
def test_extract_with_ext_as_filter(self, local_archives): apath, files_hashes = local_archives f_exts = [file_ext(f) for f in files_hashes.keys()] out_files = extract(apath, f_exts) for o_f in out_files: assert os.path.exists(apath) assert os.path.basename(o_f) in files_hashes.keys() assert get_hash_memory_optimized(o_f) == files_hashes[os.path.basename(o_f)]
def download(url, fpath): """Download file using streaming""" with open(fpath, 'wb') as f: try: with requests.get(url, stream=True) as r: r.raise_for_status() f_size = 0 for chunk in r.iter_content(chunk_size=8192): if chunk: f.write(chunk) f_size += len(chunk) f_hash = get_hash_memory_optimized(fpath) return f_size, f_hash except Exception as e: os.remove(fpath) raise AdvarchsDownloadException('Could not download file.' + e.message)