blob: 0f3df7fa0635e22bd7247f9c3c88da0cc0ae1c92 [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")
298 os.mkdir(path)
299 tarinfo = self.dst.gettarinfo(path)
300 self.assertEqual(tarinfo.size, 0)
301
302 def test_symlink(self):
303 if hasattr(os, "symlink"):
304 path = os.path.join(self.tmpdir, "symlink")
305 os.symlink("link_target", path)
306 tarinfo = self.dst.gettarinfo(path)
307 self.assertEqual(tarinfo.size, 0)
308
309
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000310class WriteStreamTest(WriteTest):
311 sep = '|'
312
Neal Norwitz0662f8a2004-07-20 21:54:18 +0000313class WriteGNULongTest(unittest.TestCase):
314 """This testcase checks for correct creation of GNU Longname
315 and Longlink extensions.
316
317 It creates a tarfile and adds empty members with either
318 long names, long linknames or both and compares the size
319 of the tarfile with the expected size.
320
321 It checks for SF bug #812325 in TarFile._create_gnulong().
322
323 While I was writing this testcase, I noticed a second bug
324 in the same method:
325 Long{names,links} weren't null-terminated which lead to
326 bad tarfiles when their length was a multiple of 512. This
327 is tested as well.
328 """
329
330 def setUp(self):
331 self.tar = tarfile.open(tmpname(), "w")
332 self.tar.posix = False
333
334 def tearDown(self):
335 self.tar.close()
336
337 def _length(self, s):
338 blocks, remainder = divmod(len(s) + 1, 512)
339 if remainder:
340 blocks += 1
341 return blocks * 512
342
343 def _calc_size(self, name, link=None):
344 # initial tar header
345 count = 512
346
347 if len(name) > tarfile.LENGTH_NAME:
348 # gnu longname extended header + longname
349 count += 512
350 count += self._length(name)
351
352 if link is not None and len(link) > tarfile.LENGTH_LINK:
353 # gnu longlink extended header + longlink
354 count += 512
355 count += self._length(link)
356
357 return count
358
359 def _test(self, name, link=None):
360 tarinfo = tarfile.TarInfo(name)
361 if link:
362 tarinfo.linkname = link
363 tarinfo.type = tarfile.LNKTYPE
364
365 self.tar.addfile(tarinfo)
366
367 v1 = self._calc_size(name, link)
368 v2 = self.tar.offset
369 self.assertEqual(v1, v2, "GNU longname/longlink creation failed")
370
371 def test_longname_1023(self):
372 self._test(("longnam/" * 127) + "longnam")
373
374 def test_longname_1024(self):
375 self._test(("longnam/" * 127) + "longname")
376
377 def test_longname_1025(self):
378 self._test(("longnam/" * 127) + "longname_")
379
380 def test_longlink_1023(self):
381 self._test("name", ("longlnk/" * 127) + "longlnk")
382
383 def test_longlink_1024(self):
384 self._test("name", ("longlnk/" * 127) + "longlink")
385
386 def test_longlink_1025(self):
387 self._test("name", ("longlnk/" * 127) + "longlink_")
388
389 def test_longnamelink_1023(self):
390 self._test(("longnam/" * 127) + "longnam",
391 ("longlnk/" * 127) + "longlnk")
392
393 def test_longnamelink_1024(self):
394 self._test(("longnam/" * 127) + "longname",
395 ("longlnk/" * 127) + "longlink")
396
397 def test_longnamelink_1025(self):
398 self._test(("longnam/" * 127) + "longname_",
399 ("longlnk/" * 127) + "longlink_")
400
Georg Brandl38c6a222006-05-10 16:26:03 +0000401class ReadGNULongTest(unittest.TestCase):
402
403 def setUp(self):
404 self.tar = tarfile.open(tarname())
405
406 def tearDown(self):
407 self.tar.close()
408
409 def test_1471427(self):
410 """Test reading of longname (bug #1471427).
411 """
412 name = "test/" * 20 + "0-REGTYPE"
413 try:
414 tarinfo = self.tar.getmember(name)
415 except KeyError:
416 tarinfo = None
417 self.assert_(tarinfo is not None, "longname not found")
418 self.assert_(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype")
419
420 def test_read_name(self):
421 name = ("0-LONGNAME-" * 10)[:101]
422 try:
423 tarinfo = self.tar.getmember(name)
424 except KeyError:
425 tarinfo = None
426 self.assert_(tarinfo is not None, "longname not found")
427
428 def test_read_link(self):
429 link = ("1-LONGLINK-" * 10)[:101]
430 name = ("0-LONGNAME-" * 10)[:101]
431 try:
432 tarinfo = self.tar.getmember(link)
433 except KeyError:
434 tarinfo = None
435 self.assert_(tarinfo is not None, "longlink not found")
436 self.assert_(tarinfo.linkname == name, "linkname wrong")
437
438 def test_truncated_longname(self):
439 fobj = StringIO.StringIO(file(tarname()).read(1024))
440 tar = tarfile.open(name="foo.tar", fileobj=fobj)
441 self.assert_(len(tar.getmembers()) == 0, "")
442
443
Neal Norwitza4f651a2004-07-20 22:07:44 +0000444class ExtractHardlinkTest(BaseTest):
445
446 def test_hardlink(self):
447 """Test hardlink extraction (bug #857297)
448 """
449 # Prevent errors from being caught
450 self.tar.errorlevel = 1
451
452 self.tar.extract("0-REGTYPE", dirname())
453 try:
454 # Extract 1-LNKTYPE which is a hardlink to 0-REGTYPE
455 self.tar.extract("1-LNKTYPE", dirname())
456 except EnvironmentError, e:
457 import errno
458 if e.errno == errno.ENOENT:
459 self.fail("hardlink not extracted properly")
460
Neal Norwitzb0e32e22005-10-20 04:50:13 +0000461class CreateHardlinkTest(BaseTest):
462 """Test the creation of LNKTYPE (hardlink) members in an archive.
463 In this respect tarfile.py mimics the behaviour of GNU tar: If
464 a file has a st_nlink > 1, it will be added a REGTYPE member
465 only the first time.
466 """
467
468 def setUp(self):
469 self.tar = tarfile.open(tmpname(), "w")
470
471 self.foo = os.path.join(dirname(), "foo")
472 self.bar = os.path.join(dirname(), "bar")
473
474 if os.path.exists(self.foo):
475 os.remove(self.foo)
476 if os.path.exists(self.bar):
477 os.remove(self.bar)
478
479 file(self.foo, "w").write("foo")
480 self.tar.add(self.foo)
481
482 def test_add_twice(self):
483 # If st_nlink == 1 then the same file will be added as
484 # REGTYPE every time.
485 tarinfo = self.tar.gettarinfo(self.foo)
486 self.assertEqual(tarinfo.type, tarfile.REGTYPE,
487 "add file as regular failed")
488
489 def test_add_hardlink(self):
490 # If st_nlink > 1 then the same file will be added as
491 # LNKTYPE.
492 os.link(self.foo, self.bar)
493 tarinfo = self.tar.gettarinfo(self.foo)
494 self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
495 "add file as hardlink failed")
496
497 tarinfo = self.tar.gettarinfo(self.bar)
498 self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
499 "add file as hardlink failed")
500
501 def test_dereference_hardlink(self):
502 self.tar.dereference = True
503 os.link(self.foo, self.bar)
504 tarinfo = self.tar.gettarinfo(self.bar)
505 self.assertEqual(tarinfo.type, tarfile.REGTYPE,
506 "dereferencing hardlink failed")
507
Neal Norwitza4f651a2004-07-20 22:07:44 +0000508
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000509# Gzip TestCases
510class ReadTestGzip(ReadTest):
511 comp = "gz"
512class ReadStreamTestGzip(ReadStreamTest):
513 comp = "gz"
514class WriteTestGzip(WriteTest):
515 comp = "gz"
516class WriteStreamTestGzip(WriteStreamTest):
517 comp = "gz"
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000518class ReadDetectTestGzip(ReadDetectTest):
519 comp = "gz"
520class ReadDetectFileobjTestGzip(ReadDetectFileobjTest):
521 comp = "gz"
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000522class ReadAsteriskTestGzip(ReadAsteriskTest):
523 comp = "gz"
524class ReadStreamAsteriskTestGzip(ReadStreamAsteriskTest):
525 comp = "gz"
526
Andrew M. Kuchlingd4f25522004-10-20 11:47:01 +0000527# Filemode test cases
528
529class FileModeTest(unittest.TestCase):
530 def test_modes(self):
531 self.assertEqual(tarfile.filemode(0755), '-rwxr-xr-x')
532 self.assertEqual(tarfile.filemode(07111), '---s--s--t')
533
Tim Peters8ceefc52004-10-25 03:19:41 +0000534
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000535if bz2:
536 # Bzip2 TestCases
537 class ReadTestBzip2(ReadTestGzip):
538 comp = "bz2"
539 class ReadStreamTestBzip2(ReadStreamTestGzip):
540 comp = "bz2"
541 class WriteTestBzip2(WriteTest):
542 comp = "bz2"
543 class WriteStreamTestBzip2(WriteStreamTestGzip):
544 comp = "bz2"
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000545 class ReadDetectTestBzip2(ReadDetectTest):
546 comp = "bz2"
547 class ReadDetectFileobjTestBzip2(ReadDetectFileobjTest):
548 comp = "bz2"
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000549 class ReadAsteriskTestBzip2(ReadAsteriskTest):
550 comp = "bz2"
551 class ReadStreamAsteriskTestBzip2(ReadStreamAsteriskTest):
552 comp = "bz2"
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000553
554# If importing gzip failed, discard the Gzip TestCases.
555if not gzip:
556 del ReadTestGzip
557 del ReadStreamTestGzip
558 del WriteTestGzip
559 del WriteStreamTestGzip
560
Neal Norwitz996acf12003-02-17 14:51:41 +0000561def test_main():
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000562 if gzip:
563 # create testtar.tar.gz
564 gzip.open(tarname("gz"), "wb").write(file(tarname(), "rb").read())
565 if bz2:
566 # create testtar.tar.bz2
567 bz2.BZ2File(tarname("bz2"), "wb").write(file(tarname(), "rb").read())
568
Walter Dörwald21d3a322003-05-01 17:45:56 +0000569 tests = [
Andrew M. Kuchlingd4f25522004-10-20 11:47:01 +0000570 FileModeTest,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000571 ReadTest,
572 ReadStreamTest,
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000573 ReadDetectTest,
574 ReadDetectFileobjTest,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000575 ReadAsteriskTest,
576 ReadStreamAsteriskTest,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000577 WriteTest,
Martin v. Löwis5dbdc592005-08-27 10:07:56 +0000578 WriteSize0Test,
Neal Norwitz0662f8a2004-07-20 21:54:18 +0000579 WriteStreamTest,
580 WriteGNULongTest,
Georg Brandl38c6a222006-05-10 16:26:03 +0000581 ReadGNULongTest,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000582 ]
583
Neal Norwitza4f651a2004-07-20 22:07:44 +0000584 if hasattr(os, "link"):
585 tests.append(ExtractHardlinkTest)
Neal Norwitzb0e32e22005-10-20 04:50:13 +0000586 tests.append(CreateHardlinkTest)
Neal Norwitza4f651a2004-07-20 22:07:44 +0000587
Walter Dörwald21d3a322003-05-01 17:45:56 +0000588 if gzip:
589 tests.extend([
590 ReadTestGzip, ReadStreamTestGzip,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000591 WriteTestGzip, WriteStreamTestGzip,
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000592 ReadDetectTestGzip, ReadDetectFileobjTestGzip,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000593 ReadAsteriskTestGzip, ReadStreamAsteriskTestGzip
Walter Dörwald21d3a322003-05-01 17:45:56 +0000594 ])
595
596 if bz2:
597 tests.extend([
598 ReadTestBzip2, ReadStreamTestBzip2,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000599 WriteTestBzip2, WriteStreamTestBzip2,
Georg Brandl49c8f4c2006-05-15 19:30:35 +0000600 ReadDetectTestBzip2, ReadDetectFileobjTestBzip2,
Martin v. Löwis78be7df2005-03-05 12:47:42 +0000601 ReadAsteriskTestBzip2, ReadStreamAsteriskTestBzip2
Walter Dörwald21d3a322003-05-01 17:45:56 +0000602 ])
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000603 try:
Walter Dörwald21d3a322003-05-01 17:45:56 +0000604 test_support.run_unittest(*tests)
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000605 finally:
606 if gzip:
607 os.remove(tarname("gz"))
608 if bz2:
609 os.remove(tarname("bz2"))
Brett Cannon455ea532003-06-12 08:01:06 +0000610 if os.path.exists(dirname()):
611 shutil.rmtree(dirname())
612 if os.path.exists(tmpname()):
613 os.remove(tmpname())
Neal Norwitzb9ef4ae2003-01-05 23:19:43 +0000614
Neal Norwitz996acf12003-02-17 14:51:41 +0000615if __name__ == "__main__":
616 test_main()