def test_unzip_with_matching_subdirectory_names(self, remove_top_level_directory, unlink_zip): with tempfile.TemporaryDirectory() as tmp_dir: path = Path(tmp_dir) top_level_dir = path / TOP_LEVEL_DIR_NAME top_level_dir.mkdir(parents=True) next_level_dir = top_level_dir for _ in range(10): dir1 = next_level_dir / TOP_LEVEL_DIR_NAME dir1.mkdir(parents=True) next_level_dir = dir1 make_archive(path / ARCHIVE_NAME[:ARCHIVE_NAME.rfind(".")], "zip", path, TOP_LEVEL_DIR_NAME) archive_path = str(path / ARCHIVE_NAME) tmp_path = archive_path[:archive_path.rfind("/")] tmp_subdir = f"{tmp_path}/{TOP_LEVEL_DIR_NAME}_tmp" unzip_package( package_path=archive_path, target_dir=tmp_subdir, remove_top_level_directory=remove_top_level_directory, unlink_zip=unlink_zip) self.dcmp_helper(remove_top_level_directory, unlink_zip, tmp_subdir, tmp_path, archive_path)
def test_unzip_package(self, random_zip_file_with_top_level_dir, remove_top_level_directory, unlink_zip): archive_path = random_zip_file_with_top_level_dir tmp_path = archive_path[:archive_path.rfind("/")] tmp_subdir = f"{tmp_path}/{TOP_LEVEL_DIR_NAME}_tmp" unzip_package(package_path=archive_path, target_dir=tmp_subdir, remove_top_level_directory=remove_top_level_directory, unlink_zip=unlink_zip) self.dcmp_helper(remove_top_level_directory, unlink_zip, tmp_subdir, tmp_path, archive_path)
def test_unzip_package(self, random_zip_file_with_top_level_dir, remove_top_level_directory, unlink_zip): archive_path = random_zip_file_with_top_level_dir tmp_path = archive_path[:archive_path.rfind(os.path.sep)] tmp_subdir = os.path.join(tmp_path, TOP_LEVEL_DIR_NAME + "_tmp") unzip_package( package_path=archive_path, target_dir=tmp_subdir, remove_top_level_directory=remove_top_level_directory, unlink_zip=unlink_zip, ) self.dcmp_helper(remove_top_level_directory, unlink_zip, tmp_subdir, tmp_path, archive_path)
def test_unzip_with_matching_subdirectory_names( self, remove_top_level_directory, unlink_zip, tmp_path, ): path = tmp_path top_level_dir = path / TOP_LEVEL_DIR_NAME top_level_dir.mkdir(parents=True) next_level_dir = top_level_dir for _ in range(10): dir1 = next_level_dir / TOP_LEVEL_DIR_NAME dir1.mkdir(parents=True) next_level_dir = dir1 make_archive( path / ARCHIVE_NAME[:ARCHIVE_NAME.rfind(".")], "zip", path, TOP_LEVEL_DIR_NAME, ) archive_path = str(path / ARCHIVE_NAME) tmp_path = archive_path[:archive_path.rfind(os.path.sep)] tmp_subdir = os.path.join(tmp_path, TOP_LEVEL_DIR_NAME + "_tmp") unzip_package( package_path=archive_path, target_dir=tmp_subdir, remove_top_level_directory=remove_top_level_directory, unlink_zip=unlink_zip, ) self.dcmp_helper( remove_top_level_directory, unlink_zip, tmp_subdir, tmp_path, archive_path, )
def test_unzip_package(random_zip_file_with_top_level_dir, remove_top_level_directory, unlink_zip): archive_path = random_zip_file_with_top_level_dir tmp_path = archive_path[:archive_path.rfind("/")] tmp_subdir = f"{tmp_path}/{TOP_LEVEL_DIR_NAME}_tmp" unzip_package( package_path=archive_path, target_dir=tmp_subdir, remove_top_level_directory=remove_top_level_directory, unlink_zip=unlink_zip) dcmp = None if remove_top_level_directory: dcmp = dircmp(f"{tmp_subdir}", f"{tmp_path}/{TOP_LEVEL_DIR_NAME}") else: dcmp = dircmp(f"{tmp_subdir}/{TOP_LEVEL_DIR_NAME}", f"{tmp_path}/{TOP_LEVEL_DIR_NAME}") assert len(dcmp.left_only) == 0 assert len(dcmp.right_only) == 0 if unlink_zip: assert not Path(archive_path).is_file() else: assert Path(archive_path).is_file()