本文整理汇总了Python中mic.archive.make_archive函数的典型用法代码示例。如果您正苦于以下问题:Python make_archive函数的具体用法?Python make_archive怎么用?Python make_archive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_archive函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extract_archive_tar
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)
示例2: test_make_archive_negtive_target_path_not_exists
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)
示例3: test_make_archive_tar_bz2
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)
示例4: test_make_archive_zip
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)
示例5: test_make_archive_tar_bz2_with_different_name
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)
示例6: test_make_archive_tgz_with_different_name
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)
示例7: test_extract_archive_negtive_target_is_file
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)
示例8: _extract_archive_tar_bz2
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)
示例9: test_make_archive_wrong_format
def test_make_archive_wrong_format(self):
"""Test wrong make_archive format"""
with self.assertRaises(Exception):
archive.make_archive('a.sfsfrwe', self.relative_dir)
示例10: test_make_archive_negtive_parameters_are_empty
def test_make_archive_negtive_parameters_are_empty(self):
"""Test if both parameters are empty"""
with self.assertRaises(Exception):
archive.make_archive('', '')
示例11: test_make_archive_negtive_target_name_is_required
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', '')
示例12: test_make_archive_negtive_archive_name_is_required
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)