2 It is used to test mic/archive.py
10 from mic import archive
13 class ArchiveTest(unittest.TestCase):
15 test pulic methods in archive.py
18 """Create files and directories for later use"""
19 self.relative_file = './sdfb.gxdf.bzws.zzz'
20 abs_file = '/tmp/adsdfb.gxdf.bzws.zzz'
21 bare_file = 'abc.def.bz.zzz'
22 self.relative_dir = './sdf.zzz'
23 abs_dir = '/tmp/asdf.zzz'
25 self.wrong_format_file = './sdbs.werxdf.bz.zzz'
27 self.files = [self.relative_file, abs_file, bare_file]
28 self.dirs = [self.relative_dir, abs_dir, bare_dir]
29 for file_item in self.files:
30 os.system('touch %s' % file_item)
32 for dir_item in self.dirs:
33 self.create_dir(dir_item)
34 shutil.copy(self.relative_file, '%s/1.txt' % dir_item)
35 shutil.copy(self.relative_file, '%s/2.txt' % dir_item)
36 self.create_dir('%s/dir1' % dir_item)
37 self.create_dir('%s/dir2' % dir_item)
40 """Clean up unuseful file and directory """
42 for file_item in self.files:
44 for dir_item in self.dirs:
45 shutil.rmtree(dir_item, ignore_errors=True)
49 def create_dir(self, dir_name):
50 """Create directories and ignore any erros """
56 def test_get_compress_formats(self):
57 """Test get compress format """
58 compress_list = archive.get_compress_formats()
60 self.assertEqual(compress_list, ['bz2', 'gz', 'lzo'])
62 def test_compress_negtive_file_path_is_required(self):
63 """Test if the first parameter: file path is empty"""
64 self.assertRaises(OSError, archive.compress, '', 'bz2')
65 #with self.assertRaises(OSError):
66 # archive.compress('', 'bz2')
68 def test_compress_negtive_compress_format_is_required(self):
69 """Test if the second parameter: compress format is empty"""
70 self.assertRaises(ValueError, archive.compress,
71 self.relative_file, '')
72 #with self.assertRaises(ValueError):
73 # archive.compress(self.relative_file, '')
75 def test_compress_negtive_parameters_are_all_required(self):
76 """Test if two parameters are both empty"""
77 self.assertRaises(OSError, archive.compress, '', '')
78 #with self.assertRaises(OSError):
79 # archive.compress('', '')
81 def test_compress_negtive_file_not_exist(self):
82 """Test target file does not exist"""
83 self.assertRaises(OSError, archive.compress, 'a.py', 'bz2')
84 #with self.assertRaises(OSError):
85 # archive.compress('a.py', 'bz2')
87 def test_compress_negtive_file_is_dir(self):
88 """Test target is one direcoty, which is not supported"""
89 self.assertRaises(OSError, archive.compress,
90 self.relative_dir, 'bz2')
91 # with self.assertRaises(OSError):
92 # archive.compress(self.relative_dir, 'bz2')
94 def test_compress_negtive_wrong_compress_format(self):
95 """Test wrong compress format"""
96 self.assertRaises(ValueError, archive.compress,
97 self.relative_file, 'bzip2')
98 #with self.assertRaises(ValueError):
99 # archive.compress(self.relative_file, 'bzip2')
101 def _compress_negtive_gz_command_not_exists(self):
102 #TODO: test if command like 'pigz', 'gzip' does not exist
105 def _compress_negtive_lzo_command_not_exists(self):
106 #TODO: test if command 'lzop' does not exist
109 def _compress_negtive_bz2_command_not_exists(self):
110 #TODO: test if command like 'pbzip2', 'bzip2' does not exist
113 def test_compress_gz(self):
114 """Test compress format: gz"""
115 for file_item in self.files:
116 output_name = archive.compress(file_item, 'gz')
117 self.assertEqual('%s.gz' % file_item, output_name)
118 self.assertTrue(os.path.exists(output_name))
119 os.remove(output_name)
121 def test_compress_bz2(self):
122 """Test compress format: bz2"""
123 for file_item in self.files:
124 output_name = archive.compress(file_item, 'bz2')
125 self.assertEqual('%s.bz2' % file_item, output_name)
126 self.assertTrue(os.path.exists(output_name))
127 os.remove(output_name)
129 def _test_compress_lzo(self):
130 """Test compress format: lzo"""
131 for file_item in self.files:
132 output_name = archive.compress(file_item, 'lzo')
133 self.assertEqual('%s.lzo' % file_item, output_name)
134 self.assertTrue(os.path.exists(output_name))
135 os.remove(output_name)
137 def test_decompress_negtive_file_path_is_required(self):
138 """Test if the first parameter: file to be uncompressed is empty"""
139 self.assertRaises(OSError, archive.compress, '', 'bz')
140 #with self.assertRaises(OSError):
141 # archive.decompress('', 'bz')
143 def test_decompress_compress_format_is_empty(self):
144 """Test if the second parameter: compress format is empty string"""
145 output_name = archive.compress(self.relative_file, 'gz')
146 self.assertEqual('%s.gz' % self.relative_file, output_name)
147 self.assertTrue(os.path.exists(output_name))
148 self.assertFalse(os.path.exists(self.relative_file))
149 archive.decompress(output_name, '')
150 self.assertTrue(os.path.exists(self.relative_file))
152 def test_decompress_negtive_parameters_are_empty(self):
153 """Test if two parameters are both empty string"""
154 self.assertRaises(OSError, archive.decompress, '', '')
155 #with self.assertRaises(OSError):
156 # archive.decompress('', '')
158 def test_decompress_negtive_file_not_exist(self):
159 """Test decompress target does not exist"""
160 self.assertRaises(OSError, archive.decompress,
162 #with self.assertRaises(OSError):
163 # archive.decompress('tresa.py', 'bz2')
165 def test_decompress_negtive_path_is_dir(self):
166 """Test decompress target is a directory"""
167 self.assertRaises(OSError, archive.decompress,
168 self.relative_dir, 'bz2')
169 #with self.assertRaises(OSError):
170 # archive.decompress(self.relative_dir, 'bz2')
172 def _decompress_negtive_not_corresponding(self):
173 # TODO: test if path is .lzo, but given format is bz2
176 def test_decompress_negtive_wrong_compress_format(self):
177 """Test wrong decompress format"""
178 self.assertRaises(ValueError, archive.decompress,
179 self.relative_file, 'bzip2')
180 #with self.assertRaises(ValueError):
181 # archive.decompress(self.relative_file, 'bzip2')
183 def test_decompress_negtive_wrong_file_format(self):
184 """Test wrong target format"""
185 self.assertRaises(Exception, archive.decompress,
186 self.wrong_format_file, 'bz2')
187 #with self.assertRaises(Exception):
188 # archive.decompress(self.wrong_format_file, 'bz2')
190 def test_decompress_gz(self):
193 both two parameters are given, one is target file,
194 the other is corresponding compress format"""
195 for file_item in self.files:
196 output_name = archive.compress(file_item, 'gz')
197 self.assertEqual('%s.gz' % file_item, output_name)
198 self.assertTrue(os.path.exists(output_name))
199 self.assertFalse(os.path.exists(file_item))
200 archive.decompress(output_name, 'gz')
201 self.assertTrue(os.path.exists(file_item))
203 def test_decompress_gz_no_compress_format(self):
206 one parameters is given, only target file"""
207 for file_item in self.files:
208 output_name = archive.compress(file_item, 'gz')
209 self.assertEqual('%s.gz' % file_item, output_name)
210 self.assertTrue(os.path.exists(output_name))
211 self.assertFalse(os.path.exists(file_item))
212 archive.decompress(output_name)
213 self.assertTrue(os.path.exists(file_item))
215 def test_decompress_bz2(self):
218 both two parameters are given, one is target file,
219 the other is corresponding compress format"""
220 for file_item in self.files:
221 output_name = archive.compress(file_item, 'bz2')
222 self.assertEqual('%s.bz2' % file_item, output_name)
223 self.assertTrue(os.path.exists(output_name))
224 self.assertFalse(os.path.exists(file_item))
225 archive.decompress(output_name, 'bz2')
226 self.assertTrue(os.path.exists(file_item))
228 def test_decompress_bz2_no_compress_format(self):
231 one parameters is given, only target file"""
232 for file_item in self.files:
233 output_name = archive.compress(file_item, 'bz2')
234 self.assertEqual('%s.bz2' % file_item, output_name)
235 self.assertTrue(os.path.exists(output_name))
236 self.assertFalse(os.path.exists(file_item))
237 archive.decompress(output_name)
238 self.assertTrue(os.path.exists(file_item))
240 def _test_decompress_lzo(self):
243 both two parameters are given, one is target file,
244 the other is corresponding compress format"""
245 for file_item in self.files:
246 output_name = archive.compress(file_item, 'lzo')
247 self.assertEqual('%s.lzo' % file_item, output_name)
248 self.assertTrue(os.path.exists(output_name))
249 self.assertFalse(os.path.exists(file_item))
250 archive.decompress(output_name, 'lzo')
251 self.assertTrue(os.path.exists(file_item))
253 def _test_decompress_lzo_no_compress_format(self):
256 one parameters is given, only target file"""
257 for file_item in self.files:
258 output_name = archive.compress(file_item, 'lzo')
259 self.assertEqual('%s.lzo' % file_item, output_name)
260 self.assertTrue(os.path.exists(output_name))
261 self.assertFalse(os.path.exists(file_item))
262 archive.decompress(output_name)
263 self.assertTrue(os.path.exists(file_item))
265 def test_get_archive_formats(self):
266 """Test get archive format"""
267 archive_formats = archive.get_archive_formats()
268 archive_formats.sort()
269 self.assertEqual(archive_formats,
270 ["bztar", "gztar", "lzotar", "tar", 'zip'])
272 def test_get_archive_suffixes(self):
273 """Test get archive suffixes"""
274 archive_suffixes = archive.get_archive_suffixes()
275 archive_suffixes.sort()
277 self.assertEqual(archive_suffixes,
278 ['.tar', '.tar.bz', '.tar.bz2', '.tar.gz', '.tar.lzo',
279 '.taz', '.tbz', '.tbz2', '.tgz', '.tzo', '.zip'])
281 def test_make_archive_negtive_archive_name_is_required(self):
282 """Test if first parameter: file path is empty"""
283 self.assertRaises(Exception, archive.make_archive,
284 '', self.relative_dir)
285 #with self.assertRaises(Exception):
286 # archive.make_archive('', self.relative_dir)
288 def test_extract_archive_negtive_archive_name_is_required(self):
289 """Test if first parameter: file path is empty"""
290 self.assertRaises(Exception, archive.extract_archive,
291 '', self.relative_dir)
292 #with self.assertRaises(Exception):
293 # archive.extract_archive('', self.relative_dir)
295 def test_make_archive_negtive_target_name_is_required(self):
296 """Test if second parameter: target name is empty"""
297 self.assertRaises(Exception, archive.make_archive, 'a.zip', '')
298 #with self.assertRaises(Exception):
299 # archive.make_archive('a.zip', '')
301 def _extract_archive_negtive_target_name_is_required(self):
302 # Not sure if the current dir will be used ?
306 def test_make_archive_negtive_parameters_are_empty(self):
307 """Test if both parameters are empty"""
308 self.assertRaises(Exception, archive.make_archive, '', '')
309 #with self.assertRaises(Exception):
310 # archive.make_archive('', '')
312 def test_extract_archive_negtive_parameters_are_empty(self):
313 """Test if both parameters are empty"""
314 self.assertRaises(Exception, archive.extract_archive, '', '')
315 #with self.assertRaises(Exception):
316 # archive.extract_archive('', '')
318 def test_make_archive_negtive_target_path_not_exists(self):
319 """Test if file path does not exist"""
320 fake_file = 'abcdfsdf'
321 self.assertRaises(Exception, archive.make_archive,
323 #with self.assertRaises(Exception):
324 # archive.make_archive('a.tar', fake_file)
326 self.assertRaises(Exception, archive.make_archive,
328 #with self.assertRaises(Exception):
329 # archive.make_archive('a.zip', fake_file)
331 def test_extract_archive_negtive_path_not_exists(self):
332 """Test if file path does not exist"""
333 fake_file = 'abcdfsdf'
334 self.assertRaises(Exception, archive.extract_archive,
335 fake_file, self.relative_dir)
336 #with self.assertRaises(Exception):
337 # archive.extract_archive(fake_file, self.relative_dir)
339 def test_extract_archive_negtive_target_is_file(self):
340 """Test if the extract target is file"""
341 out_file = '%s.tar' % self.relative_dir
342 self.assertTrue(archive.make_archive(out_file, self.relative_dir))
343 self.assertTrue(os.path.exists(out_file))
344 self.assertRaises(Exception, archive.extract_archive,
345 out_file, self.relative_file)
346 #with self.assertRaises(Exception):
347 # archive.extract_archive(out_file, self.relative_file)
350 def test_make_archive_wrong_format(self):
351 """Test wrong make_archive format"""
352 self.assertRaises(Exception, archive.make_archive,
353 'a.sfsfrwe', self.relative_dir)
354 #with self.assertRaises(Exception):
355 # archive.make_archive('a.sfsfrwe', self.relative_dir)
357 def test_make_archive_tar_with_different_name(self):
358 """ Test make_archive format: tar
359 It packs the source with another name"""
360 for item in self.files + self.dirs:
361 out_file = 'abcd.tar'
362 self.assertTrue(archive.make_archive(out_file, item))
363 self.assertTrue(os.path.exists(out_file))
366 def test_make_archive_tar(self):
367 """ Test make_archive format: tar"""
368 for item in self.files + self.dirs:
369 out_file = '%s.tar' % item
370 self.assertTrue(archive.make_archive(out_file, item))
371 self.assertTrue(os.path.exists(out_file))
374 def test_extract_archive_tar(self):
375 """ Test extract format: tar"""
376 for item in self.files:
377 out_file = '%s.tar' % item
378 self.assertTrue(archive.make_archive(out_file, item))
379 self.assertTrue(os.path.exists(out_file))
381 out_dir = 'un_tar_dir'
382 archive.extract_archive(out_file, out_dir)
383 self.assertTrue(os.path.exists(os.path.join(
385 os.path.basename(item))))
386 shutil.rmtree(out_dir)
388 for item in self.dirs:
389 out_file = '%s.tar' % item
390 self.assertTrue(archive.make_archive(out_file, item))
391 self.assertTrue(os.path.exists(out_file))
393 out_dir = 'un_tar_dir'
394 archive.extract_archive(out_file, out_dir)
395 self.assertTrue(os.path.exists(os.path.join(out_dir, '1.txt')))
396 self.assertTrue(os.path.exists(os.path.join(out_dir, '2.txt')))
397 self.assertTrue(os.path.exists(os.path.join(out_dir, 'dir1')))
398 self.assertTrue(os.path.exists(os.path.join(out_dir, 'dir2')))
399 shutil.rmtree(out_dir)
401 def test_make_archive_zip_with_different_name(self):
402 """ Test make_archive format: zip
403 It packs the source with another name"""
404 for item in self.files + self.dirs:
406 self.assertTrue(archive.make_archive(out_file, item))
407 self.assertTrue(os.path.exists(out_file))
410 def test_make_archive_zip(self):
411 """ Test make_archive format: zip"""
412 for item in self.files + self.dirs:
413 out_file = '%s.zip' % item
414 self.assertTrue(archive.make_archive(out_file, item))
415 self.assertTrue(os.path.exists(out_file))
418 def _extract_archive_zip(self):
419 """ Test extract archive format: zip"""
420 for item in self.files + self.dirs:
421 out_file = '%s.zip' % item
422 self.assertTrue(archive.make_archive(out_file, item))
423 self.assertTrue(os.path.exists(out_file))
425 out_dir = 'un_tar_dir'
426 archive.extract_archive(out_file, out_dir)
427 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
428 shutil.rmtree(out_dir)
430 def _test_make_archive_tzo_with_different_name(self):
431 """ Test make_archive format: tzo
432 It packs the source with another name"""
433 for item in self.files + self.dirs:
435 self.assertTrue(archive.make_archive(out_file, item))
436 self.assertTrue(os.path.exists(out_file))
439 def _test_make_archive_tzo(self):
440 """ Test make_archive format: tzo"""
441 for item in self.files + self.dirs:
442 out_file = '%s.tzo' % item
443 self.assertTrue(archive.make_archive(out_file, item))
444 self.assertTrue(os.path.exists(out_file))
447 def _extract_archive_tzo(self):
448 """ Test extract format: tzo"""
449 for item in self.files + self.dirs:
450 out_file = '%s.tzo' % item
451 self.assertTrue(archive.make_archive(out_file, item))
452 self.assertTrue(os.path.exists(out_file))
454 out_dir = 'un_tar_dir'
455 archive.extract_archive(out_file, out_dir)
456 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
457 shutil.rmtree(out_dir)
459 def _test_make_archive_tar_lzo_with_different_name(self):
460 """ Test make_archive format: lzo
461 It packs the source with another name"""
462 for item in self.files + self.dirs:
463 out_file = 'abc.tar.lzo'
464 self.assertTrue(archive.make_archive(out_file, item))
465 self.assertTrue(os.path.exists(out_file))
468 def _test_make_archive_tar_lzo(self):
469 """ Test make_archive format: lzo"""
470 for item in self.files + self.dirs:
471 out_file = '%s.tar.lzo' % item
472 self.assertTrue(archive.make_archive(out_file, item))
473 self.assertTrue(os.path.exists(out_file))
476 def _extract_archive_tar_lzo(self):
477 """ Test extract_archive format: lzo"""
478 for item in self.files + self.dirs:
479 out_file = '%s.tar.lzo' % item
480 self.assertTrue(archive.make_archive(out_file, item))
481 self.assertTrue(os.path.exists(out_file))
483 out_dir = 'un_tar_dir'
484 archive.extract_archive(out_file, out_dir)
485 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
486 shutil.rmtree(out_dir)
488 def test_make_archive_taz_with_different_name(self):
489 """ Test make_archive format: taz
490 It packs the source with another name"""
491 for item in self.files + self.dirs:
492 out_file = 'abcd.taz'
493 self.assertTrue(archive.make_archive(out_file, item))
494 self.assertTrue(os.path.exists(out_file))
497 def test_make_archive_taz(self):
498 """ Test make_archive format: taz"""
499 for item in self.files + self.dirs:
500 out_file = '%s.taz' % item
501 self.assertTrue(archive.make_archive(out_file, item))
502 self.assertTrue(os.path.exists(out_file))
505 def _extract_archive_taz(self):
506 """ Test extract archive format: taz"""
507 for item in self.files + self.dirs:
508 out_file = '%s.taz' % item
509 self.assertTrue(archive.make_archive(out_file, item))
510 self.assertTrue(os.path.exists(out_file))
512 out_dir = 'un_tar_dir'
513 archive.extract_archive(out_file, out_dir)
514 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
515 shutil.rmtree(out_dir)
517 def test_make_archive_tgz_with_different_name(self):
518 """ Test make_archive format: tgz
519 It packs the source with anotehr name"""
520 for item in self.files + self.dirs:
522 self.assertTrue(archive.make_archive(out_file, item))
523 self.assertTrue(os.path.exists(out_file))
526 def test_make_archive_tgz(self):
527 """ Test make_archive format: tgz"""
528 for item in self.files + self.dirs:
529 out_file = '%s.tgz' % item
530 self.assertTrue(archive.make_archive(out_file, item))
531 self.assertTrue(os.path.exists(out_file))
534 def _extract_archive_tgz(self):
535 """ Test extract archive format: tgz"""
536 for item in self.files + self.dirs:
537 out_file = '%s.tgz' % item
538 self.assertTrue(archive.make_archive(out_file, item))
539 self.assertTrue(os.path.exists(out_file))
541 out_dir = 'un_tar_dir'
542 archive.extract_archive(out_file, out_dir)
543 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
544 shutil.rmtree(out_dir)
546 def test_make_archive_tar_gz_with_different_name(self):
547 """ Test make_archive format: tar.gz
548 It packs the source with another name"""
549 for item in self.files + self.dirs:
550 out_file = 'erwe.tar.gz'
551 self.assertTrue(archive.make_archive(out_file, item))
552 self.assertTrue(os.path.exists(out_file))
555 def test_make_archive_tar_gz(self):
556 """ Test make_archive format: tar.gz"""
557 for item in self.files + self.dirs:
558 out_file = '%s.tar.gz' % item
559 self.assertTrue(archive.make_archive(out_file, item))
560 self.assertTrue(os.path.exists(out_file))
563 def _extract_archive_tar_gz(self):
564 """ Test extract archive format: tar.gz"""
565 for item in self.files + self.dirs:
566 out_file = '%s.tar.gz' % item
567 self.assertTrue(archive.make_archive(out_file, item))
568 self.assertTrue(os.path.exists(out_file))
570 out_dir = 'un_tar_dir'
571 archive.extract_archive(out_file, out_dir)
572 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
573 shutil.rmtree(out_dir)
575 def test_make_archive_tbz_with_different_name(self):
576 """ Test make_archive format: tbz
577 It packs the source with another name"""
578 for item in self.files + self.dirs:
579 out_file = 'sdfsd.tbz'
580 self.assertTrue(archive.make_archive(out_file, item))
581 self.assertTrue(os.path.exists(out_file))
584 def test_make_archive_tbz(self):
585 """ Test make_archive format: tbz"""
586 for item in self.files + self.dirs:
587 out_file = '%s.tbz' % item
588 self.assertTrue(archive.make_archive(out_file, item))
589 self.assertTrue(os.path.exists(out_file))
592 def _extract_archive_tbz(self):
593 """ Test extract format: tbz"""
594 for item in self.files + self.dirs:
595 out_file = '%s.tbz' % item
596 self.assertTrue(archive.make_archive(out_file, item))
597 self.assertTrue(os.path.exists(out_file))
599 out_dir = 'un_tar_dir'
600 archive.extract_archive(out_file, out_dir)
601 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
602 shutil.rmtree(out_dir)
604 def test_make_archive_tbz2_with_different_name(self):
605 """ Test make_archive format: tbz2
606 It packs source with another name"""
607 for item in self.files + self.dirs:
608 out_file = 'sfsfd.tbz2'
609 self.assertTrue(archive.make_archive(out_file, item))
610 self.assertTrue(os.path.exists(out_file))
613 def test_make_archive_tbz2(self):
614 """ Test make_archive format: tbz2"""
615 for item in self.files + self.dirs:
616 out_file = '%s.tbz2' % item
617 self.assertTrue(archive.make_archive(out_file, item))
618 self.assertTrue(os.path.exists(out_file))
621 def _extract_archive_tbz2(self):
622 """ Test extract format: tbz2"""
623 for item in self.files + self.dirs:
624 out_file = '%s.tbz2' % item
625 self.assertTrue(archive.make_archive(out_file, item))
626 self.assertTrue(os.path.exists(out_file))
628 out_dir = 'un_tar_dir'
629 archive.extract_archive(out_file, out_dir)
630 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
631 shutil.rmtree(out_dir)
633 def test_make_archive_tar_bz_with_different_name(self):
634 """ Test make_archive format: tar.bz
635 It packs source with antoher name"""
636 for item in self.files + self.dirs:
637 out_file = 'sdf.tar.bz'
638 self.assertTrue(archive.make_archive(out_file, item))
639 self.assertTrue(os.path.exists(out_file))
642 def test_make_archive_tar_bz(self):
643 """ Test make_archive format: tar.bz"""
644 for item in self.files + self.dirs:
645 out_file = '%s.tar.bz' % item
646 self.assertTrue(archive.make_archive(out_file, item))
647 self.assertTrue(os.path.exists(out_file))
650 def _extract_archive_tar_bz(self):
651 """ Test extract format: tar.bz"""
652 for item in self.files + self.dirs:
653 out_file = '%s.tar.bz' % item
654 self.assertTrue(archive.make_archive(out_file, item))
655 self.assertTrue(os.path.exists(out_file))
657 out_dir = 'un_tar_dir'
658 archive.extract_archive(out_file, out_dir)
659 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
660 shutil.rmtree(out_dir)
662 def test_make_archive_tar_bz2_with_different_name(self):
663 """ Test make_archive format: tar.bz2
664 it packs the source with another name """
665 for item in self.files + self.dirs:
666 out_file = 'df.tar.bz2'
667 self.assertTrue(archive.make_archive(out_file, item))
668 self.assertTrue(os.path.exists(out_file))
671 def test_make_archive_tar_bz2(self):
672 """ Test make_archive format: tar.bz2"""
673 for item in self.files + self.dirs:
674 out_file = '%s.tar.bz2' % item
675 self.assertTrue(archive.make_archive(out_file, item))
676 self.assertTrue(os.path.exists(out_file))
679 def _extract_archive_tar_bz2(self):
680 """ Test extract format: tar.bz2"""
681 for item in self.files + self.dirs:
682 out_file = '%s.tar.bz2' % item
683 self.assertTrue(archive.make_archive(out_file, item))
684 self.assertTrue(os.path.exists(out_file))
686 out_dir = 'un_tar_dir'
687 archive.extract_archive(out_file, out_dir)
688 self.assertTrue(os.path.exists(os.path.join(out_dir, item)))
689 shutil.rmtree(out_dir)
691 if __name__ == "__main__":