def test_extract_archive_tar(self): """ Test extract format: tar""" for item in self.files: out_file = '%s.tar' % item self.assertTrue(archive.make_archive(out_file, item)) self.assertTrue(os.path.exists(out_file)) out_dir = 'un_tar_dir' archive.extract_archive(out_file, out_dir) self.assertTrue( os.path.exists(os.path.join(out_dir, os.path.basename(item)))) shutil.rmtree(out_dir) for item in self.dirs: out_file = '%s.tar' % item self.assertTrue(archive.make_archive(out_file, item)) self.assertTrue(os.path.exists(out_file)) out_dir = 'un_tar_dir' archive.extract_archive(out_file, out_dir) self.assertTrue(os.path.exists(os.path.join(out_dir, '1.txt'))) self.assertTrue(os.path.exists(os.path.join(out_dir, '2.txt'))) self.assertTrue(os.path.exists(os.path.join(out_dir, 'dir1'))) self.assertTrue(os.path.exists(os.path.join(out_dir, 'dir2'))) shutil.rmtree(out_dir)
def test_extract_archive_tar(self): """ Test extract format: tar""" for item in self.files: out_file = '%s.tar' % item self.assertTrue(archive.make_archive(out_file, item)) self.assertTrue(os.path.exists(out_file)) out_dir = 'un_tar_dir' archive.extract_archive(out_file, out_dir) self.assertTrue(os.path.exists(os.path.join( out_dir, os.path.basename(item)))) shutil.rmtree(out_dir) for item in self.dirs: out_file = '%s.tar' % item self.assertTrue(archive.make_archive(out_file, item)) self.assertTrue(os.path.exists(out_file)) out_dir = 'un_tar_dir' archive.extract_archive(out_file, out_dir) self.assertTrue(os.path.exists(os.path.join(out_dir, '1.txt'))) self.assertTrue(os.path.exists(os.path.join(out_dir, '2.txt'))) self.assertTrue(os.path.exists(os.path.join(out_dir, 'dir1'))) self.assertTrue(os.path.exists(os.path.join(out_dir, 'dir2'))) shutil.rmtree(out_dir)
def test_extract_archive_negtive_target_is_file(self): """Test if the extract target is file""" out_file = '%s.tar' % self.relative_dir self.assertTrue(archive.make_archive(out_file, self.relative_dir)) self.assertTrue(os.path.exists(out_file)) with self.assertRaises(Exception): archive.extract_archive(out_file, self.relative_file) os.remove(out_file)
def _extract_archive_tar_bz2(self): """ Test extract format: tar.bz2""" for item in self.files + self.dirs: out_file = '%s.tar.bz2' % item self.assertTrue(archive.make_archive(out_file, item)) self.assertTrue(os.path.exists(out_file)) out_dir = 'un_tar_dir' archive.extract_archive(out_file, out_dir) self.assertTrue(os.path.exists(os.path.join(out_dir, item))) shutil.rmtree(out_dir)
def test_extract_archive_negtive_path_not_exists(self): """Test if file path does not exist""" fake_file = 'abcdfsdf' with self.assertRaises(Exception): archive.extract_archive(fake_file, self.relative_dir)
def test_extract_archive_negtive_parameters_are_empty(self): """Test if both parameters are empty""" with self.assertRaises(Exception): archive.extract_archive('', '')
def test_extract_archive_negtive_archive_name_is_required(self): """Test if first parameter: file path is empty""" with self.assertRaises(Exception): archive.extract_archive('', self.relative_dir)