def test_gz_unpack(self): """unpack gz file""" with self.assertRaises(UnpackError): Unpack.dispatch(".gz", file_path=os.path.join(self.path, "gz_error.txt"), save_file=os.path.join(self.path, "bz2_unpack.sqlite"))
def test_error_tar(self): """error tar file""" with self.assertRaises(IOError): Unpack.dispatch(".tar", file_path=os.path.join(self.path, "tar_error.txt"), save_file=os.path.join(self.path, "bz2_unpack.sqlite"))
def test_many_zip_file(self): """Multiple compressed files""" with self.assertRaises(IOError): Unpack.dispatch(".zip", file_path=os.path.join(self.path, "many-error.zip"), save_file=os.path.join(self.path, "zip_file.sqlite"))
def test_file_path_none(self): """unpack xz file""" with self.assertRaises(ValueError): Unpack.dispatch(".xz", file_path=None, save_file=os.path.join(self.path, "xz.sqlite")) with self.assertRaises(ValueError): Unpack.dispatch(".xz", file_path=None, save_file=None)
def test_mkdir_error(self, mock_makedirs, mock_exists): """Folder creation error""" mock_exists.return_value = False mock_makedirs.side_effect = IOError("") with self.assertRaises(IOError): Unpack.dispatch(".zip", file_path=os.path.join(self.path, "zip_file.zip"), save_file=os.path.join(self.path, "zip_file.sqlite"))
def test_error_zip_unpack(self): """unpack error zip file""" file = os.path.join(self.path, "zip_error.txt") with open(file, "w", encoding="utf-8") as f: f.write("error zip file") with self.assertRaises(IOError): Unpack.dispatch(".zip", file_path=file, save_file=os.path.join(self.path, "zip_file.sqlite")) if os.path.exists(file): os.remove(file)
def test_many_tar_file(self): """many tar file""" with self.assertRaises(IOError): Unpack.dispatch(".tar", file_path=os.path.join(self.path, "many-tar.tar.gz"), save_file=os.path.join(self.path, "zip_file.sqlite")) with self.assertRaises(IOError): Unpack.dispatch(".tar", file_path=os.path.join(self.path, "many-tar.tar.gz"), save_file=os.path.join(self.path, "zip_file.sqlite"))
def test_zip_unpack(self): """unpack zip file""" self.assertEqual( None, Unpack.dispatch(".zip", file_path=os.path.join(self.path, "zip_file.zip"), save_file=os.path.join(self.path, "zip_file.sqlite")))
def test_dispatch_not_params(self): """not params""" with self.assertRaises(TypeError): Unpack.dispatch(".xz")
def test_tar_unpack(self): """unpack tar file""" Unpack.dispatch(".tar", file_path=os.path.join(self.path, "test_tar.tar.gz"), save_file=os.path.join(self.path, "bz2_unpack.sqlite"))
def test_unpack_file_is_none(self): """file path is empty""" with self.assertRaises(ValueError): Unpack.dispatch(".xz", file_path=None, save_file=None)
def test_not_support(self): """Unsupported compression format""" with self.assertRaises(UnpackError): Unpack.dispatch(".rar", file_path=None, save_file=None)