blob: 503de26c9a3d67c911ae351705ebbc6815ab9aba [file] [log] [blame]
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +00001import sys
2import os
3import shutil
Brett Cannon455ea532003-06-12 08:01:06 +00004import tempfile
Georg Brandl38c6a222006-05-10 16:26:03 +00005import StringIO
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +00006
7import unittest
8import tarfile
9
10from test import test_support
11
12# Check for our compression modules.
13try:
14 import gzip
Neal Norwitzae323192003-04-14 01:18:32 +000015 gzip.GzipFile
16except (ImportError, AttributeError):
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +000017 gzip = None
18try:
19 import bz2
20except ImportError:
21 bz2 = None
22
23def path(path):
24 return test_support.findfile(path)
25
Brett Cannon455ea532003-06-12 08:01:06 +000026testtar = path("testtar.tar")
27tempdir = os.path.join(tempfile.gettempdir(), "testtar" + os.extsep + "dir")
28tempname = test_support.TESTFN
Georg Brandl38c6a222006-05-10 16:26:03 +000029membercount = 12
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +000030
31def tarname(comp=""):
32 if not comp:
33 return testtar
Brett Cannon43e559a2003-06-12 19:16:58 +000034 return os.path.join(tempdir, "%s%s%s" % (testtar, os.extsep, comp))
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +000035
36def dirname():
37 if not os.path.exists(tempdir):
38 os.mkdir(tempdir)
39 return tempdir
40
41def tmpname():
42 return tempname
43
44
45class BaseTest(unittest.TestCase):
46 comp = ''
47 mode = 'r'
48 sep = ':'
49
50 def setUp(self):
51 mode = self.mode + self.sep + self.comp
52 self.tar = tarfile.open(tarname(self.comp), mode)
53
54 def tearDown(self):
55 self.tar.close()
56
57class ReadTest(BaseTest):
58
59 def test(self):
60 """Test member extraction.
61 """
62 members = 0
63 for tarinfo in self.tar:
64 members += 1
65 if not tarinfo.isreg():
66 continue
67 f = self.tar.extractfile(tarinfo)
68 self.assert_(len(f.read()) == tarinfo.size,
69 "size read does not match expected size")
70 f.close()
71
72 self.assert_(members == membercount,
73 "could not find all members")
74
75 def test_sparse(self):
76 """Test sparse member extraction.
77 """
78 if self.sep != "|":
79 f1 = self.tar.extractfile("S-SPARSE")
Jack Jansen149a8992003-03-07 13:27:53 +000080 f2 = self.tar.extractfile("S-SPARSE-WITH-NULLS")
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +000081 self.assert_(f1.read() == f2.read(),
82 "_FileObject failed on sparse file member")
83
84 def test_readlines(self):
85 """Test readlines() method of _FileObject.
86 """
87 if self.sep != "|":
Jack Jansen149a8992003-03-07 13:27:53 +000088 filename = "0-REGTYPE-TEXT"
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +000089 self.tar.extract(filename, dirname())
Jack Jansenc7fcc2d2003-03-07 12:50:45 +000090 lines1 = file(os.path.join(dirname(), filename), "rU").readlines()
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +000091 lines2 = self.tar.extractfile(filename).readlines()
92 self.assert_(lines1 == lines2,
93 "_FileObject.readline() does not work correctly")
94
Martin v. Löwisdf241532005-03-03 08:17:42 +000095 def test_iter(self):
96 # Test iteration over ExFileObject.
97 if self.sep != "|":
98 filename = "0-REGTYPE-TEXT"
99 self.tar.extract(filename, dirname())
100 lines1 = file(os.path.join(dirname(), filename), "rU").readlines()
101 lines2 = [line for line in self.tar.extractfile(filename)]
102 self.assert_(lines1 == lines2,
103 "ExFileObject iteration does not work correctly")
104
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000105 def test_seek(self):
106 """Test seek() method of _FileObject, incl. random reading.
107 """
108 if self.sep != "|":
Jack Jansen149a8992003-03-07 13:27:53 +0000109 filename = "0-REGTYPE"
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000110 self.tar.extract(filename, dirname())
111 data = file(os.path.join(dirname(), filename), "rb").read()
112
113 tarinfo = self.tar.getmember(filename)
114 fobj = self.tar.extractfile(tarinfo)
115
116 text = fobj.read()
117 fobj.seek(0)
118 self.assert_(0 == fobj.tell(),
119 "seek() to file's start failed")
120 fobj.seek(2048, 0)
121 self.assert_(2048 == fobj.tell(),
122 "seek() to absolute position failed")
123 fobj.seek(-1024, 1)
124 self.assert_(1024 == fobj.tell(),
125 "seek() to negative relative position failed")
126 fobj.seek(1024, 1)
127 self.assert_(2048 == fobj.tell(),
128 "seek() to positive relative position failed")
129 s = fobj.read(10)
130 self.assert_(s == data[2048:2058],
131 "read() after seek failed")
132 fobj.seek(0, 2)
133 self.assert_(tarinfo.size == fobj.tell(),
134 "seek() to file's end failed")
135 self.assert_(fobj.read() == "",
136 "read() at file's end did not return empty string")
137 fobj.seek(-tarinfo.size, 2)
138 self.assert_(0 == fobj.tell(),
139 "relative seek() to file's start failed")
140 fobj.seek(512)
141 s1 = fobj.readlines()
142 fobj.seek(512)
143 s2 = fobj.readlines()
144 self.assert_(s1 == s2,
145 "readlines() after seek failed")
146 fobj.close()
147
Neal Norwitzf3396542005-10-28 05:52:22 +0000148 def test_old_dirtype(self):
149 """Test old style dirtype member (bug #1336623).
150 """
151 # Old tars create directory members using a REGTYPE
152 # header with a "/" appended to the filename field.
153
154 # Create an old tar style directory entry.
155 filename = tmpname()
156 tarinfo = tarfile.TarInfo("directory/")
157 tarinfo.type = tarfile.REGTYPE
158
159 fobj = file(filename, "w")
160 fobj.write(tarinfo.tobuf())
161 fobj.close()
162
163 try:
164 # Test if it is still a directory entry when
165 # read back.
166 tar = tarfile.open(filename)
167 tarinfo = tar.getmembers()[0]
168 tar.close()
169
170 self.assert_(tarinfo.type == tarfile.DIRTYPE)
171 self.assert_(tarinfo.name.endswith("/"))
172 finally:
173 try:
174 os.unlink(filename)
175 except:
176 pass
177
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000178class ReadStreamTest(ReadTest):
179 sep = "|"
180
181 def test(self):
182 """Test member extraction, and for StreamError when
183 seeking backwards.
184 """
185 ReadTest.test(self)
186 tarinfo = self.tar.getmembers()[0]
187 f = self.tar.extractfile(tarinfo)
188 self.assertRaises(tarfile.StreamError, f.read)
189
190 def test_stream(self):
191 """Compare the normal tar and the stream tar.
192 """
193 stream = self.tar
194 tar = tarfile.open(tarname(), 'r')
195
196 while 1:
197 t1 = tar.next()
198 t2 = stream.next()
199 if t1 is None:
200 break
201 self.assert_(t2 is not None, "stream.next() failed.")
202
203 if t2.islnk() or t2.issym():
204 self.assertRaises(tarfile.StreamError, stream.extractfile, t2)
205 continue
206 v1 = tar.extractfile(t1)
207 v2 = stream.extractfile(t2)
208 if v1 is None:
209 continue
210 self.assert_(v2 is not None, "stream.extractfile() failed")
211 self.assert_(v1.read() == v2.read(), "stream extraction failed")
212
213 stream.close()
214
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000215class ReadDetectTest(ReadTest):
216
217 def setUp(self):
218 self.tar = tarfile.open(tarname(self.comp), self.mode)
219
220class ReadDetectFileobjTest(ReadTest):
221
222 def setUp(self):
223 name = tarname(self.comp)
Tim Peters12087ba2006-05-15 20:44:10 +0000224 self.tar = tarfile.open(name, mode=self.mode,
225 fileobj=open(name, "rb"))
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000226
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000227class ReadAsteriskTest(ReadTest):
228
229 def setUp(self):
230 mode = self.mode + self.sep + "*"
231 self.tar = tarfile.open(tarname(self.comp), mode)
232
233class ReadStreamAsteriskTest(ReadStreamTest):
234
235 def setUp(self):
236 mode = self.mode + self.sep + "*"
237 self.tar = tarfile.open(tarname(self.comp), mode)
238
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000239class WriteTest(BaseTest):
240 mode = 'w'
241
242 def setUp(self):
243 mode = self.mode + self.sep + self.comp
244 self.src = tarfile.open(tarname(self.comp), 'r')
Martin v. Löwisc234a522004-08-22 21:28:33 +0000245 self.dstname = tmpname()
246 self.dst = tarfile.open(self.dstname, mode)
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000247
248 def tearDown(self):
249 self.src.close()
250 self.dst.close()
251
252 def test_posix(self):
253 self.dst.posix = 1
254 self._test()
255
256 def test_nonposix(self):
257 self.dst.posix = 0
258 self._test()
259
Martin v. Löwisc234a522004-08-22 21:28:33 +0000260 def test_small(self):
261 self.dst.add(os.path.join(os.path.dirname(__file__),"cfgparser.1"))
262 self.dst.close()
263 self.assertNotEqual(os.stat(self.dstname).st_size, 0)
264
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000265 def _test(self):
266 for tarinfo in self.src:
267 if not tarinfo.isreg():
268 continue
269 f = self.src.extractfile(tarinfo)
Georg Brandl38c6a222006-05-10 16:26:03 +0000270 if self.dst.posix and len(tarinfo.name) > tarfile.LENGTH_NAME and "/" not in tarinfo.name:
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000271 self.assertRaises(ValueError, self.dst.addfile,
272 tarinfo, f)
273 else:
274 self.dst.addfile(tarinfo, f)
275
Martin v. Löwis5dbdc592005-08-27 10:07:56 +0000276class WriteSize0Test(BaseTest):
277 mode = 'w'
278
279 def setUp(self):
280 self.tmpdir = dirname()
281 self.dstname = tmpname()
282 self.dst = tarfile.open(self.dstname, "w")
283
284 def tearDown(self):
285 self.dst.close()
286
287 def test_file(self):
288 path = os.path.join(self.tmpdir, "file")
289 file(path, "w")
290 tarinfo = self.dst.gettarinfo(path)
291 self.assertEqual(tarinfo.size, 0)
292 file(path, "w").write("aaa")
293 tarinfo = self.dst.gettarinfo(path)
294 self.assertEqual(tarinfo.size, 3)
295
296 def test_directory(self):
297 path = os.path.join(self.tmpdir, "directory")
Tim Peters4ccc0b72006-05-15 21:32:25 +0000298 if os.path.exists(path):
299 # This shouldn't be necessary, but is <wink> if a previous
300 # run was killed in mid-stream.
301 shutil.rmtree(path)
Martin v. Löwis5dbdc592005-08-27 10:07:56 +0000302 os.mkdir(path)
303 tarinfo = self.dst.gettarinfo(path)
304 self.assertEqual(tarinfo.size, 0)
305
306 def test_symlink(self):
307 if hasattr(os, "symlink"):
308 path = os.path.join(self.tmpdir, "symlink")
309 os.symlink("link_target", path)
310 tarinfo = self.dst.gettarinfo(path)
311 self.assertEqual(tarinfo.size, 0)
312
313
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000314class WriteStreamTest(WriteTest):
315 sep = '|'
316
Neal Norwitz0662f8a2004-07-20 21:54:18 +0000317class WriteGNULongTest(unittest.TestCase):
318 """This testcase checks for correct creation of GNU Longname
319 and Longlink extensions.
320
321 It creates a tarfile and adds empty members with either
322 long names, long linknames or both and compares the size
323 of the tarfile with the expected size.
324
325 It checks for SF bug #812325 in TarFile._create_gnulong().
326
327 While I was writing this testcase, I noticed a second bug
328 in the same method:
329 Long{names,links} weren't null-terminated which lead to
330 bad tarfiles when their length was a multiple of 512. This
331 is tested as well.
332 """
333
334 def setUp(self):
335 self.tar = tarfile.open(tmpname(), "w")
336 self.tar.posix = False
337
338 def tearDown(self):
339 self.tar.close()
340
341 def _length(self, s):
342 blocks, remainder = divmod(len(s) + 1, 512)
343 if remainder:
344 blocks += 1
345 return blocks * 512
346
347 def _calc_size(self, name, link=None):
348 # initial tar header
349 count = 512
350
351 if len(name) > tarfile.LENGTH_NAME:
352 # gnu longname extended header + longname
353 count += 512
354 count += self._length(name)
355
356 if link is not None and len(link) > tarfile.LENGTH_LINK:
357 # gnu longlink extended header + longlink
358 count += 512
359 count += self._length(link)
360
361 return count
362
363 def _test(self, name, link=None):
364 tarinfo = tarfile.TarInfo(name)
365 if link:
366 tarinfo.linkname = link
367 tarinfo.type = tarfile.LNKTYPE
368
369 self.tar.addfile(tarinfo)
370
371 v1 = self._calc_size(name, link)
372 v2 = self.tar.offset
373 self.assertEqual(v1, v2, "GNU longname/longlink creation failed")
374
375 def test_longname_1023(self):
376 self._test(("longnam/" * 127) + "longnam")
377
378 def test_longname_1024(self):
379 self._test(("longnam/" * 127) + "longname")
380
381 def test_longname_1025(self):
382 self._test(("longnam/" * 127) + "longname_")
383
384 def test_longlink_1023(self):
385 self._test("name", ("longlnk/" * 127) + "longlnk")
386
387 def test_longlink_1024(self):
388 self._test("name", ("longlnk/" * 127) + "longlink")
389
390 def test_longlink_1025(self):
391 self._test("name", ("longlnk/" * 127) + "longlink_")
392
393 def test_longnamelink_1023(self):
394 self._test(("longnam/" * 127) + "longnam",
395 ("longlnk/" * 127) + "longlnk")
396
397 def test_longnamelink_1024(self):
398 self._test(("longnam/" * 127) + "longname",
399 ("longlnk/" * 127) + "longlink")
400
401 def test_longnamelink_1025(self):
402 self._test(("longnam/" * 127) + "longname_",
403 ("longlnk/" * 127) + "longlink_")
404
Georg Brandl38c6a222006-05-10 16:26:03 +0000405class ReadGNULongTest(unittest.TestCase):
406
407 def setUp(self):
408 self.tar = tarfile.open(tarname())
409
410 def tearDown(self):
411 self.tar.close()
412
413 def test_1471427(self):
414 """Test reading of longname (bug #1471427).
415 """
416 name = "test/" * 20 + "0-REGTYPE"
417 try:
418 tarinfo = self.tar.getmember(name)
419 except KeyError:
420 tarinfo = None
421 self.assert_(tarinfo is not None, "longname not found")
422 self.assert_(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype")
423
424 def test_read_name(self):
425 name = ("0-LONGNAME-" * 10)[:101]
426 try:
427 tarinfo = self.tar.getmember(name)
428 except KeyError:
429 tarinfo = None
430 self.assert_(tarinfo is not None, "longname not found")
431
432 def test_read_link(self):
433 link = ("1-LONGLINK-" * 10)[:101]
434 name = ("0-LONGNAME-" * 10)[:101]
435 try:
436 tarinfo = self.tar.getmember(link)
437 except KeyError:
438 tarinfo = None
439 self.assert_(tarinfo is not None, "longlink not found")
440 self.assert_(tarinfo.linkname == name, "linkname wrong")
441
442 def test_truncated_longname(self):
443 fobj = StringIO.StringIO(file(tarname()).read(1024))
444 tar = tarfile.open(name="foo.tar", fileobj=fobj)
445 self.assert_(len(tar.getmembers()) == 0, "")
446
447
Neal Norwitza4f651a2004-07-20 22:07:44 +0000448class ExtractHardlinkTest(BaseTest):
449
450 def test_hardlink(self):
451 """Test hardlink extraction (bug #857297)
452 """
453 # Prevent errors from being caught
454 self.tar.errorlevel = 1
455
456 self.tar.extract("0-REGTYPE", dirname())
457 try:
458 # Extract 1-LNKTYPE which is a hardlink to 0-REGTYPE
459 self.tar.extract("1-LNKTYPE", dirname())
460 except EnvironmentError, e:
461 import errno
462 if e.errno == errno.ENOENT:
463 self.fail("hardlink not extracted properly")
464
Neal Norwitzb0e32e22005-10-20 04:50:13 +0000465class CreateHardlinkTest(BaseTest):
466 """Test the creation of LNKTYPE (hardlink) members in an archive.
467 In this respect tarfile.py mimics the behaviour of GNU tar: If
468 a file has a st_nlink > 1, it will be added a REGTYPE member
469 only the first time.
470 """
471
472 def setUp(self):
473 self.tar = tarfile.open(tmpname(), "w")
474
475 self.foo = os.path.join(dirname(), "foo")
476 self.bar = os.path.join(dirname(), "bar")
477
478 if os.path.exists(self.foo):
479 os.remove(self.foo)
480 if os.path.exists(self.bar):
481 os.remove(self.bar)
482
483 file(self.foo, "w").write("foo")
484 self.tar.add(self.foo)
485
486 def test_add_twice(self):
487 # If st_nlink == 1 then the same file will be added as
488 # REGTYPE every time.
489 tarinfo = self.tar.gettarinfo(self.foo)
490 self.assertEqual(tarinfo.type, tarfile.REGTYPE,
491 "add file as regular failed")
492
493 def test_add_hardlink(self):
494 # If st_nlink > 1 then the same file will be added as
495 # LNKTYPE.
496 os.link(self.foo, self.bar)
497 tarinfo = self.tar.gettarinfo(self.foo)
498 self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
499 "add file as hardlink failed")
500
501 tarinfo = self.tar.gettarinfo(self.bar)
502 self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
503 "add file as hardlink failed")
504
505 def test_dereference_hardlink(self):
506 self.tar.dereference = True
507 os.link(self.foo, self.bar)
508 tarinfo = self.tar.gettarinfo(self.bar)
509 self.assertEqual(tarinfo.type, tarfile.REGTYPE,
510 "dereferencing hardlink failed")
511
Neal Norwitza4f651a2004-07-20 22:07:44 +0000512
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000513# Gzip TestCases
514class ReadTestGzip(ReadTest):
515 comp = "gz"
516class ReadStreamTestGzip(ReadStreamTest):
517 comp = "gz"
518class WriteTestGzip(WriteTest):
519 comp = "gz"
520class WriteStreamTestGzip(WriteStreamTest):
521 comp = "gz"
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000522class ReadDetectTestGzip(ReadDetectTest):
523 comp = "gz"
524class ReadDetectFileobjTestGzip(ReadDetectFileobjTest):
525 comp = "gz"
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000526class ReadAsteriskTestGzip(ReadAsteriskTest):
527 comp = "gz"
528class ReadStreamAsteriskTestGzip(ReadStreamAsteriskTest):
529 comp = "gz"
530
Andrew M. Kuchlingd4f25522004-10-20 11:47:01 +0000531# Filemode test cases
532
533class FileModeTest(unittest.TestCase):
534 def test_modes(self):
535 self.assertEqual(tarfile.filemode(0755), '-rwxr-xr-x')
536 self.assertEqual(tarfile.filemode(07111), '---s--s--t')
537
Tim Peters8ceefc52004-10-25 03:19:41 +0000538
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000539if bz2:
540 # Bzip2 TestCases
541 class ReadTestBzip2(ReadTestGzip):
542 comp = "bz2"
543 class ReadStreamTestBzip2(ReadStreamTestGzip):
544 comp = "bz2"
545 class WriteTestBzip2(WriteTest):
546 comp = "bz2"
547 class WriteStreamTestBzip2(WriteStreamTestGzip):
548 comp = "bz2"
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000549 class ReadDetectTestBzip2(ReadDetectTest):
550 comp = "bz2"
551 class ReadDetectFileobjTestBzip2(ReadDetectFileobjTest):
552 comp = "bz2"
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000553 class ReadAsteriskTestBzip2(ReadAsteriskTest):
554 comp = "bz2"
555 class ReadStreamAsteriskTestBzip2(ReadStreamAsteriskTest):
556 comp = "bz2"
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000557
558# If importing gzip failed, discard the Gzip TestCases.
559if not gzip:
560 del ReadTestGzip
561 del ReadStreamTestGzip
562 del WriteTestGzip
563 del WriteStreamTestGzip
564
Neal Norwitz996acf12003-02-17 14:51:41 +0000565def test_main():
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000566 if gzip:
567 # create testtar.tar.gz
568 gzip.open(tarname("gz"), "wb").write(file(tarname(), "rb").read())
569 if bz2:
570 # create testtar.tar.bz2
571 bz2.BZ2File(tarname("bz2"), "wb").write(file(tarname(), "rb").read())
572
Walter Dörwald21d3a322003-05-01 17:45:56 +0000573 tests = [
Andrew M. Kuchlingd4f25522004-10-20 11:47:01 +0000574 FileModeTest,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000575 ReadTest,
576 ReadStreamTest,
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000577 ReadDetectTest,
578 ReadDetectFileobjTest,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000579 ReadAsteriskTest,
580 ReadStreamAsteriskTest,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000581 WriteTest,
Martin v. Löwis5dbdc592005-08-27 10:07:56 +0000582 WriteSize0Test,
Neal Norwitz0662f8a2004-07-20 21:54:18 +0000583 WriteStreamTest,
584 WriteGNULongTest,
Georg Brandl38c6a222006-05-10 16:26:03 +0000585 ReadGNULongTest,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000586 ]
587
Neal Norwitza4f651a2004-07-20 22:07:44 +0000588 if hasattr(os, "link"):
589 tests.append(ExtractHardlinkTest)
Neal Norwitzb0e32e22005-10-20 04:50:13 +0000590 tests.append(CreateHardlinkTest)
Neal Norwitza4f651a2004-07-20 22:07:44 +0000591
Walter Dörwald21d3a322003-05-01 17:45:56 +0000592 if gzip:
593 tests.extend([
594 ReadTestGzip, ReadStreamTestGzip,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000595 WriteTestGzip, WriteStreamTestGzip,
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000596 ReadDetectTestGzip, ReadDetectFileobjTestGzip,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000597 ReadAsteriskTestGzip, ReadStreamAsteriskTestGzip
Walter Dörwald21d3a322003-05-01 17:45:56 +0000598 ])
599
600 if bz2:
601 tests.extend([
602 ReadTestBzip2, ReadStreamTestBzip2,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000603 WriteTestBzip2, WriteStreamTestBzip2,
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000604 ReadDetectTestBzip2, ReadDetectFileobjTestBzip2,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000605 ReadAsteriskTestBzip2, ReadStreamAsteriskTestBzip2
Walter Dörwald21d3a322003-05-01 17:45:56 +0000606 ])
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000607 try:
Walter Dörwald21d3a322003-05-01 17:45:56 +0000608 test_support.run_unittest(*tests)
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000609 finally:
610 if gzip:
611 os.remove(tarname("gz"))
612 if bz2:
613 os.remove(tarname("bz2"))
Brett Cannon455ea532003-06-12 08:01:06 +0000614 if os.path.exists(dirname()):
615 shutil.rmtree(dirname())
616 if os.path.exists(tmpname()):
617 os.remove(tmpname())
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000618
Neal Norwitz996acf12003-02-17 14:51:41 +0000619if __name__ == "__main__":
620 test_main()