Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def test_make_archive_negtive_target_path_not_exists(self):
        """Test if file path does not exist"""
        fake_file = 'abcdfsdf'
        with self.assertRaises(Exception):
            archive.make_archive('a.tar', fake_file)

        with self.assertRaises(Exception):
            archive.make_archive('a.zip', fake_file)
Ejemplo n.º 4
0
 def test_make_archive_tar_bz2(self):
     """ Test make_archive 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))
         os.remove(out_file)
Ejemplo n.º 5
0
 def test_make_archive_zip(self):
     """ Test make_archive format: zip"""
     for item in self.files + self.dirs:
         out_file = '%s.zip' % item
         self.assertTrue(archive.make_archive(out_file, item))
         self.assertTrue(os.path.exists(out_file))
         os.remove(out_file)
Ejemplo n.º 6
0
 def test_make_archive_tar_bz2(self):
     """ Test make_archive 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))
         os.remove(out_file)
Ejemplo n.º 7
0
 def test_make_archive_zip(self):
     """ Test make_archive format: zip"""
     for item in self.files + self.dirs:
         out_file = '%s.zip' % item
         self.assertTrue(archive.make_archive(out_file, item))
         self.assertTrue(os.path.exists(out_file))
         os.remove(out_file)
Ejemplo n.º 8
0
 def test_make_archive_tgz_with_different_name(self):
     """ Test make_archive format: tgz
         It packs the source with anotehr name"""
     for item in self.files + self.dirs:
         out_file = 'abc.tgz'
         self.assertTrue(archive.make_archive(out_file, item))
         self.assertTrue(os.path.exists(out_file))
         os.remove(out_file)
Ejemplo n.º 9
0
 def test_make_archive_tgz_with_different_name(self):
     """ Test make_archive format: tgz
         It packs the source with anotehr name"""
     for item in self.files + self.dirs:
         out_file = 'abc.tgz'
         self.assertTrue(archive.make_archive(out_file, item))
         self.assertTrue(os.path.exists(out_file))
         os.remove(out_file)
Ejemplo n.º 10
0
 def test_make_archive_tar_bz2_with_different_name(self):
     """ Test make_archive format: tar.bz2
         it packs the source with another name """
     for item in self.files + self.dirs:
         out_file = 'df.tar.bz2'
         self.assertTrue(archive.make_archive(out_file, item))
         self.assertTrue(os.path.exists(out_file))
         os.remove(out_file)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 def test_make_archive_tar_bz2_with_different_name(self):
     """ Test make_archive format: tar.bz2
         it packs the source with another name """
     for item in self.files + self.dirs:
         out_file = 'df.tar.bz2'
         self.assertTrue(archive.make_archive(out_file, item))
         self.assertTrue(os.path.exists(out_file))
         os.remove(out_file)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
 def test_make_archive_negtive_archive_name_is_required(self):
     """Test if first parameter: file path is empty"""
     with self.assertRaises(Exception):
         archive.make_archive('', self.relative_dir)
Ejemplo n.º 16
0
 def test_make_archive_wrong_format(self):
     """Test wrong make_archive format"""
     with self.assertRaises(Exception):
         archive.make_archive('a.sfsfrwe', self.relative_dir)
Ejemplo n.º 17
0
 def test_make_archive_negtive_parameters_are_empty(self):
     """Test if both parameters are empty"""
     with self.assertRaises(Exception):
         archive.make_archive('', '')
Ejemplo n.º 18
0
 def test_make_archive_negtive_target_name_is_required(self):
     """Test if second parameter: target name is empty"""
     with self.assertRaises(Exception):
         archive.make_archive('a.zip', '')