def extracted_archive(self, archive, workdir): a = Archive(archive) d = os.path.join(workdir, 'dir') a.extract_archive(d) if archive == self.GEM: # append top level dir d = os.path.join(d, 'archive') return d
def extraction_test(self, archive): """ Generic test for extraction of all types of archives """ EXTRACT_DIR = os.path.join(os.getcwd(), 'dir') EXTRACTED_FILE = os.path.join(EXTRACT_DIR, self.ARCHIVED_FILE) archive = Archive(archive) archive.extract_archive(EXTRACT_DIR) # check if the dir was created assert os.path.isdir(EXTRACT_DIR) # check if the file was extracted assert os.path.isfile(EXTRACTED_FILE) # check the content with open(EXTRACTED_FILE) as f: assert f.read().strip() == self.ARCHIVED_FILE_CONTENT
def extract_archive(archive_path, destination): """ Extracts given archive into the destination and handle all exceptions. :param archive_path: path to the archive to be extracted :param destination: path to a destination, where the archive should be extracted to :return: """ archive = Archive(archive_path) try: archive.extract_archive(destination) except IOError as e: raise RebaseHelperError("Archive '{}' can not be extracted".format( archive_path)) from e except (EOFError, SystemError) as e: raise RebaseHelperError( "Archive '{}' is damaged".format(archive_path)) from e
def extract_archive(archive_path, destination): """ Extracts given archive into the destination and handle all exceptions. :param archive_path: path to the archive to be extracted :param destination: path to a destination, where the archive should be extracted to :return: """ try: archive = Archive(archive_path) except NotImplementedError as ni_e: raise RebaseHelperError('%s. Supported archives are %s', ni_e.message, Archive.get_supported_archives()) try: archive.extract_archive(destination) except IOError: raise RebaseHelperError("Archive '%s' can not be extracted", archive_path) except (EOFError, SystemError): raise RebaseHelperError("Archive '%s' is damaged", archive_path)
def extract_archive(archive_path, destination): """ Extracts given archive into the destination and handle all exceptions. :param archive_path: path to the archive to be extracted :param destination: path to a destination, where the archive should be extracted to :return: """ try: archive = Archive(archive_path) except NotImplementedError as ni_e: raise RebaseHelperError('%s. Supported archives are %s' % (six.text_type(ni_e), Archive.get_supported_archives())) try: archive.extract_archive(destination) except IOError: raise RebaseHelperError("Archive '%s' can not be extracted" % archive_path) except (EOFError, SystemError): raise RebaseHelperError("Archive '%s' is damaged" % archive_path)
def extracted_archive(self, archive, workdir): a = Archive(archive) d = os.path.join(workdir, 'dir') a.extract_archive(d) return d
def test_invalid_archive(self, archive, workdir): a = Archive(archive) d = os.path.join(workdir, 'dir') with pytest.raises(IOError): a.extract_archive(d)
def _extract_sources(self, archive, dir_name): archive = Archive(archive) archive.extract_archive(dir_name)
def test_invalid_archive(self, archive, workdir): a = Archive(archive) d = os.path.join(workdir, 'dir') with pytest.raises(IOError): a.extract_archive(d)
def extracted_archive(self, archive, workdir): a = Archive(archive) d = os.path.join(workdir, 'dir') a.extract_archive(d) return d