def test(): with temp_file_tools.create_temp_folder() as temp_folder: assert isinstance(temp_folder, pathlib.Path) folder_to_zip = (temp_folder / 'folder_to_zip') folder_to_zip.mkdir() assert isinstance(folder_to_zip, pathlib.Path) (folder_to_zip / 'some_file.txt').open('w').write(u'hello there!') (folder_to_zip / 'some_other_file.txt').open('w').write(u'hello there again!') import gc gc.collect() # Making PyPy happy. zip_file_path = temp_folder / 'archive.zip' assert isinstance(zip_file_path, pathlib.Path) zip_tools.zip_folder(folder_to_zip, temp_folder / 'archive.zip') result = set(zip_tools.unzip_in_memory( zip_file_path.open('rb').read())) assert zip_file_path.is_file() # Got two options here because of PyPy shenanigans: assert result == { ('folder_to_zip/some_file.txt', b'hello there!'), ('folder_to_zip/some_other_file.txt', b'hello there again!'), } or result == { ('folder_to_zip/some_file.txt', 'hello there!'), ('folder_to_zip/some_other_file.txt', 'hello there again!'), } import gc gc.collect() # Making PyPy happy.
def test(): with temp_file_tools.create_temp_folder() as temp_folder: assert isinstance(temp_folder, pathlib.Path) folder_to_zip = (temp_folder / 'folder_to_zip') folder_to_zip.mkdir() assert isinstance(folder_to_zip, pathlib.Path) (folder_to_zip / 'some_file.txt').open('w').write(u'hello there!') (folder_to_zip / 'some_other_file.txt').open('w').write( u'hello there again!') import gc; gc.collect() # Making PyPy happy. zip_file_path = temp_folder / 'archive.zip' assert isinstance(zip_file_path, pathlib.Path) zip_tools.zip_folder(folder_to_zip, temp_folder / 'archive.zip') result = set( zip_tools.unzip_in_memory(zip_file_path.open('rb').read()) ) assert zip_file_path.is_file() # Got two options here because of PyPy shenanigans: assert result == { ('folder_to_zip/some_file.txt', b'hello there!'), ('folder_to_zip/some_other_file.txt', b'hello there again!'), } or result == { ('folder_to_zip/some_file.txt', 'hello there!'), ('folder_to_zip/some_other_file.txt', 'hello there again!'), } import gc; gc.collect() # Making PyPy happy.
def test_zipping_in_memory(): ''' ''' files = (('meow.txt', b"I'm a cat."), ('dog.txt', b"I'm a dog."), ('folder/binary.bin', bytes(bytearray(range(256))))) zip_archive = zip_tools.zip_in_memory(files) assert isinstance(zip_archive, bytes) assert set(zip_tools.unzip_in_memory(zip_archive)) == set(files)
def test_zipping_in_memory(): ''' ''' files = (('meow.txt', "I'm a cat."), ('dog.txt', "I'm a dog."), ('folder/binary.bin', ''.join(map(chr, xrange(256))))) zip_archive = zip_tools.zip_in_memory(files) assert isinstance(zip_archive, str) assert set(zip_tools.unzip_in_memory(zip_archive)) == set(files)
def test_zipping_in_memory(): ''' ''' files = ( ('meow.txt', "I'm a cat."), ('dog.txt', "I'm a dog."), ('folder/binary.bin', ''.join(map(chr, xrange(256)))) ) zip_archive = zip_tools.zip_in_memory(files) assert isinstance(zip_archive, str) assert set(zip_tools.unzip_in_memory(zip_archive)) == set(files)
def test(): with temp_file_tools.create_temp_folder() as temp_folder: assert isinstance(temp_folder, pathlib.Path) folder_to_zip = (temp_folder / 'folder_to_zip') folder_to_zip.mkdir() assert isinstance(folder_to_zip, pathlib.Path) (folder_to_zip / 'some_file.txt').open('w').write('hello there!') (folder_to_zip / 'some_other_file.txt').open('w').write('hello there again!') zip_file_path = temp_folder / 'archive.zip' assert isinstance(zip_file_path, pathlib.Path) zip_tools.zip_folder(folder_to_zip, temp_folder / 'archive.zip') assert zip_file_path.is_file() assert set(zip_tools.unzip_in_memory( zip_file_path.open('rb').read())) == { ('folder_to_zip/some_file.txt', b'hello there!'), ('folder_to_zip/some_other_file.txt', b'hello there again!'), }
def test(): with temp_file_tools.create_temp_folder() as temp_folder: assert isinstance(temp_folder, pathlib.Path) folder_to_zip = temp_folder / "folder_to_zip" folder_to_zip.mkdir() assert isinstance(folder_to_zip, pathlib.Path) (folder_to_zip / "some_file.txt").open("w").write(u"hello there!") (folder_to_zip / "some_other_file.txt").open("w").write(u"hello there again!") import gc gc.collect() # Making PyPy happy. zip_file_path = temp_folder / "archive.zip" assert isinstance(zip_file_path, pathlib.Path) zip_tools.zip_folder(folder_to_zip, temp_folder / "archive.zip") result = set(zip_tools.unzip_in_memory(zip_file_path.open("rb").read())) assert zip_file_path.is_file() # Got two options here because of PyPy shenanigans: assert result == set( ( ("folder_to_zip/some_file.txt", b"hello there!"), ("folder_to_zip/some_other_file.txt", b"hello there again!"), ) ) or result == set( ( ("folder_to_zip/some_file.txt", "hello there!"), ("folder_to_zip/some_other_file.txt", "hello there again!"), ) ) import gc gc.collect() # Making PyPy happy.
def test(): with temp_file_tools.create_temp_folder() as temp_folder: assert isinstance(temp_folder, pathlib.Path) folder_to_zip = (temp_folder / 'folder_to_zip') folder_to_zip.mkdir() assert isinstance(folder_to_zip, pathlib.Path) (folder_to_zip / 'some_file.txt').open('w').write('hello there!') (folder_to_zip / 'some_other_file.txt').open('w').write( 'hello there again!') zip_file_path = temp_folder / 'archive.zip' assert isinstance(zip_file_path, pathlib.Path) zip_tools.zip_folder(folder_to_zip, temp_folder / 'archive.zip') assert zip_file_path.is_file() assert set( zip_tools.unzip_in_memory(zip_file_path.open('rb').read()) ) == { ('folder_to_zip/some_file.txt', b'hello there!'), ('folder_to_zip/some_other_file.txt', b'hello there again!'), }